Skip to content

feat(zero): allow --rebalance_interval=0 to disable automatic tablet … - #9848

Merged
matthewmcneely merged 1 commit into
mainfrom
shiva/rebalance-off
Oct 7, 2026
Merged

matthewmcneely merged 1 commit into
mainfrom
shiva/rebalance-off

Conversation

@shiva-istari

@shiva-istari shiva-istari commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

…rebalancing

Zero's automatic rebalancer could not be turned off: --rebalance_interval required a positive value, so operators who need a stable tablet layout (e.g. one chosen with the bulk loader's --tablet_placement, #9842) had to resort to absurdly large intervals like 99999h. This makes the intent expressible directly:

dgraph zero --rebalance_interval=0

What this does

  • 0 disables automatic tablet rebalancing. The rebalance loop logs Automatic tablet rebalancing is disabled (rebalance_interval=0s). once at startup and exits; chooseTablet is never invoked for the life of the process. No ticker is created, no background scanning happens.
  • Negative values remain a startup error, now with a message that documents the 0 semantics: Rebalance interval must be zero (to disable automatic tablet rebalancing) or positive.
  • Positive values are unchanged, including the 8-minute default — existing clusters see no behavior difference.
  • rebalanceTablets now takes the interval as a parameter (previously read the package-global options), which also makes the disabled path unit-testable. The guard returns before time.Tick, which panics on non-positive durations.

What still works with rebalancing disabled

  • /moveTablet is fully functional. Manual moves call movePredicate directly with an explicit source and destination and never consult the rebalancer, so operators can still move any tablet to any group deliberately — with all the usual machinery (one-at-a-time serialization, commit blocking during the move, size-aware timeout). Only Zero-initiated moves stop.
  • Initial tablet assignment is unaffected. A predicate written for the first time still gets its tablet assigned to a group as today.
  • The move-failure backoff state is only consulted by the automatic path (and only written when a move runs), so it stays empty and inert.

What this does NOT do

  • It does not pin tablets: nothing prevents a manual /moveTablet from changing the layout, and nothing records an intended placement. It is a global on/off switch, not per-predicate control.
  • It is startup configuration, not cluster state: the flag must be set on every Zero in the ensemble (any Zero can become leader after a failover), and a Zero restarted without it reverts to the 8-minute default.
  • With rebalancing off, group size balancing is entirely the operator's responsibility.

Testing

  • TestRebalanceTabletsDisabled: the loop returns immediately for 0 and negative intervals instead of ticking (done-channel with timeout); passes with -race. The enabled path is the existing infinite ticker loop, exercised by every integration test that boots a Zero.
  • Manual smoke: a Zero started with --rebalance_interval=0 boots healthy and logs the disabled message; --rebalance_interval=-5m fails startup with the new error; default start unchanged.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • New Features
    • Automatic tablet rebalancing can now be disabled by setting its interval to zero.
  • Bug Fixes
    • Zero intervals are accepted, while negative intervals remain invalid. Positive intervals continue to enable automatic rebalancing.
  • Tests
    • Added coverage to verify that rebalancing exits promptly when given a zero or negative interval.

…rebalancing

A zero interval now disables the rebalancer entirely instead of failing
startup; negative values remain a startup error. The loop returns before
creating the ticker (time.Tick panics on non-positive durations) and logs
that rebalancing is disabled. Manual /moveTablet is unaffected.
@shiva-istari
shiva-istari requested a review from a team as a code owner October 7, 2026 09:28
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8e3cec29-439e-4fab-be87-23eb571dd5bf
📥 Commits

Reviewing files that changed from the base of the PR and between fe01f6c and b70215f.

📒 Files selected for processing (4)
  • dgraph/cmd/zero/run.go
  • dgraph/cmd/zero/tablet.go
  • dgraph/cmd/zero/tablet_test.go
  • dgraph/cmd/zero/zero.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The rebalance interval can now be zero to disable automatic tablet rebalancing. The server passes the configured interval to the rebalancing routine, which returns without starting a ticker for non-positive intervals.

Changes

Tablet rebalancing

Layer / File(s) Summary
Accept a zero rebalance interval
dgraph/cmd/zero/run.go
The flag description states that zero disables automatic tablet rebalancing. run rejects negative intervals and accepts zero.
Apply the interval to tablet rebalancing
dgraph/cmd/zero/tablet.go, dgraph/cmd/zero/zero.go, dgraph/cmd/zero/tablet_test.go
Server.Init passes the configured interval to rebalanceTablets. The routine returns for non-positive intervals. A test checks that zero and negative intervals return within five seconds.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: matthewmcneely

Merge Risk: ⚪ Minimal · up to b7021

Setting the interval to zero disables automatic tablet rebalancing without blocking initial assignment or separate manual moves. No material merge-blocking risk is established; the change is ready for normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: setting --rebalance_interval=0 disables automatic tablet rebalancing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@matthewmcneely
matthewmcneely merged commit 06f4759 into main Oct 7, 2026
19 checks passed
@matthewmcneely
matthewmcneely deleted the shiva/rebalance-off branch October 7, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants