Github user shubhamchopra commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13932#discussion_r108203064
  
    --- Diff: 
core/src/test/scala/org/apache/spark/storage/BlockReplicationPolicySuite.scala 
---
    @@ -68,7 +68,60 @@ class BlockReplicationPolicySuite extends SparkFunSuite
           logDebug(s"Random peers : ${secondPass.mkString(", ")}")
           assert(secondPass.toSet.size === numReplicas)
         }
    +  }
    +
    +  protected def generateBlockManagerIds(count: Int, racks: Seq[String]): 
Seq[BlockManagerId] = {
    +    (1 to count).map{i =>
    +      BlockManagerId(s"Exec-$i", s"Host-$i", 10000 + i, 
Some(racks(Random.nextInt(racks.size))))
    +    }
    +  }
    +}
    +
    +class TopologyAwareBlockReplicationPolicyBehavior extends 
RandomBlockReplicationPolicyBehavior {
    +  override val replicationPolicy = new BasicBlockReplicationPolicy
    +
    +  test("All peers in the same rack") {
    +    val racks = Seq("/default-rack")
    +    val numBlockManager = 10
    +    (1 to 10).foreach {numReplicas =>
    +      val peers = generateBlockManagerIds(numBlockManager, racks)
    +      val blockManager = BlockManagerId("Driver", "Host-driver", 10001, 
Some(racks.head))
    +
    +      val prioritizedPeers = replicationPolicy.prioritize(
    +        blockManager,
    +        peers,
    +        mutable.HashSet.empty,
    +        blockId,
    +        numReplicas
    +      )
     
    +      assert(prioritizedPeers.toSet.size == numReplicas)
    +      assert(prioritizedPeers.forall(p => p.host != blockManager.host))
    +    }
       }
     
    +  test("Peers in 2 racks") {
    +    val racks = Seq("/Rack-1", "/Rack-2")
    +    (1 to 10).foreach {numReplicas =>
    +      val peers = generateBlockManagerIds(10, racks)
    +      val blockManager = BlockManagerId("Driver", "Host-driver", 9001, 
Some(racks.head))
    +
    +      val prioritizedPeers = replicationPolicy.prioritize(
    +        blockManager,
    +        peers,
    +        mutable.HashSet.empty,
    +        blockId,
    +        numReplicas
    +      )
    +
    +      assert(prioritizedPeers.toSet.size == numReplicas)
    +      val priorityPeers = prioritizedPeers.take(2)
    +      assert(priorityPeers.forall(p => p.host != blockManager.host))
    +      if(numReplicas > 1) {
    +        // both these conditions should be satisfied when numReplicas > 1
    +        assert(priorityPeers.exists(p => p.topologyInfo == 
blockManager.topologyInfo))
    +        assert(priorityPeers.exists(p => p.topologyInfo != 
blockManager.topologyInfo))
    --- End diff --
    
    My intended behavior is to ensure one is within rack and one outside, not 
necessarily the first or the second.


---
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]

Reply via email to