Skip to content

Rebase and retry the IdealState update in place on a version conflict during tier-relocation rebalance#19069

Open
Jackie-Jiang wants to merge 1 commit into
apache:masterfrom
Jackie-Jiang:rebalance-rebase-on-version-conflict
Open

Rebase and retry the IdealState update in place on a version conflict during tier-relocation rebalance#19069
Jackie-Jiang wants to merge 1 commit into
apache:masterfrom
Jackie-Jiang:rebalance-rebase-on-version-conflict

Conversation

@Jackie-Jiang

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #19054. That PR reduces the cost of the version-checked IdealState update losing the compare-and-set during a tier-relocation rebalance of a strict realtime table (upsert/dedup); this PR reduces the cost of recovering from a lost compare-and-set.

Each batch of segment moves is applied with a version-checked IdealState update. On a continuously-ingesting table, consuming-segment commits bump the IdealState version between the read and the write, so the update loses the compare-and-set. Previously every lost compare-and-set fell back to the top of the convergence loop — another ExternalView-convergence wait (~hundreds of ms) plus a target recompute — so the rebalance could make very little progress while ingestion continued.

Change

When the rebalance moves only tier segments (the base placements of the partitions are unchanged — the same condition #19054 uses to skip the target recompute), a concurrent write that does not touch the segments this batch moves cannot invalidate the batch. So on a ZkBadVersionException:

  1. Re-read the IdealState.
  2. If the concurrent change is disjoint from the segments this batch moves, rebase the batch onto the latest IdealState (reapply the batch's moves, preserving the concurrent changes) and retry the compare-and-set in place — no ExternalView wait, no rebalanceTable.
  3. On overlap, re-read failure, or exhausting a bounded number of attempts (MAX_IDEAL_STATE_UPDATE_REBASE_ATTEMPTS), fall back to the convergence loop as before.

On a successful rebase, the target assignment is refreshed from the adopted IdealState so the currentAssignment.equals(targetAssignment) convergence check stays well-defined when a rebase pulls in concurrently added (e.g. new consuming) or removed (e.g. retention) segments.

Net effect: disjoint version churn is absorbed in place, so a tier relocation makes progress against a steady stream of consuming-segment commits instead of repeatedly restarting.

Notes

@codecov-commenter

codecov-commenter commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 15.09434% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.42%. Comparing base (706b772) to head (931f4af).

Files with missing lines Patch % Lines
...ntroller/helix/core/rebalance/TableRebalancer.java 15.09% 43 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #19069      +/-   ##
============================================
- Coverage     65.43%   65.42%   -0.01%     
  Complexity     1421     1421              
============================================
  Files          3425     3425              
  Lines        216173   216219      +46     
  Branches      34239    34249      +10     
============================================
+ Hits         141449   141458       +9     
- Misses        63340    63376      +36     
- Partials      11384    11385       +1     
Flag Coverage Δ
custom-integration1 100.00% <ø> (ø)
integration 100.00% <ø> (ø)
integration1 100.00% <ø> (ø)
integration2 0.00% <ø> (ø)
java-25 65.42% <15.09%> (-0.01%) ⬇️
temurin 65.42% <15.09%> (-0.01%) ⬇️
unittests 65.42% <15.09%> (-0.01%) ⬇️
unittests1 56.85% <ø> (-0.01%) ⬇️
unittests2 37.81% <15.09%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ier-relocation rebalance

When TableRebalancer moves segments in batches, each batch is applied with a version-checked
IdealState update. On a continuously-ingesting strict realtime table (upsert/dedup),
consuming-segment commits bump the IdealState version between the read and the write, so the
update loses the compare-and-set. Previously every lost compare-and-set fell back to the top
of the convergence loop, paying another ExternalView-convergence wait and target recompute,
so the rebalance could make very little progress while ingestion continued.

When the rebalance moves only tier segments (so the base placements of the partitions are
unchanged), a concurrent write that does not touch the segments this batch moves cannot
invalidate the batch. In that case, on a version conflict, re-read the IdealState, and if the
concurrent change is disjoint from the segments this batch moves, rebase the batch onto the
latest IdealState and retry the compare-and-set in place, without waiting for the
ExternalView to converge again or recomputing the target. The retry is bounded; on overlap,
re-read failure, or exhausting the retries, it falls back to the convergence loop as before.

This builds on the target-recompute skip for tier-relocation rebalances: it reuses the same
"moves only tier segments" condition to decide when a batch is safe to rebase, and refreshes
the target from the adopted IdealState so the convergence check stays well-defined when a
rebase pulls in concurrently added or removed segments.
@Jackie-Jiang
Jackie-Jiang force-pushed the rebalance-rebase-on-version-conflict branch from ddcba5e to 931f4af Compare July 23, 2026 23:35
@Jackie-Jiang Jackie-Jiang added enhancement Improvement to existing functionality segment-rebalance Related to segment rebalancing across servers labels Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement to existing functionality segment-rebalance Related to segment rebalancing across servers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants