Skip to content

[server] Expose rebalance start and completion timestamps - #3985

Open
morazow wants to merge 1 commit into
apache:mainfrom
morazow:rebalance-progress
Open

morazow wants to merge 1 commit into
apache:mainfrom
morazow:rebalance-progress

Conversation

@morazow

@morazow morazow commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: part of #3965

Admin#listRebalanceProgress does not say when a rebalance started or finished, so
"when did the cluster last rebalance, and how long did it take?" can only be answered from
server logs.

This PR adds the start and completion timestamps. Following review, it is the first of two
steps: the bounded rebalance history (listing finished rebalances) moves to a follow-up PR
that builds on this one.

Brief change log

Server

  • RebalanceTask carries startedAtMs and completedAtMs. Its JSON format in ZooKeeper
    goes to version 3. A task written by an older coordinator reads back with both set to
    -1 (unset). Older coordinators still read version 3, because the reader looks fields up
    by name and ignores unknown ones.
  • RebalanceManager sets the start time when it generates the task and the completion time
    when it persists the final status. A cancel keeps the start time. Recovery after a
    coordinator failover restores both.

RPC and client

  • ListRebalanceProgressResponse gets two optional fields, started_at_ms and
    completed_at_ms. There is no API version bump: an older server omits them and the
    client maps an absent field to -1. An older client ignores them.
  • RebalanceProgress gains startedAtMs() and completedAtMs() (-1 if unknown, or for
    completedAtMs() while still running). RebalanceProgressJsonSerializer writes them
    when set.
  • RebalanceProgress#formatAsPercentage now uses Locale.ROOT, so the output no longer
    depends on the machine locale (100%, not 100 %). Without it,
    RebalanceProgressJsonSerializerTest fails on some locales.
  • Rust client: RebalanceProgress exposes started_at_ms and completed_at_ms.

Flink

  • sys.list_rebalance gets two new trailing columns, started_at and completed_at
    (TIMESTAMP_LTZ(3)), NULL when unset.

Tests

  • RebalanceTaskJsonSerdeTest: version 3 round-trip; a version 1 task reads back with
    -1 timestamps.
  • RebalanceManagerTest: start time on task generation, completion time on the final
    status, start time kept across a cancel, both restored on recovery.
  • RebalanceProgressJsonSerializerTest: timestamps written when set, omitted when unset.
  • RebalanceITCase: timestamps on a completed rebalance against a live cluster.
  • FlinkProcedureITCase: the new sys.list_rebalance columns, with
    completed_at >= started_at.
  • Rust: RebalanceProgress::from_pb keeps the timestamps.

API and Format

  • Public API: two new getters and a new constructor overload on RebalanceProgress. The
    existing constructor is unchanged.
  • RPC: two new optional fields on ListRebalanceProgressResponse, wire compatible in both
    directions.
  • Storage: the rebalance task znode format goes from version 2 to version 3 (two added
    fields). Both directions stay readable.
  • sys.list_rebalance output gains two trailing columns.

Documentation

website/docs/engine-flink/procedures.md (new columns) and
website/docs/maintenance/operations/rebalance.md (duration example).


🤖 Generated with Claude Code

@morazow
morazow force-pushed the rebalance-progress branch from 5b2283c to 64191c5 Compare August 18, 2026 13:49
@morazow morazow changed the title [server] Retain bounded rebalance history and add listRebalances API [server] Add listRebalances API and expose rebalance timestamps Aug 18, 2026
@morazow
morazow force-pushed the rebalance-progress branch 5 times, most recently from 8569c10 to 014a5ac Compare August 19, 2026 08:44
@morazow

morazow commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Scope note for reviewers: per-bucket detail for historical rebalances

This PR keeps listRebalances() deliberately summary-only (id, status, timestamps). The per-bucket plan of a retained historical rebalance is already persisted, each history znode stores the full RebalanceTask, plan included.

