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] Driver lifecycle api (#533)
Introduce driver shuffle lifecycle APIs
- Loading branch information
Showing
11 changed files
with
241 additions
and
6 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
core/src/main/java/org/apache/spark/api/shuffle/ShuffleDriverComponents.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,33 @@ | ||
/* | ||
* 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 java.io.IOException; | ||
import java.util.Map; | ||
|
||
public interface ShuffleDriverComponents { | ||
|
||
/** | ||
* @return additional SparkConf values necessary for the executors. | ||
*/ | ||
Map<String, String> initializeApplication(); | ||
|
||
void cleanupApplication() throws IOException; | ||
|
||
void removeShuffleData(int shuffleId, boolean blocking) throws IOException; | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...src/main/java/org/apache/spark/shuffle/sort/lifecycle/DefaultShuffleDriverComponents.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,54 @@ | ||
/* | ||
* 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.lifecycle; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.apache.spark.SparkEnv; | ||
import org.apache.spark.api.shuffle.ShuffleDriverComponents; | ||
import org.apache.spark.storage.BlockManagerMaster; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class DefaultShuffleDriverComponents implements ShuffleDriverComponents { | ||
|
||
private BlockManagerMaster blockManagerMaster; | ||
|
||
@Override | ||
public Map<String, String> initializeApplication() { | ||
blockManagerMaster = SparkEnv.get().blockManager().master(); | ||
return ImmutableMap.of(); | ||
} | ||
|
||
@Override | ||
public void cleanupApplication() { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void removeShuffleData(int shuffleId, boolean blocking) throws IOException { | ||
checkInitialized(); | ||
blockManagerMaster.removeShuffle(shuffleId, blocking); | ||
} | ||
|
||
private void checkInitialized() { | ||
if (blockManagerMaster == null) { | ||
throw new IllegalStateException("Driver components must be initialized before using"); | ||
} | ||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
core/src/test/scala/org/apache/spark/shuffle/ShuffleDriverComponentsSuite.scala
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,71 @@ | ||
/* | ||
* 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 | ||
|
||
import java.util | ||
|
||
import com.google.common.collect.ImmutableMap | ||
|
||
import org.apache.spark.{LocalSparkContext, SparkConf, SparkContext, SparkEnv, SparkFunSuite} | ||
import org.apache.spark.api.shuffle.{ShuffleDataIO, ShuffleDriverComponents, ShuffleExecutorComponents, ShuffleWriteSupport} | ||
import org.apache.spark.internal.config.SHUFFLE_IO_PLUGIN_CLASS | ||
import org.apache.spark.shuffle.sort.io.DefaultShuffleWriteSupport | ||
|
||
class ShuffleDriverComponentsSuite extends SparkFunSuite with LocalSparkContext { | ||
test(s"test serialization of shuffle initialization conf to executors") { | ||
val testConf = new SparkConf() | ||
.setAppName("testing") | ||
.setMaster("local-cluster[2,1,1024]") | ||
.set(SHUFFLE_IO_PLUGIN_CLASS, "org.apache.spark.shuffle.TestShuffleDataIO") | ||
|
||
sc = new SparkContext(testConf) | ||
|
||
sc.parallelize(Seq((1, "one"), (2, "two"), (3, "three")), 3) | ||
.groupByKey() | ||
.collect() | ||
} | ||
} | ||
|
||
class TestShuffleDriverComponents extends ShuffleDriverComponents { | ||
override def initializeApplication(): util.Map[String, String] = | ||
ImmutableMap.of("test-key", "test-value") | ||
|
||
override def cleanupApplication(): Unit = {} | ||
|
||
override def removeShuffleData(shuffleId: Int, blocking: Boolean): Unit = {} | ||
} | ||
|
||
class TestShuffleDataIO(sparkConf: SparkConf) extends ShuffleDataIO { | ||
override def driver(): ShuffleDriverComponents = new TestShuffleDriverComponents() | ||
|
||
override def executor(): ShuffleExecutorComponents = | ||
new TestShuffleExecutorComponents(sparkConf) | ||
} | ||
|
||
class TestShuffleExecutorComponents(sparkConf: SparkConf) extends ShuffleExecutorComponents { | ||
override def initializeExecutor(appId: String, execId: String, | ||
extraConfigs: util.Map[String, String]): Unit = { | ||
assert(extraConfigs.get("test-key") == "test-value") | ||
} | ||
|
||
override def writes(): ShuffleWriteSupport = { | ||
val blockManager = SparkEnv.get.blockManager | ||
val blockResolver = new IndexShuffleBlockResolver(sparkConf, blockManager) | ||
new DefaultShuffleWriteSupport(sparkConf, blockResolver) | ||
} | ||
} |
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