joewitt opened a new pull request, #11996:
URL: https://github.com/apache/nifi/pull/11996

   # Summary
   
   [NIFI-16665](https://issues.apache.org/jira/browse/NIFI-16665)
   
   `NodeClusterCoordinator.validateHeartbeat` (added with NIFI-8204) requests a 
reconnect when a node's heartbeat has a Revision Update Count larger than the 
coordinator's. The coordinator increments its count only after its own update 
task returns. A cluster-wide update runs on all nodes at about the same time, 
so a node that finishes first can send its next heartbeat before the 
coordinator finishes the same update. The heartbeat monitor then reconnects a 
healthy node. This is related to NIFI-13885 and NIFI-15839.
   
   Two system-test failures match this:
   
   - `OffloadIT.testOffload` on macOS, run 
[46473747623](https://github.com/apache/nifi/actions/runs/46473747623): `Node 
has a Revision Update Count of 12 but local value is only 11`
   - `LoadBalanceIT.testPartitionByAttribute` on Ubuntu, run 
[45459725674](https://github.com/apache/nifi/actions/runs/45459725674): `Node 
has a Revision Update Count of 444 but local value is only 443`
   
   In both, the coordinator had started the update task but had not yet 
incremented its count when the monitor checked.
   
   Changes:
   
   - `RevisionManager.isRevisionUpdateInProgress()` is a new default method 
that returns `false`. It is `true` while any `updateRevision` or 
`deleteRevision` call has started and not completed, including calls waiting 
for another update.
   - `NaiveRevisionManager` counts those calls. The counter is incremented 
before the call waits for the lock and decremented only after the update count 
is incremented.
   - `validateHeartbeat` reads the in-progress state before the update count. 
If the node is ahead and an update is in progress, it does nothing. If the node 
is ahead and no update is in progress, it requests a reconnect only when the 
node was also ahead on the previous check. The observation is cleared when the 
node is not ahead, when its connection state changes, and when it is removed.
   
   A node whose count is truly wrong is still reconnected, one heartbeat check 
later than before (2 seconds in the system tests, 5 seconds by default).
   
   What this does and does not show:
   
   - With a 2.5 second stall injected into the coordinator's update task, the 
original code reconnects the node and this change does not. This confirms the 
mechanism.
   - I did not find what makes the coordinator's update task slow enough in CI. 
Measured on a quiet laptop, update tasks took 1 ms at the median, 48 ms at p99 
and 94 ms at most. The Ubuntu incident implies a window of about 63 ms. The 
macOS incident implies at least 0.6 to 1.6 seconds.
   - A delay before the update reaches the revision manager is not covered by 
the in-progress check. It is covered only by requiring two consecutive 
observations.
   
   Questions for reviewers:
   
   - Is one additional heartbeat check of delay acceptable for the NIFI-8204 
recovery case, or should only the in-progress check be kept?
   - If a revision update is stuck, the check is skipped for as long as it 
runs. That also blocks flow changes on that node, so I did not add a limit. 
Should there be one?
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue 
created
   
   ### Pull Request Tracking
   
   - [x] Pull Request title starts with Apache NiFi Jira issue number, such as 
`NIFI-00000`
   - [x] Pull Request commit message starts with Apache NiFi Jira issue number, 
as such `NIFI-00000`
   - [x] Pull request contains [commits 
signed](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits)
 with a registered key indicating `Verified` status
   
   ### Pull Request Formatting
   
   - [x] Pull Request based on current revision of the `main` branch
   - [x] Pull Request refers to a feature branch with one commit containing 
changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request 
creation.
   
   ### Build
   
   - [ ] Build completed using `./mvnw clean install -P contrib-check`
     - [ ] JDK 21
     - [ ] JDK 25
   
   Ran `./mvnw -P contrib-check verify` on the three changed modules only, 
`nifi-framework-core-api`, `nifi-framework-cluster` and 
`nifi-web-optimistic-locking`, with JDK 21 and JDK 25. Both builds succeeded 
(53, 239 and 7 tests, 0 failures).
   
   ### Verification performed
   
   - [x] Nine new tests in `TestNodeClusterCoordinator` cover: an update in 
progress, a node ahead once, a node ahead on consecutive checks, a node far 
ahead of an idle coordinator, a node that catches up, an in-progress check 
between two observations, a node that is not ahead, per-node tracking, and a 
node status change clearing the observation
   - [x] Seven new tests in `NaiveRevisionManagerTest` cover: the initial 
state, in progress during an update and a delete task, not in progress after a 
failed task or a rejected stale revision, and in progress while waiting for 
another update
   - [x] A 2.5 second stall injected into the coordinator's update task in a 
two-node `OffloadIT` run on a patched build: the original code reconnects the 
node, this change does not
   
   ### Licensing
   
   - [ ] New dependencies are compatible with the [Apache License 
2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License 
Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` 
files
   
   Not applicable: no dependencies are added or changed.
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   
   Not applicable: no documentation is changed.
   


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

Reply via email to