But listRebalanceProgress(id) still throws NoRebalanceInProgressException for non-current ids, so that plan is not yet reachable through the API.

It is easier to enable this API: listRebalanceProgress(id) fall back to the ZooKeeper history when the id is not current, and build the RebalanceProgress from the stored plan. No proto or serde change is needed; the existing response message already carries per-bucket plans.

Keeping it out of this PR keeps the review surface small and leaves one design point open for discussion:

  • History stores plans plus the overall final status, not per-bucket outcomes (those live only in coordinator memory). A historical RebalanceProgress would stamp every bucket with the overall status — exact for COMPLETED, approximate for FAILED/CANCELED. If per-bucket outcomes matter, the follow-up would instead need a serde bump to store RebalanceResultForBucket per bucket. Opinions welcome.

The follow-up also changes one contract: NoRebalanceInProgressException would no longer be thrown for ids still in Zookeeper, which I read as the intent of #3965.

@morazow
morazow marked this pull request as ready for review August 19, 2026 09:30
@morazow
morazow force-pushed the rebalance-progress branch from 014a5ac to 8757b6a Compare August 19, 2026 22:02

@affo affo 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.

Thanks, this is a well-structured change — the bottom-up layering is clean, the failover restore paths and the final-status-before-history ordering are handled carefully, and the test coverage matches the claims in the description. I went through it layer by layer and found no blocking issues.

One design suggestion (splitting the SQL procedure instead of overloading it) and a handful of smaller points inline. The procedure split is the only one I'd push on before merge, since it also removes the two-RPC staleness window flagged in the description.

Comment thread website/docs/engine-flink/procedures.md Resolved
@morazow

morazow commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

addressed: procedure split applied (sys.list_rebalances added, staleness window gone) and all inline comments addressed in the linked commit

2901d9a

@morazow
morazow requested a review from affo August 25, 2026 10:31

@affo affo 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.

Thanks for addressing! Now looks good to me!

@morazow
morazow force-pushed the rebalance-progress branch 2 times, most recently from 3bb4ad6 to 0a14c88 Compare September 14, 2026 11:26
@morazow
morazow force-pushed the rebalance-progress branch 9 times, most recently from c453793 to 1403167 Compare November 6, 2026 21:52
Comment thread fluss-rpc/src/main/proto/FlussApi.proto Outdated
}

