Skip to content

[server] Add bounded rebalance history and listAllRebalances - #5446

Open
morazow wants to merge 3 commits into
apache:mainfrom
morazow:rebalance-history
Open

morazow wants to merge 3 commits into
apache:mainfrom
morazow:rebalance-history

Conversation

@morazow

@morazow morazow commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: close #3965

Depends on #3985. The first commit on this branch is #3985 (rebalance start and
completion timestamps). Please review only the last two commits:

[rust]   Add list_all_rebalances
[server] Add bounded rebalance history and listAllRebalances
------------------------------------------------------------ #3985 below
[server] Expose rebalance start and completion timestamps

listRebalanceProgress covers only the most recent rebalance. Once the next rebalance
starts, the previous one is gone, so "what happened in the last few rebalances?" can only
be answered from server logs. This PR keeps a bounded summary of finished rebalances and
lists it.

This is the history half of the earlier version of #3985, split out after review. It
keeps the design agreed in that review: a single ListRebalanceProgress RPC with
include_history, and history entries that store only a summary.

Brief change log

History storage

  • When a rebalance reaches a final status, the coordinator writes a summary (id, status,
    start and completion time, failure reason) to /cluster/rebalance_history/<rebalanceId>.
    The entry does not contain the plan, so its size does not grow with the rebalance.
  • The history keeps the 10 most recent entries. The coordinator trims older entries in the
    order ZooKeeper created them, so coordinator clock differences after a failover cannot
    reorder or wrongly trim entries.
  • A rebalance that moved nothing stays out of the history, so repeated calls on a balanced
    cluster cannot push real rebalances out.
  • On startup, a final task written by a coordinator from before the history existed is
    added to the history. Otherwise the next rebalance would overwrite it.
  • An entry that fails to decode, for example one written by a newer coordinator, is skipped
    when listing. The trim does not read entries, so it keeps such an entry until it falls out
    of the 10 most recent.

Listing API

  • ListRebalanceProgressRequest gets include_history. With it, the response carries a
    repeated PbRebalanceInfo: the current rebalance first, then the history, newest first.
    include_history cannot be combined with rebalance_id; the coordinator rejects that
    with InvalidRequestException.
  • LIST_REBALANCE_PROGRESS goes to version 1. An older server ignores include_history
    and answers with the current rebalance only, which the client could not tell apart from
    an empty history. So the client fails with UnsupportedVersionException when the server
    only supports version 0.
  • The coordinator takes a snapshot of the current rebalance on the event thread, where it
    changes, and reads the history from ZooKeeper on the IO executor, so the event loop never
    blocks on ZooKeeper.
  • New public RebalanceInfo (@PublicEvolving) and Admin#listAllRebalances().
  • New sys.list_all_rebalances procedure: rebalance_id, rebalance_status,
    started_at, completed_at, failure_reason.
  • Rust client: FlussAdmin::list_all_rebalances.

Related changes

  • RebalanceTask stores each bucket's own final status when it differs from the overall
    status. Before, a coordinator that recovered a finished CANCELED or FAILED rebalance
    reported every bucket with the overall status, including buckets that had completed.
  • A FAILED rebalance records why its first failed bucket was given up on (failure_reason).
  • Writes to the rebalance znodes check the coordinator epoch, so a coordinator that lost
    leadership cannot overwrite the current task or the history.
  • FutureUtils#completeFromCallable also completes the future when the callable throws an
    Error. Without this, an Error thrown on the IO executor would leave the client waiting
    until the RPC times out.
  • listRebalanceProgress(id) now throws NoRebalanceInProgressException when the id is
    not the most recent rebalance, including when no rebalance has run. Before, an id with no
    rebalance present returned an empty result. The message points to listAllRebalances().
  • The client rejects an unknown rebalance status code with a clear error. In the summary
    list, it skips such entries and logs a warning.

