Skip to content

[Refactor] Decouple HA container and bucket assignment store - #4367

Open
zhoujinsong wants to merge 13 commits into
apache:masterfrom
zhoujinsong:refactor-master-slave-mode-2
Open

zhoujinsong wants to merge 13 commits into
apache:masterfrom
zhoujinsong:refactor-master-slave-mode-2

Conversation

@zhoujinsong

Copy link
Copy Markdown
Contributor

Why are the changes needed?

This is a follow-up PR after #4339.
This PR tried to decouple the HA container and bucket assignment store.

Brief change log

  • As title

How was this patch tested?

  • Add some test cases that check the changes thoroughly including negative and positive cases if possible

  • Add screenshots for manual tests if appropriate

  • Run test locally before making a pull request

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

@github-actions github-actions Bot added the module:ams-server Ams server module label Sep 8, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@amoro.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Oct 15, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions Bot closed this Oct 22, 2026
@zhoujinsong zhoujinsong reopened this Nov 12, 2026

@xxubai xxubai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for the three reproducible issues below. The 35 existing targeted tests pass, but do not cover these scenarios.

ZkBucketAssignStore:
- registerNode() now creates the ephemeral registration under the dedicated
  nodes path (/{ns}/amoro/ams/nodes/{nodeKey}) instead of under
  /bucket-assignments/{nodeKey}. ZooKeeper rejects children of ephemeral
  nodes (NoChildrenForEphemeralsException), so the previous layout broke
  saveAssignments()/updateLastUpdateTime() on a fresh cluster.
- getAliveNodes() discovers membership from the nodes path; persistent
  assignment directories from the old layout are no longer misreported as
  alive after a node crash, so its buckets can be reassigned.
- removeNode() clears both the ephemeral registration and the persistent
  assignments.

DBBucketAssignStore:
- registerNode() tolerates a concurrent heartbeat insert: if the HA
  container's upsertNodeHeartbeat() inserts the row after registration's
  UPDATE returns zero, the duplicate-key INSERT is retried as an UPDATE
  instead of propagating out of startBaseServices() and killing AMS.

Tests:
- Add TestZkBucketAssignStoreWithRealZk: real-ZooKeeper integration tests
  (curator-test TestingServer) covering registration followed by
  assignment on a fresh cluster, path separation, crash/upgrade/fast-restart
  regressions.
- Add TestDBBucketAssignStore#testRegisterNodeToleratesConcurrentHeartbeatInsert
  on Derby for the concurrent duplicate-insert interleaving.

@xxubai xxubai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 8bf7419. The previous three findings are addressed, and all 43 targeted tests pass. I reproduced three remaining lifecycle/compatibility issues below using Derby and real ZooKeeper.

if (IS_MASTER_SLAVE_MODE) {
if (bucketAssignStore != null && haContainer != null) {
try {
bucketAssignStore.removeNode(haContainer.getOptimizingServiceServerInfo());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Retain departed assignments until their buckets are reclaimed. Both stores' removeNode() delete the assignments along with membership. With two nodes holding 50 buckets each, stopping one leaves only the survivor's 50 buckets in the store. doAssign() sees no node changes, treats the single survivor as balanced, and never reassigns the missing 50 buckets. Please defer assignment deletion to the assigner or check total bucket coverage on every pass. Reproduced with Derby across 10 assignment cycles.

} catch (KeeperException.NodeExistsException e) {
// Already registered, update data
try {
zkClient.setData().forPath(nodePath, serverInfoJson.getBytes(StandardCharsets.UTF_8));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Ensure registration belongs to the new session after a fast restart. If the previous process's session has not expired, this fixed path still belongs to that session. setData() does not transfer ephemeral ownership, so the old session's eventual expiry deletes the restarted process's registration while its new connection remains healthy. There is no subsequent registration attempt. Please handle an existing node owned by another session; the new restart test currently deletes it manually before registering, bypassing this case.

return nodes;
}
List<String> nodeKeys = zkClient.getChildren().forPath(assignmentsBasePath);
List<String> nodeKeys = zkClient.getChildren().forPath(nodesBasePath);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve discovery of legacy registrations during upgrades. Before this PR, live nodes register as /nodes/node-000... with their server info in the JSON payload. This loop now expects every child name to be host:port, so it excludes all old-version nodes. During a rolling upgrade, a new leader can reclaim buckets from nodes that are still running. Please read the registration payload for both layouts and add a mixed-version membership test.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants