[improve][offload] Coalesce automatic offload triggers to reduce retry loops and ledger scans - #25793
Conversation
Automatic offload can be triggered repeatedly while a previous offload is still running. Each trigger may read offload policies, scan the ledger list, fail to acquire the offload mutex, and schedule another 100ms retry. With slow offload or many ledgers, this can create unnecessary scheduler and executor pressure. Coalesce automatic triggers so there is at most one in-flight automatic offload and one pending rerun. If another trigger arrives during an in-flight offload, run one follow-up pass after the current offload completes. This keeps the final offload progression behavior while avoiding repeated retry loops, policy reads, and ledger scans. Keep explicit offload requests unchanged, and rename the automatic sentinel to make it clear that its Position value is not consumed. Add tests for trigger coalescing, coalesced reruns, and automatic state release when offload thresholds are disabled.
|
The following are findings from a local Claude Code review of this PR (human-reviewed before posting). Sharing them here in case they're useful — please treat them as review input, not blockers to be applied verbatim. SummaryThe change does what it claims: automatic offload triggers (from There is one concurrency race worth addressing, plus a few robustness/quality notes. 1. (Bug) Lost-trigger race between
|
lhotari
left a comment
There was a problem hiding this comment.
Great work @void-ptr974. Please check the local Claude Code review comment about the possible bug.
|
Thanks @lhotari. I moved the automatic offload coalescing into I also added a race test for the trigger/completion interleaving, kept integration coverage for the rerun behavior, and removed the old confusing sentinel alias. |
…y loops and ledger scans (apache#25793) (cherry picked from commit 7ecedb8) (cherry picked from commit dd8ce54)
Related issue
Fixes #25859
Motivation
Automatic managed ledger offload can be triggered repeatedly while a previous offload is still running, for example around ledger rollover or topic load.
Before this change, every automatic trigger could independently enter the offload path:
When offload is slow, or when a managed ledger has many ledgers, repeated automatic triggers can build up unnecessary scheduler/executor work. These retries do not improve the final offload
result because only one offload can run at a time.
Modifications
This change coalesces automatic offload triggers in
ManagedLedgerImpl.After this change:
CompletableFuture<Position>behaviorPositionvalue is not consumedgetOffloadPolicies()calls are avoided in the appendable offloader policy lookup pathImpact
The final automatic offload progression is preserved: if new ledgers become eligible while an offload is running, the follow-up pass still picks them up.
The main benefit is reducing unnecessary work under slow offload or large-ledger workloads:
In practice, repeated automatic triggers while one offload is running are reduced from many independent retry loops to one active run plus one pending rerun.
Verifying this change
This change added tests and can be verified as follows:
Local verification:
Does this pull request potentially affect one of the following parts:
This only changes the internal scheduling behavior of automatic managed ledger offload. Public APIs, configs, metrics, explicit/manual offload behavior, and offload metadata semantics are
unchanged.