Tests

  • ZooKeeperClientTest: retention trim, creation-order listing under coordinator clock
    skew, idempotent re-register, corrupt entries skipped and aged out, sibling znode
    isolation, epoch-fenced writes.
  • RebalanceManagerTest: history written on completion and cancel (not on a cancellation
    request or a no-op rebalance), current-first then newest-first listing, stale snapshot
    vs. history, startup backfill, per-bucket status and failure reason on recovery,
    older and unknown id errors, ZooKeeper read failure.
  • RebalanceTaskJsonSerdeTest, RebalanceInfoJsonSerdeTest: per-bucket status, failure
    reason, unknown status codes (a bucket falls back to the task status; a history entry
    fails to decode).
  • CoordinatorRebalanceTest: the response callback completes when the rebalance manager is
    closed.
  • ServerConnectionTest: include_history against a version 0 server.
  • ClientRpcMessageUtilsTest: summary conversion, absent fields, unknown status.
  • FutureUtilsTest: completeFromCallable with an Error.
  • RebalanceITCase: listAllRebalances on a live cluster, and include_history with
    rebalance_id rejected.
  • FlussAuthorizationITCase#testListAllRebalances: DESCRIBE on the cluster resource.
  • FlinkProcedureITCase: sys.list_all_rebalances.
  • Rust: RebalanceInfo::from_pb, version check for include_history.

API and Format

  • Public API: new RebalanceInfo class and Admin#listAllRebalances().
    listRebalanceProgress(id) now throws for an id when no rebalance has run (see above).
  • RPC: LIST_REBALANCE_PROGRESS version 1 with include_history and rebalance_infos.
    Version 0 requests behave as before.
  • Storage: new znodes under /cluster/rebalance_history. The rebalance task znode gains
    optional bucket_status and failure_reason fields within format version 3; older
    coordinators ignore them.

Documentation

website/docs/engine-flink/procedures.md (list_all_rebalances, updated list_rebalance)
and website/docs/maintenance/operations/rebalance.md.


🤖 Generated with Claude Code

Record when a rebalance started and when it reached a final status, and
return both from listRebalanceProgress.

- RebalanceTask carries startedAtMs/completedAtMs (JSON serde v3). A task
  written by an older coordinator reads back as -1 (unset).
- RebalanceManager sets the start time when it generates the task and the
  completion time when it persists the final status. The cancellation
  task keeps the start time. Recovery restores both.
- ListRebalanceProgressResponse gets optional started_at_ms and
  completed_at_ms fields. No API version bump: an older server omits them
  and the client maps that to -1.
- RebalanceProgress gains startedAtMs()/completedAtMs(), and
  RebalanceProgressJsonSerializer writes them when set.
- sys.list_rebalance gets started_at/completed_at TIMESTAMP_LTZ(3) columns.
- The Rust client exposes both on RebalanceProgress.
- RebalanceProgress#formatAsPercentage uses Locale.ROOT, so the output
  does not depend on the machine locale ("100%", not "100 %").
Keep a summary of the last 10 finished rebalances in ZooKeeper and list
them, together with the current rebalance, through
Admin#listAllRebalances. Builds on the rebalance start and completion
timestamps.

- A finished rebalance is added to /cluster/rebalance_history/<id> as a
  summary (id, status, timestamps, failure reason), without the plan.
  The oldest entries beyond 10 are trimmed, ordered by ZooKeeper creation
  order. A no-op rebalance stays out of the history. On startup, a final
  task written before the history existed is added to it.
- ListRebalanceProgressRequest gets include_history, and the response a
  repeated PbRebalanceInfo. LIST_REBALANCE_PROGRESS goes to version 1, and
  the client rejects include_history against a version 0 server.
  include_history cannot be combined with rebalance_id.
- The coordinator snapshots the current rebalance on the event thread and
  reads the history on the IO executor.
- RebalanceInfo (public) is the summary type. A FAILED rebalance carries
  the reason its first bucket was given up on.
- RebalanceTask keeps each bucket's own final status, so a recovered
  canceled or failed rebalance no longer reports every bucket with the
  overall status.
- Rebalance znode writes check the coordinator epoch.
- New sys.list_all_rebalances procedure.
Mirror Admin#listAllRebalances in the Rust client. RebalanceInfo is the
summary type, and ListRebalanceProgress v1 sends include_history. The
request fails with UnsupportedVersion against a server that only
supports version 0.
@morazow
morazow marked this pull request as ready for review December 1, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add completion timestamp and historical listing to RebalanceProgress

1 participant