sarutak commented on code in PR #60142:
URL: https://github.com/apache/spark/pull/60142#discussion_r4510305907
##########
resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/YarnAllocator.scala:
##########
@@ -476,14 +476,19 @@ private[yarn] class YarnAllocator(
// Some of the nodes are put in decommissioning state where RM did allocate
// resources on those nodes for earlier allocateResource calls, so
notifying driver
// to put those executors in decommissioning state
- allocateResponse.getUpdatedNodes.asScala.filter (node =>
- node.getNodeState == NodeState.DECOMMISSIONING &&
- !decommissioningNodesCache.containsKey(getHostAddress(node)))
- .foreach { node =>
- val host = getHostAddress(node)
- driverRef.send(DecommissionExecutorsOnHost(host))
- decommissioningNodesCache.put(host, true)
+ allocateResponse.getUpdatedNodes.asScala.foreach { node =>
+ val host = getHostAddress(node)
+ node.getNodeState match {
+ case NodeState.DECOMMISSIONING if
!decommissioningNodesCache.containsKey(host) =>
+ driverRef.send(DecommissionExecutorsOnHost(host))
+ decommissioningNodesCache.put(host, true)
+ case NodeState.RUNNING =>
+ // The node was recommissioned (YARN-10538 reports it as RUNNING
again). Forget it so
+ // that a later decommissioning of the same node is notified to the
driver again.
Review Comment:
nit: as you confirmed in the conversation, RUNNING is also reported when a
node re-registers after being DECOMMISSIONED (`AddNodeTransition` then
`reportNodeRunning`), and this branch handles that too. Maybe something like:
```scala
// The node is usable again, e.g. recommissioned (YARN-10538) or
re-registered.
// Forget it so that a later decommissioning of the same node is
notified to the
// driver again.
```
##########
resource-managers/yarn/src/test/scala/org/apache/spark/deploy/yarn/YarnAllocatorSuite.scala:
##########
@@ -881,6 +881,56 @@ class YarnAllocatorSuite extends SparkFunSuite
send(DecommissionExecutorsOnHost(org.mockito.ArgumentMatchers.any()))
}
+ test("SPARK-60914: node recommissioned and decommissioned again should be " +
+ "decommissioned again") {
+ sparkConf.set(DECOMMISSION_ENABLED.key, "true")
+ val rmClient: AMRMClient[ContainerRequest] = AMRMClient.createAMRMClient()
+ val rmClientSpy = spy[AMRMClient[ContainerRequest]](rmClient)
+ val allocateResponse = mock(classOf[AllocateResponse])
+ val (handler, _) = createAllocator(1, rmClientSpy)
+
+ val container1 = createContainer("host1")
+ when(allocateResponse.getAllocatedContainers)
+ .thenReturn(new util.ArrayList[Container](Seq(container1).asJava))
+ when(allocateResponse.getUpdatedNodes).thenReturn(new
util.ArrayList[NodeReport]())
+ doAnswer(new Answer[AnyRef]() {
+ override def answer(invocationOnMock: InvocationOnMock):
AllocateResponse = allocateResponse
+ }).when(rmClientSpy).allocate(org.mockito.ArgumentMatchers.anyFloat())
+
+ // Heartbeat 1: one container allocated on host1, no node updates.
+ handler.allocateResources()
+ verify(rpcEndPoint, times(0)).send(DecommissionExecutorsOnHost("host1"))
+
+ def nodeReportWithState(state: NodeState): util.List[NodeReport] = {
+ val nodeReport = mock(classOf[NodeReport])
+ val nodeId = mock(classOf[NodeId])
+ when(nodeReport.getNodeState).thenReturn(state)
+ when(nodeReport.getNodeId).thenReturn(nodeId)
+ when(nodeId.getHost).thenReturn("host1")
+ new util.ArrayList[NodeReport](Seq(nodeReport).asJava)
+ }
+
+ // Heartbeat 2: host1 goes DECOMMISSIONING, executors on it must be
decommissioned.
+ when(allocateResponse.getAllocatedContainers).thenReturn(new
util.ArrayList[Container]())
+ val decommissioning1 = nodeReportWithState(NodeState.DECOMMISSIONING)
+ when(allocateResponse.getUpdatedNodes).thenReturn(decommissioning1)
+ handler.allocateResources()
+ verify(rpcEndPoint, times(1)).send(DecommissionExecutorsOnHost("host1"))
+
+ // Heartbeat 3: host1 is recommissioned, YARN reports it as RUNNING again.
+ val running = nodeReportWithState(NodeState.RUNNING)
+ when(allocateResponse.getUpdatedNodes).thenReturn(running)
+ handler.allocateResources()
+ verify(rpcEndPoint, times(1)).send(DecommissionExecutorsOnHost("host1"))
+
+ // Heartbeat 4: host1 goes DECOMMISSIONING a second time. Executors
launched on host1
+ // after the recommission must be decommissioned as well.
+ val decommissioning2 = nodeReportWithState(NodeState.DECOMMISSIONING)
+ when(allocateResponse.getUpdatedNodes).thenReturn(decommissioning2)
+ handler.allocateResources()
+ verify(rpcEndPoint, times(2)).send(DecommissionExecutorsOnHost("host1"))
Review Comment:
Could you extend this test a bit? The dedup guard was not covered before
either, but since this PR rewrites it into `case NodeState.DECOMMISSIONING if
!decommissioningNodesCache.containsKey(host)`, it would be good to pin it now:
no test sends DECOMMISSIONING again for a host that is still in the cache (here
a RUNNING report always comes in between), and every node report here is for
host1 only. So dropping the guard, dropping the `put`, or replacing
`remove(host)` with `clear()` still passes both "Test YARN container
decommissioning" and this test. I tried the change below locally: it adds a
second DECOMMISSIONING heartbeat before the RUNNING one, plus a host2 that
stays DECOMMISSIONING while host1 is recommissioned. Each of those three
changes, and removing the RUNNING case, makes the test fail, and it passes on
the current head. (Heartbeat 3 pins the guard even though the RM does not
normally re-send DECOMMISSIONING for a node that is already DECOMMISSIONING.)
It also rewords t
he heartbeat comments to say the driver is notified, since the test does not
allocate any container on host1 after the recommission and
`DecommissionExecutorsOnHost` only carries the host.
<details>
<summary>diff</summary>
```diff
- def nodeReportWithState(state: NodeState): util.List[NodeReport] = {
- val nodeReport = mock(classOf[NodeReport])
- val nodeId = mock(classOf[NodeId])
- when(nodeReport.getNodeState).thenReturn(state)
- when(nodeReport.getNodeId).thenReturn(nodeId)
- when(nodeId.getHost).thenReturn("host1")
- new util.ArrayList[NodeReport](Seq(nodeReport).asJava)
+ def nodeReports(states: (String, NodeState)*): util.List[NodeReport] = {
+ val reports = states.map { case (host, state) =>
+ val nodeReport = mock(classOf[NodeReport])
+ val nodeId = mock(classOf[NodeId])
+ when(nodeReport.getNodeState).thenReturn(state)
+ when(nodeReport.getNodeId).thenReturn(nodeId)
+ when(nodeId.getHost).thenReturn(host)
+ nodeReport
+ }
+ new util.ArrayList[NodeReport](reports.asJava)
}
- // Heartbeat 2: host1 goes DECOMMISSIONING, executors on it must be
decommissioned.
+ // Heartbeat 2: host1 and host2 go DECOMMISSIONING, the driver is
notified for both.
when(allocateResponse.getAllocatedContainers).thenReturn(new
util.ArrayList[Container]())
- val decommissioning1 = nodeReportWithState(NodeState.DECOMMISSIONING)
+ val decommissioning1 = nodeReports(
+ "host1" -> NodeState.DECOMMISSIONING, "host2" ->
NodeState.DECOMMISSIONING)
when(allocateResponse.getUpdatedNodes).thenReturn(decommissioning1)
handler.allocateResources()
verify(rpcEndPoint, times(1)).send(DecommissionExecutorsOnHost("host1"))
+ verify(rpcEndPoint, times(1)).send(DecommissionExecutorsOnHost("host2"))
+
+ // Heartbeat 3: both are still DECOMMISSIONING, the driver must not be
notified again.
+ val decommissioningAgain = nodeReports(
+ "host1" -> NodeState.DECOMMISSIONING, "host2" ->
NodeState.DECOMMISSIONING)
+ when(allocateResponse.getUpdatedNodes).thenReturn(decommissioningAgain)
+ handler.allocateResources()
+ verify(rpcEndPoint, times(1)).send(DecommissionExecutorsOnHost("host1"))
+ verify(rpcEndPoint, times(1)).send(DecommissionExecutorsOnHost("host2"))
- // Heartbeat 3: host1 is recommissioned, YARN reports it as RUNNING
again.
- val running = nodeReportWithState(NodeState.RUNNING)
+ // Heartbeat 4: host1 is recommissioned, YARN reports it as RUNNING
again.
+ val running = nodeReports("host1" -> NodeState.RUNNING)
when(allocateResponse.getUpdatedNodes).thenReturn(running)
handler.allocateResources()
verify(rpcEndPoint, times(1)).send(DecommissionExecutorsOnHost("host1"))
- // Heartbeat 4: host1 goes DECOMMISSIONING a second time. Executors
launched on host1
- // after the recommission must be decommissioned as well.
- val decommissioning2 = nodeReportWithState(NodeState.DECOMMISSIONING)
+ // Heartbeat 5: host1 goes DECOMMISSIONING a second time and the driver
must be notified
+ // again. host2 was never recommissioned, so it must not be notified
again.
+ val decommissioning2 = nodeReports(
+ "host1" -> NodeState.DECOMMISSIONING, "host2" ->
NodeState.DECOMMISSIONING)
when(allocateResponse.getUpdatedNodes).thenReturn(decommissioning2)
handler.allocateResources()
verify(rpcEndPoint, times(2)).send(DecommissionExecutorsOnHost("host1"))
+ verify(rpcEndPoint, times(1)).send(DecommissionExecutorsOnHost("host2"))
```
</details>
--
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]