Repository navigation
fix(#9554): accept peers' cluster token while the HA plugin starts and stops - #9566
Conversation
…and stops The HTTP gate and the snapshot route read the cluster token through server.getHA(), which RaftHAPlugin sets only once raft.start() returns and whose Raft server it drops when it stops. Ratis can be elected leader inside raft.start(), and HA stops before the HTTP listener, so in both windows a peer's correct token was compared against the empty raw setting and the forward was answered 401 "Invalid cluster token". - HAServerPlugin.effectiveClusterToken finds the registered HA plugin when getHA() does not name one yet - RaftHAPlugin keeps the token of the Raft server it stopped - SnapshotHttpHandler uses the shared helper instead of its own lookup Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 34 minutes. View limit detailsLimit details: You’ve used all 4 included reviews currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 4 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
ReviewThe fix is sound and well scoped. The root cause is correctly identified, the snapshot handler now shares the common helper instead of keeping its own copy of the lookup, and the tests reproduce both windows. No blocking issues. What I checked
Minor suggestions (non-blocking)
Conventions
LGTM, pending CI. |
…apshot is served (200) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ReviewOverall this is a well-scoped, well-explained fix. No blocking issues found. What looks good
Minor suggestions (non-blocking)
Style and conventions match CLAUDE.md: imports are used, there are no stray 🤖 Generated with Claude Code |
Closes #9554
Summary
A peer's forwarded command got HTTP 401 "Invalid cluster token" around leader changes because the receiving node checked the token through
server.getHA(). There are two windows where that returns nothing usable:RaftHAPlugin.startService()callsserver.setHA(this)only afterraft.start()returns. The HTTP listener is already up, and Ratis is already running insideraft.start(), so the node can be elected leader before then. Peers forward to it, andHAServerPlugin.effectiveClusterTokenfalls back to the rawarcadedb.ha.clusterTokensetting. That setting is empty on any cluster whose token is derived, so the peer's correct token was refused.ArcadeDBServer.stopInternal()stops HA before the HTTP listener.RaftHAPlugin.stopService()nullsraftHAServer, which was the only source of its token. For the rest of the shutdown, a forward from a peer that still saw this node as leader got the same 401 instead of the retryable "not the leader" refusal.Changes:
HAServerPlugin.effectiveClusterTokenlooks the HA plugin up among the server's registered plugins whengetHA()does not name one yet.RaftHAPluginkeeps the token of the Raft server it stopped. The token never changes for the life of the process, and each server start creates a new plugin instance.SnapshotHttpHandler.authenticatehad its own copy of thegetHA()lookup and the same defect: a follower asking a just-elected leader for a snapshot got 401. It now uses the shared helper.Bullet 3 of the issue ("a 401 turned into a non-retryable client error"): with the cause above removed, the 401 is left non-retryable on purpose. A 401 "Invalid cluster token" now means the nodes really are configured with different tokens, and retrying cannot fix that. Making it retryable would turn a configuration error into a retry storm.
Test plan
Issue9554ClusterTokenRetainedAfterStopTest(unit): the token survivesstopService(), called twice as in a real shutdown. Fails without the fix (expected "issue9554-token" but was null).Issue9554ClusterTokenAcrossHALifecycleIT: on a live 2-node cluster, setssetHA(null)to reproduce the startup window, then:"");Issue7516ClusterTokenHopProofTest,Issue7528LeaderProxyRemovedTest,RaftHAPluginExecutorLeakTest,ClusterTokenProviderTest,Issue6125SnapshotRouteValidationTest,Issue7837ShutdownRequestCredentialTest,Issue7516BasicAuthForwardLoopIT,ClusterAuthSessionTokenIT,Issue7603LeaderForwardHopIT,RaftReplicationWriteAgainstReplicaIT.Coverage
Invariant: a node accepts its peers' cluster token for as long as its HTTP listener is up and it holds an HA plugin, whatever stage that plugin's lifecycle is in.
AbstractServerHttpHandler.isValidClusterToken(every HTTP route, including/api/v1/commandforwards and/api/v1/server)effectiveClusterTokenSnapshotHttpHandler.authenticate(/api/v1/ha/snapshot/*)PostClusterAuthSessionHandlerLeaderCommandForwarder,SupportPeerQuery)RaftReplicatedDatabase.forwardCommandToLeaderViaRaftRaftHAServer.getClusterToken(), andstart()initializes the provider before Ratis starts, so no leader is known before the token isFound with
grep -rn "X-ArcadeDB-Cluster-Token" server/src/main ha-raft/src/main grpcw/src/mainandgrep -rn "effectiveClusterToken\|getClusterToken()". grpcw, bolt and postgresw do not validate cluster tokens.Known gaps: None.
Adversarial pass
No subagent tool was available in this run, so I did the pass myself against the diff. No further gap found. I checked:
Review cycles
6ea9790493- claude review LGTM with 4 non-blocking suggestions. Applied build support #1 (documented the fallback when the plugin has not started yet), Bump gremlin.version from 3.4.10 to 3.5.1 #2 (IT Javadoc onsetHA(null)racing background threads) and Bump slf4j-simple.version from 1.7.31 to 1.7.32 #3 (the snapshot test now asserts 200 instead of "not 401"). Bump mongo-java-driver from 3.12.4 to 3.12.10 #4 agreed with leaving the 401 non-retryable.903f4b5757- claude review: no blocking issues. Only optional suggestions, skipped as listed below.Deferred items
These were skipped as optional:
isAutoDiscoveredregisters a single Raft plugin. Adding the comment would cost a review cycle for no behavior change.getHA()is restored": every test restores it infinally, and the cluster is torn down per class.Final state: clean-approval
🤖 Generated with Claude Code