message ListRebalancesResponse {
repeated PbRebalanceInfo rebalance_infos = 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have a few related questions about the API and history storage design:

  1. Could we extend the existing RPC? For example, add an optional include_history field to ListRebalanceProgressRequest and a repeated PbRebalanceInfo field to its response, while retaining the existing fields and the current single-rebalance behavior when the flag is absent. A separate Admin method and SQL procedure could still use the same RPC underneath. This seems worth considering before introducing another RPC. We would also need to define the interaction with rebalance_id and handle older servers explicitly, so an unsupported history request cannot silently return an incomplete result.

  2. What should PbRebalanceInfo represent? Should it be a summary, or also contain table/bucket details through repeated PbRebalanceProgressForTable (which includes the plan)? I would avoid returning every historical plan by default. If this is intended to summarize outcomes, could we include an optional, concise error_message or failure_reason? A status such as FAILED alone does not explain what went wrong. The reason would need to be captured and persisted when the failure occurs to remain useful after coordinator failover. Full plan details could remain available through the by-ID query, depending on the retention decision below.

  3. Can we align the history storage with [server] Store rebalance tasks in remote storage #5133? That PR moves rebalance tasks into remote storage to address large serialized plans exceeding ZooKeeper's znode size limit. Here, each /cluster/rebalance_history/<rebalanceId> still stores a complete RebalanceTask. Keeping only 10 entries bounds the count, but does not bound an individual entry's size; even the summary listing currently reads and decodes those complete tasks. Do we need to retain the full plan for historical rebalances, or would summary metadata and diagnostic information be sufficient? If historical plan lookup is required, could history retain metadata plus a remote reference, aligned with [server] Store rebalance tasks in remote storage #5133, with cleanup preserving files referenced by retained history? If we choose summary-only retention instead, we should explicitly adjust the historical detail-query contract.

  4. Could we name the new SQL procedure sys.list_all_rebalances()? Its multi-row summary schema and use case differ substantially from sys.list_rebalance([id]), which returns one rebalance's detailed progress and plan. The more explicit name would make that distinction clearer than the singular/plural difference alone. The documentation should clarify that "all" means the current rebalance plus retained history, rather than an unbounded audit history.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @wuchong, I am going to follow-up on your suggestions and findings and address them soon🤞

@wuchong

wuchong commented Nov 17, 2026

Copy link
Copy Markdown
Member

Btw, is it really necessary to display the results of the last 10 rebalances? Based on our operational experience, showing only the most recent result should be sufficient. What do you think @swuferhong ?

@swuferhong

Copy link
Copy Markdown
Contributor

Btw, is it really necessary to display the results of the last 10 rebalances? Based on our operational experience, showing only the most recent result should be sufficient. What do you think @swuferhong ?

I haven’t encountered this requirement either. I’d recommend using the existing List Rebalance Process API to implement this rather than introducing a new API.

@morazow

morazow commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Hello @wuchong, @swuferhong

Thanks for your detailed and on point reviews, your suggestions made the design simpler. I pushed two follow-up commits.

Single RPC

I removed ListRebalances and added include_history to ListRebalanceProgressRequest. The response carries the list in a new rebalance_infos field. LIST_REBALANCE_PROGRESS goes to version 1.

include_history cannot be combined with rebalance_id. The coordinator rejects that with InvalidRequestException.

PbRebalanceInfo content

It is a summary of one rebalance: id, status, start time, completion time. It does not carry the plan or per-bucket progress. Per-bucket detail stays in ListRebalanceProgress without include_history, and only for the most recent rebalance.

I added the optional failure_reason as you suggested.

History storage

History entries now store only the summary (id, status, timestamps, failure reason) under /cluster/rebalance_history/<rebalanceId>, not the full RebalanceTask. The entry size no longer grows with the plan, so this does not conflict with #5133 moving the plan to remote storage. This PR does not depend on #5133 yet.

Naming

The procedure is renamed to sys.list_all_rebalances(). The docs now state that "all" means the current rebalance plus the retained history.

Please have another look 🙏

@morazow
morazow requested a review from wuchong November 19, 2026 14:48
@swuferhong

Copy link
Copy Markdown
Contributor

Hi, @morazow I still think the current implementation is too complex. Could we split it into smaller steps—first adding a timestamp to the plan, then adding rebalance history support in a follow-up PR?

@morazow

morazow commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thank @swuferhong for suggestions, changing 👍 I'll ping you once done

@morazow
morazow force-pushed the rebalance-progress branch from f2872bf to 1c6cf8b Compare December 1, 2026 13:02
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 %").
@morazow
morazow force-pushed the rebalance-progress branch from 1c6cf8b to 1d126a0 Compare December 1, 2026 13:30
@morazow morazow changed the title [server] Add listRebalances API and expose rebalance timestamps [server] Expose rebalance start and completion timestamps Dec 1, 2026
@morazow

morazow commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Hi @swuferhong, thanks for the suggestion. I split the PR as you proposed.

This PR (#3985) now only adds the start and completion timestamps. It covers what @wuchong mentioned: listRebalanceProgress(null) returns the most recent rebalance, now including when it started and finished.

The rebalance history (listAllRebalances, the bounded ZooKeeper history and sys.list_all_rebalances) moved to a follow-up draft, #5446. GitHub can't stack it on this PR's branch from my fork, so #5446 also contains this PR's commit for now. I'll rebase it once this one is merged.

Please have another look 🙏

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.

4 participants