spark-test commented on code in PR #57525:
URL: https://github.com/apache/spark/pull/57525#discussion_r4508703841


##########
core/src/test/scala/org/apache/spark/scheduler/CoarseGrainedSchedulerBackendSuite.scala:
##########
@@ -1073,6 +1085,74 @@ class CoarseGrainedSchedulerBackendSuite extends 
SparkFunSuite with LocalSparkCo
     (thread, request)
   }
 
+  test("SPARK-58322: reject stale executors after same-app-ID driver address 
reuse") {
+    sc = new SparkContext(new 
SparkConf().setMaster("local").setAppName("identity-swap"))
+    val scheduler = mock[TaskSchedulerImpl]
+    when(scheduler.sc).thenReturn(sc)
+    when(scheduler.excludedNodes()).thenReturn(Set.empty[String])
+    when(scheduler.resourceOffers(any[IndexedSeq[WorkerOffer]], any[Boolean]))
+      .thenReturn(Seq.empty)
+    val resourceProfileId = ResourceProfile.DEFAULT_RESOURCE_PROFILE_ID
+    var port = 0
+    var originalId = ""
+    for (attempt <- 0 until 2) {
+      val conf = new SparkConf().set("spark.port.maxRetries", "0")
+      val rpcEnv = RpcEnv.create("identity-driver", "localhost", port, conf,
+        new SecurityManager(conf))
+      val backend = new CoarseGrainedSchedulerBackend(scheduler, rpcEnv) {
+        override def applicationId(): String = "same-application-id"
+      }
+      val executorRpcEnv = RpcEnv.create("identity-executor", "localhost", 0, 
conf,
+        new SecurityManager(conf), clientMode = true)
+      try {
+        backend.start()
+        val driver = executorRpcEnv.setupEndpointRef(rpcEnv.address,
+          CoarseGrainedSchedulerBackend.ENDPOINT_NAME)
+        assert(backend.applicationId() == "same-application-id")
+        val instanceId = backend.driverInstanceId
+        assert(sc.conf.get(DRIVER_INSTANCE_ID) == instanceId)
+        val config = driver.askSync[SparkAppConfig](
+          RetrieveSparkAppConfigWithIdentity(resourceProfileId, instanceId))
+        assert(config.sparkProperties.contains(DRIVER_INSTANCE_ID.key -> 
instanceId))
+        if (attempt == 0) {
+          port = rpcEnv.address.port
+          originalId = instanceId
+        } else {
+          assert(rpcEnv.address.port == port)
+          assert(instanceId != originalId)
+          val bootstrapError = intercept[SparkException] {
+            driver.askSync[SparkAppConfig](
+              RetrieveSparkAppConfigWithIdentity(resourceProfileId, 
originalId))
+          }
+          assert(bootstrapError.getCause.getMessage.contains("does not match"))
+          val registrationError = intercept[SparkException] {
+            driver.askSync[Boolean](RegisterExecutor(
+              "stale-executor", null, "localhost", 1, Map.empty,
+              Map(DRIVER_INSTANCE_ID.key -> originalId), Map.empty, 
resourceProfileId))
+          }
+          assert(registrationError.getCause.getMessage.contains("does not 
match"))
+          val missingIdError = intercept[SparkException] {
+            driver.askSync[Boolean](RegisterExecutor(
+              "missing-id", null, "localhost", 1, Map.empty, Map.empty, 
Map.empty,

Review Comment:
   **Nit (P3):** This case sends no `spark.driver.instanceId` key at all, a 
form the in-tree senders never produce. When the launcher does not propagate 
the property, `CoarseGrainedExecutorBackend.run` and 
`KubernetesExecutorBackend.run` send `RetrieveSparkAppConfigWithIdentity` with 
`executorConf.get(DRIVER_INSTANCE_ID)`, which is `""`. `onStart` always adds 
the key, with an empty value when its conf lacks it. No test sends an empty or 
null bootstrap ID, or an empty registration attribute.
   
   So the bootstrap rejection has no regression signal, and the registration 
check does not backstop it. An executor admitted at bootstrap without an ID 
gets `spark.driver.instanceId` back in `sparkProperties`, and because startup 
keys are applied with `setIfMissing`, its conf adopts the driver's own ID and 
`onStart` registers with a matching one. A later change that let an empty ID 
through bootstrap, for example by guarding the check with 
`instanceId.nonEmpty`, would hand Spark properties and credentials to 
identity-less executors and register them, with every current test still 
passing.
   
   **Verification:**
   - **Regression:** A test sends the identity-carrying bootstrap request to a 
running scheduler backend once with an empty driver instance ID and once with a 
null one. It must fail if the driver returns any application config for either 
request, or if either rejection is anything other than the missing-ID failure.
   - **Regression:** A test registers an executor whose spark.driver.instanceId 
attribute is the empty string. It must fail if registration succeeds, if the 
rejection is not the missing-ID failure, or if the executor appears in the 
backend's executor set.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to