This is an automated email from the ASF dual-hosted git repository.
pvillard31 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 99f0fd37b15 NIFI-16664 Corrected node status update identifiers to
prevent offload hang (#11995)
99f0fd37b15 is described below
commit 99f0fd37b15c81e092781f9f8a7d03f842be4b7f
Author: Joe Witt <[email protected]>
AuthorDate: Fri Dec 4 04:54:31 2026 -0700
NIFI-16664 Corrected node status update identifiers to prevent offload hang
(#11995)
- Changed requestNodeDisconnect to keep the existing status when a node is
already disconnected for the same code and reason
- Changed NodeConnectionStatus.updateIdGenerator to make the next update
identifier greater than the received identifier
- Added tests for repeated disconnect requests, update identifier ordering,
and offload after a repeated disconnect request
---
.../coordination/node/NodeConnectionStatus.java | 9 +--
.../coordination/node/NodeClusterCoordinator.java | 18 +++++-
.../node/TestNodeClusterCoordinator.java | 75 ++++++++++++++++++++++
3 files changed, 97 insertions(+), 5 deletions(-)
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionStatus.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionStatus.java
index 7d3e270aa7b..eb246b10ee5 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionStatus.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionStatus.java
@@ -130,12 +130,13 @@ public class NodeConnectionStatus {
}
/**
- * Updates the ID Generator so that it is at least equal to the given
minimum value
+ * Updates the ID Generator so that the next Update Identifier is greater
than the given value
*
- * @param minimumValue the minimum value that the ID Generator should be
set to
+ * @param lastUsedValue the highest Update Identifier that is known to
have been used
*/
- static void updateIdGenerator(long minimumValue) {
- idGenerator.updateAndGet(curValue -> Math.max(minimumValue, curValue));
+ static void updateIdGenerator(long lastUsedValue) {
+ final long nextValue = lastUsedValue + 1;
+ idGenerator.updateAndGet(curValue -> Math.max(nextValue, curValue));
}
@Override
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java
index 4e6fe996a70..cb796f7a86d 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/node/NodeClusterCoordinator.java
@@ -587,7 +587,12 @@ public class NodeClusterCoordinator implements
ClusterCoordinator, ProtocolHandl
logger.info("Requesting that {} disconnect due to {}", nodeId,
explanation == null ? disconnectionCode : explanation);
- updateNodeStatus(new NodeConnectionStatus(nodeId, disconnectionCode,
explanation));
+ // A node that is already disconnected for the same reason keeps its
current status. Replacing it would create a status with a newer
+ // Update Identifier that is not sent to the other nodes because the
state does not change. A later status update from another node,
+ // such as the Offload request from a newly elected Cluster
Coordinator, would then be rejected as older than the status of this node.
+ if (!isAlreadyDisconnected(nodeId, disconnectionCode, explanation)) {
+ updateNodeStatus(new NodeConnectionStatus(nodeId,
disconnectionCode, explanation));
+ }
// There is no need to tell the node that it's disconnected if it is
due to being
// shutdown, as we will not be able to connect to the node anyway.
@@ -603,6 +608,17 @@ public class NodeClusterCoordinator implements
ClusterCoordinator, ProtocolHandl
return disconnectAsynchronously(request, 10, 5);
}
+ private boolean isAlreadyDisconnected(final NodeIdentifier nodeId, final
DisconnectionCode disconnectionCode, final String explanation) {
+ final NodeConnectionStatus currentStatus =
nodeStatuses.get(nodeId.getId());
+ if (currentStatus == null || currentStatus.getState() !=
NodeConnectionState.DISCONNECTED) {
+ return false;
+ }
+
+ return disconnectionCode != null
+ && disconnectionCode == currentStatus.getDisconnectCode()
+ && Objects.equals(explanation, currentStatus.getReason());
+ }
+
@Override
public void disconnectionRequestedByNode(final NodeIdentifier nodeId,
final DisconnectionCode disconnectionCode, final String explanation) {
logger.info("{} requested disconnection from cluster due to {}",
nodeId, explanation == null ? disconnectionCode : explanation);
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java
index 8d50813d20c..ef4b6624df0 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java
@@ -396,6 +396,81 @@ public class TestNodeClusterCoordinator {
coordinator.requestNodeDisconnect(nodeId2,
DisconnectionCode.USER_DISCONNECTED, "Unit Test");
}
+ @Test
+ public void
testRepeatedDisconnectRequestKeepsUpdateIdentifierOfDisconnectedNode() {
+ final NodeIdentifier nodeId = createNodeId(1);
+ coordinator.updateNodeStatus(new NodeConnectionStatus(createNodeId(2),
NodeConnectionState.CONNECTED));
+ coordinator.requestNodeDisconnect(nodeId,
DisconnectionCode.USER_DISCONNECTED, "Unit Test");
+
+ final NodeConnectionStatus disconnectedStatus =
coordinator.getConnectionStatus(nodeId);
+ assertEquals(NodeConnectionState.DISCONNECTED,
disconnectedStatus.getState());
+
+ // This is what happens when a heartbeat that was sent before the node
disconnected is received
+ coordinator.requestNodeDisconnect(nodeId,
DisconnectionCode.USER_DISCONNECTED, "Unit Test");
+
+ final NodeConnectionStatus statusAfterRepeatedRequest =
coordinator.getConnectionStatus(nodeId);
+ assertEquals(NodeConnectionState.DISCONNECTED,
statusAfterRepeatedRequest.getState());
+ assertEquals(disconnectedStatus.getUpdateIdentifier(),
statusAfterRepeatedRequest.getUpdateIdentifier(),
+ "Repeating a disconnect request must not create a newer status
that other nodes do not know about");
+ }
+
+ @Test
+ public void
testDisconnectRequestWithDifferentCodeReplacesDisconnectedStatus() {
+ final NodeIdentifier nodeId = createNodeId(1);
+ coordinator.updateNodeStatus(new NodeConnectionStatus(createNodeId(2),
NodeConnectionState.CONNECTED));
+ coordinator.requestNodeDisconnect(nodeId,
DisconnectionCode.USER_DISCONNECTED, "Unit Test");
+ final long firstUpdateId =
coordinator.getConnectionStatus(nodeId).getUpdateIdentifier();
+
+ coordinator.requestNodeDisconnect(nodeId,
DisconnectionCode.LACK_OF_HEARTBEAT, "No heartbeat");
+
+ final NodeConnectionStatus status =
coordinator.getConnectionStatus(nodeId);
+ assertEquals(DisconnectionCode.LACK_OF_HEARTBEAT,
status.getDisconnectCode());
+ assertTrue(status.getUpdateIdentifier() > firstUpdateId);
+ }
+
+ @Test
+ public void
testOffloadRequestAfterRepeatedDisconnectRequestIsAppliedByDisconnectedNode() {
+ // The disconnected node (and former Cluster Coordinator) receives a
late heartbeat from itself and repeats the disconnect request.
+ // The new Cluster Coordinator, which only knows the first
Disconnected status, then requests the offload with an update identifier
+ // that is not newer than that status. The disconnected node must
still apply it.
+ final NodeIdentifier nodeId = createNodeId(1);
+ coordinator.updateNodeStatus(new NodeConnectionStatus(createNodeId(2),
NodeConnectionState.CONNECTED));
+ coordinator.requestNodeDisconnect(nodeId,
DisconnectionCode.USER_DISCONNECTED, "Unit Test");
+ final long knownUpdateId =
coordinator.getConnectionStatus(nodeId).getUpdateIdentifier();
+ coordinator.requestNodeDisconnect(nodeId,
DisconnectionCode.USER_DISCONNECTED, "Unit Test");
+
+ final NodeConnectionStatus offloadingStatus = new
NodeConnectionStatus(knownUpdateId, nodeId, NodeConnectionState.OFFLOADING,
+ OffloadCode.OFFLOADED, null, "Unit Test", null);
+ final NodeStatusChangeMessage message = new NodeStatusChangeMessage();
+ message.setNodeId(nodeId);
+ message.setNodeConnectionStatus(offloadingStatus);
+ coordinator.handle(message, Collections.emptySet());
+
+ assertEquals(NodeConnectionState.OFFLOADING,
coordinator.getConnectionStatus(nodeId).getState());
+ }
+
+ @Test
+ public void testLocallyCreatedStatusIsNewerThanReceivedStatus() {
+ final NodeIdentifier nodeId = createNodeId(1);
+ coordinator.updateNodeStatus(new NodeConnectionStatus(nodeId,
DisconnectionCode.USER_DISCONNECTED));
+
+ final long receivedUpdateId = 1_000_000L;
+ final NodeConnectionStatus receivedStatus = new
NodeConnectionStatus(receivedUpdateId, nodeId, NodeConnectionState.DISCONNECTED,
+ null, DisconnectionCode.USER_DISCONNECTED, "Unit Test", null);
+ final NodeStatusChangeMessage message = new NodeStatusChangeMessage();
+ message.setNodeId(nodeId);
+ message.setNodeConnectionStatus(receivedStatus);
+ coordinator.handle(message, Collections.emptySet());
+ assertEquals(receivedUpdateId,
coordinator.getConnectionStatus(nodeId).getUpdateIdentifier());
+
+ coordinator.requestNodeOffload(nodeId, OffloadCode.OFFLOADED, "Unit
Test");
+
+ final NodeConnectionStatus offloadingStatus =
coordinator.getConnectionStatus(nodeId);
+ assertEquals(NodeConnectionState.OFFLOADING,
offloadingStatus.getState());
+ assertTrue(offloadingStatus.getUpdateIdentifier() > receivedUpdateId,
+ "Status created after receiving update " + receivedUpdateId + "
must have a newer update identifier but was " +
offloadingStatus.getUpdateIdentifier());
+ }
+
@Test
@Timeout(value = 5)
public void testUpdateNodeStatusOutOfOrder() throws InterruptedException {