forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-25299] Shuffle locations api (#517)
Implements the shuffle locations API as part of SPARK-25299. This adds an additional field to all `MapStatus` objects: a `MapShuffleLocations` that indicates where a task's map output is stored. This module is optional and implementations of the pluggable shuffle writers and readers can ignore it accordingly. This API is designed with the use case in mind of future plugin implementations desiring to have the driver store metadata about where shuffle blocks are stored. There are a few caveats to this design: - We originally wanted to remove the `BlockManagerId` from `MapStatus` entirely and replace it with this object. However, doing this proves to be very difficult, as many places use the block manager ID for other kinds of shuffle data bookkeeping. As a result, we concede to storing the block manager ID redundantly here. However, the overhead should be minimal: because we cache block manager ids and default map shuffle locations, the two fields in `MapStatus` should point to the same object on the heap. Thus we add `O(M)` storage overhead on the driver, where for each map status we're storing an additional pointer to the same on-heap object. We will run benchmarks against the TPC-DS workload to see if there are significant performance repercussions for this implementation. - `KryoSerializer` expects `CompressedMapStatus` and `HighlyCompressedMapStatus` to be serialized via reflection, so originally all fields of these classes needed to be registered with Kryo. However, the `MapShuffleLocations` is now pluggable. We think however that previously Kryo was defaulting to Java serialization anyways, so we now just explicitly tell Kryo to use `ExternalizableSerializer` to deal with these objects. There's a small hack in the serialization protocol that attempts to avoid serializing the same `BlockManagerId` twice in the case that the map shuffle locations is a `DefaultMapShuffleLocations`.
- Loading branch information
1 parent
8b021b3
commit 16caee4
Showing
29 changed files
with
463 additions
and
125 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
core/src/main/java/org/apache/spark/api/shuffle/MapShuffleLocations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.spark.api.shuffle; | ||
|
||
import org.apache.spark.annotation.Experimental; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Represents metadata about where shuffle blocks were written in a single map task. | ||
* <p> | ||
* This is optionally returned by shuffle writers. The inner shuffle locations may | ||
* be accessed by shuffle readers. Shuffle locations are only necessary when the | ||
* location of shuffle blocks needs to be managed by the driver; shuffle plugins | ||
* may choose to use an external database or other metadata management systems to | ||
* track the locations of shuffle blocks instead. | ||
*/ | ||
@Experimental | ||
public interface MapShuffleLocations extends Serializable { | ||
|
||
/** | ||
* Get the location for a given shuffle block written by this map task. | ||
*/ | ||
ShuffleLocation getLocationForBlock(int reduceId); | ||
} |
25 changes: 25 additions & 0 deletions
25
core/src/main/java/org/apache/spark/api/shuffle/ShuffleLocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.api.shuffle; | ||
|
||
/** | ||
* Marker interface representing a location of a shuffle block. Implementations of shuffle readers | ||
* and writers are expected to cast this down to an implementation-specific representation. | ||
*/ | ||
public interface ShuffleLocation { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
core/src/main/java/org/apache/spark/shuffle/sort/DefaultMapShuffleLocations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.shuffle.sort; | ||
|
||
import com.google.common.cache.CacheBuilder; | ||
import com.google.common.cache.CacheLoader; | ||
import com.google.common.cache.LoadingCache; | ||
|
||
import org.apache.spark.api.shuffle.MapShuffleLocations; | ||
import org.apache.spark.api.shuffle.ShuffleLocation; | ||
import org.apache.spark.storage.BlockManagerId; | ||
|
||
import java.util.Objects; | ||
|
||
public class DefaultMapShuffleLocations implements MapShuffleLocations, ShuffleLocation { | ||
|
||
/** | ||
* We borrow the cache size from the BlockManagerId's cache - around 1MB, which should be | ||
* feasible. | ||
*/ | ||
private static final LoadingCache<BlockManagerId, DefaultMapShuffleLocations> | ||
DEFAULT_SHUFFLE_LOCATIONS_CACHE = | ||
CacheBuilder.newBuilder() | ||
.maximumSize(BlockManagerId.blockManagerIdCacheSize()) | ||
.build(new CacheLoader<BlockManagerId, DefaultMapShuffleLocations>() { | ||
@Override | ||
public DefaultMapShuffleLocations load(BlockManagerId blockManagerId) { | ||
return new DefaultMapShuffleLocations(blockManagerId); | ||
} | ||
}); | ||
|
||
private final BlockManagerId location; | ||
|
||
public DefaultMapShuffleLocations(BlockManagerId blockManagerId) { | ||
this.location = blockManagerId; | ||
} | ||
|
||
public static DefaultMapShuffleLocations get(BlockManagerId blockManagerId) { | ||
return DEFAULT_SHUFFLE_LOCATIONS_CACHE.getUnchecked(blockManagerId); | ||
} | ||
|
||
@Override | ||
public ShuffleLocation getLocationForBlock(int reduceId) { | ||
return this; | ||
} | ||
|
||
public BlockManagerId getBlockManagerId() { | ||
return location; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other instanceof DefaultMapShuffleLocations | ||
&& Objects.equals(((DefaultMapShuffleLocations) other).location, location); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(location); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.