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

    https://github.com/apache/spark/pull/18092#discussion_r121281612
  
    --- Diff: 
core/src/test/scala/org/apache/spark/storage/BlockManagerSuite.scala ---
    @@ -1281,6 +1285,57 @@ class BlockManagerSuite extends SparkFunSuite with 
Matchers with BeforeAndAfterE
         assert(master.getLocations("item").isEmpty)
       }
     
    +  test("SPARK-20640: Shuffle registration timeout and maxAttempts conf are 
working") {
    +    val shufflePort = 10000
    +    val tryAgainMsg = "test_spark_20640_try_again"
    +    conf.set("spark.shuffle.service.enabled", "true")
    +    conf.set("spark.shuffle.service.port", shufflePort.toString)
    +    // a server which delays response 50ms and must try twice for success.
    +    def newShuffleServer(): TransportServer = {
    +      val attempts = new mutable.HashMap[String, Int]()
    +      val handler = new NoOpRpcHandler {
    +        override def receive(client: TransportClient, message: ByteBuffer,
    +                             callback: RpcResponseCallback): Unit = {
    +          val msgObj = BlockTransferMessage.Decoder.fromByteBuffer(message)
    +          msgObj match {
    +            case exec: RegisterExecutor =>
    +              Thread.sleep(50)
    +              val attempt = attempts.getOrElse(exec.execId, 0) + 1
    +              attempts(exec.execId) = attempt
    +              if (attempt < 2) {
    +                callback.onFailure(new Exception(tryAgainMsg))
    +                return
    +              }
    +              callback.onSuccess(ByteBuffer.wrap(new Array[Byte](0)))
    +          }
    +        }
    +      }
    +
    +      val transConf = SparkTransportConf.fromSparkConf(conf, "shuffle", 
numUsableCores = 0)
    +      val transCtx = new TransportContext(transConf, handler, true)
    +      transCtx.createServer(shufflePort, 
Nil.asInstanceOf[Seq[TransportServerBootstrap]].asJava)
    +    }
    +    newShuffleServer()
    +
    +    conf.set(SHUFFLE_REGISTRATION_TIMEOUT.key, "40")
    +    conf.set(SHUFFLE_REGISTRATION_MAX_ATTEMPTS.key, "1")
    +    var e = intercept[SparkException]{
    +      makeBlockManager(8000, "executor1")
    +    }.getMessage
    +    assert(e.contains("TimeoutException"))
    +
    +    conf.set(SHUFFLE_REGISTRATION_TIMEOUT.key, "1000")
    +    conf.set(SHUFFLE_REGISTRATION_MAX_ATTEMPTS.key, "1")
    +    e = intercept[SparkException]{
    --- End diff --
    
    Hi, what's your suggestion?  When attempt < 2, we already return an error 
`tryAgainMsg`. The request must fail if specified time is not passed, and 
succeed otherwise, there seems to be no other choice besides `sleep`.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to