Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/9214#discussion_r43952983
--- Diff: core/src/test/scala/org/apache/spark/ShuffleSuite.scala ---
@@ -317,6 +309,156 @@ abstract class ShuffleSuite extends SparkFunSuite
with Matchers with LocalSparkC
assert(metrics.bytesWritten === metrics.byresRead)
assert(metrics.bytesWritten > 0)
}
+
+ /**
+ * ShuffleOutputCoordinator requires that a given shuffle always
generate the same set of files on
+ * all attempts, even if the data is non-deterministic. We test the
extreme case where the data
+ * is completely missing in one case
+ */
+ test("same set of shuffle files regardless of data") {
+
+ def shuffleAndGetShuffleFiles(data: Seq[Int]): Map[String, Long] = {
+ var tempDir: File = null
+ try {
+ tempDir = Utils.createTempDir()
+ conf.set("spark.local.dir", tempDir.getAbsolutePath)
+ sc = new SparkContext("local", "test", conf)
+ val rdd = sc.parallelize(data, 10).map(x => (x, x))
+ val shuffledRdd = new ShuffledRDD[Int, Int, Int](rdd, new
HashPartitioner(4))
+ shuffledRdd.count()
+ val shuffleFiles =
+ FileUtils.listFiles(tempDir, TrueFileFilter.INSTANCE,
TrueFileFilter.INSTANCE)
+ sc.stop()
+ shuffleFiles.asScala.map { file: File =>
+ file.getName -> file.length()
+ }.toMap
+ } finally {
+ conf.remove("spark.local.dir")
+ Utils.deleteRecursively(tempDir)
+ }
+ }
+
+ val shuffleFilesWithData = shuffleAndGetShuffleFiles(0 until 100)
+ val shuffleFilesNoData = shuffleAndGetShuffleFiles(Seq[Int]())
+ assert(shuffleFilesNoData.keySet === shuffleFilesWithData.keySet)
+ // make sure our test is doing what it is supposed to -- at least some
of the
+ // "no data" files are empty
+ assert(shuffleFilesNoData.filter{ case (name, size) =>
+ size == 0L && shuffleFilesWithData(name) != 0L
+ }.nonEmpty)
+ }
+
+ test("multiple simultaneous attempts for one task (SPARK-8029)") {
+ sc = new SparkContext("local", "test", conf)
+ val mapStatusFile =
sc.env.blockManager.diskBlockManager.getFile(ShuffleMapStatusBlockId(0, 0))
+ val mapTrackerMaster =
sc.env.mapOutputTracker.asInstanceOf[MapOutputTrackerMaster]
+ val manager = sc.env.shuffleManager
+
+ val taskMemoryManager = new TaskMemoryManager(sc.env.memoryManager, 0L)
+ val metricsSystem = sc.env.metricsSystem
+ val shuffleMapRdd = new MyRDD(sc, 1, Nil)
+ val shuffleDep = new ShuffleDependency(shuffleMapRdd, new
HashPartitioner(1))
+ val shuffleHandle = manager.registerShuffle(0, 1, shuffleDep)
+
+ // first attempt -- its successful
+ val writer1 = manager.getWriter[Int, Int](shuffleHandle, 0,
+ new TaskContextImpl(0, 0, 0L, 0, taskMemoryManager, metricsSystem,
+ InternalAccumulator.create(sc)))
+ val data1 = (1 to 10).map { x => x -> x}
+
+ // second attempt -- also successful. We'll write out different data,
+ // just to simulate the fact that the records may get written
differently
+ // depending on what gets spilled, what gets combined, etc.
+ val writer2 = manager.getWriter[Int, Int](shuffleHandle, 0,
+ new TaskContextImpl(0, 0, 1L, 0, taskMemoryManager, metricsSystem,
+ InternalAccumulator.create(sc)))
+ val data2 = (11 to 20).map { x => x -> x}
+
+ // interleave writes of both attempts -- we want to test that both
attempts can occur
+ // simultaneously, and everything is still OK
+
+ def writeAndClose(
+ writer: ShuffleWriter[Int, Int])(
--- End diff --
Indentation.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]