Skip to content

Commit a3e979f

Browse files
committed
address comments, and fix the test error
1 parent 1d863b7 commit a3e979f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

core/src/main/scala/org/apache/spark/storage/BlockManager.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,14 @@ private[spark] class BlockManager(
617617
private def getLocations(blockId: BlockId): Seq[BlockManagerId] = {
618618
val locs = Random.shuffle(master.getLocations(blockId))
619619
val (preferredLocs, otherLocs) = locs.partition { loc => blockManagerId.host == loc.host }
620-
val (sameRackLocs, differentRackLocs) = otherLocs.partition {
621-
loc => blockManagerId.topologyInfo == loc.topologyInfo
620+
blockManagerId.topologyInfo match {
621+
case None => preferredLocs ++ otherLocs
622+
case Some(_) =>
623+
val (sameRackLocs, differentRackLocs) = otherLocs.partition {
624+
loc => blockManagerId.topologyInfo == loc.topologyInfo
625+
}
626+
preferredLocs ++ sameRackLocs ++ differentRackLocs
622627
}
623-
preferredLocs ++ sameRackLocs ++ differentRackLocs
624628
}
625629

626630
/**

core/src/test/scala/org/apache/spark/storage/BlockManagerSuite.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ class BlockManagerSuite extends SparkFunSuite with Matchers with BeforeAndAfterE
497497
}
498498

499499
test("optimize a location order of blocks without topology information") {
500-
val localHost = Utils.localHostName()
500+
val localHost = "localhost"
501501
val otherHost = "otherHost"
502502
val bmMaster = mock(classOf[BlockManagerMaster])
503503
val bmId1 = BlockManagerId("id1", localHost, 1)
@@ -512,7 +512,7 @@ class BlockManagerSuite extends SparkFunSuite with Matchers with BeforeAndAfterE
512512
}
513513

514514
test("optimize a location order of blocks with topology information") {
515-
val localHost = Utils.localHostName()
515+
val localHost = "localhost"
516516
val otherHost = "otherHost"
517517
val localRack = "localRack"
518518
val otherRack = "otherRack"
@@ -527,6 +527,8 @@ class BlockManagerSuite extends SparkFunSuite with Matchers with BeforeAndAfterE
527527
.thenReturn(Seq(bmId1, bmId2, bmId5, bmId3, bmId4))
528528

529529
val blockManager = makeBlockManager(128, "exec", bmMaster)
530+
blockManager.blockManagerId =
531+
BlockManagerId(SparkContext.DRIVER_IDENTIFIER, localHost, 1, Some(localRack))
530532
val getLocations = PrivateMethod[Seq[BlockManagerId]]('getLocations)
531533
val locations = blockManager invokePrivate getLocations(BroadcastBlockId(0))
532534
assert(locations.map(_.host) === Seq(localHost, localHost, otherHost, otherHost, otherHost))

0 commit comments

Comments
 (0)