ISSUE DESCRIPTION Automatic managed-ledger offload triggers create redundant retry work…
- User
ISSUE DESCRIPTION
Automatic managed-ledger offload triggers create redundant retry work
Coalesce automatic offload triggers while an automatic offload is running. There must be at most one active automatic run and at most one follow-up run when additional triggers arrive. A follow-up must still process newly eligible ledgers, and explicit/manual offload futures must retain their existing behavior.
Interface
No new public interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /pulsar, current file: none) bash-$
- Assistant
I’ll first locate managed-ledger offload trigger paths and their tests, then identify how automatic versus explicit requests are represented and scheduled. I’ll reproduce the redundant scheduling behavior with the most focused existing test or a temporary harness, implement coalescing without changing manual future semantics, and run the relevant test suite.
- Assistant
The automatic trigger is in
ManagedLedgerImpl, while broker-level manual offload is likely separate. I’ll inspect the scheduling implementation, related state fields, and managed-ledger tests that exercise automatic offload timing/concurrency. - Assistant
The redundancy is clear: every automatic trigger enqueues its own executor task and, on mutex contention, each independently schedules a 100 ms retry. The same mutex is used by explicit
asyncOffloadPrefix, whose callback currently fails immediately if busy; that behavior must remain unchanged. I’ll inspect allmaybeOffloadInBackgroundcallers and the mutex implementation to choose a race-safe coalescing state model. - Assistant
Automatic calls normally share an already-completed sentinel future, but the method is also package-visible and tests may pass a real future. Coalescing therefore must preserve completion for every automatic caller, likely by attaching each caller to one active/follow-up cycle rather than dropping futures. I’ll inspect factory cadence, test setup utilities/offloader mocks, and project style for atomic work-in-progress state.
- Assistant
I’ll implement a per-ledger automatic-offload coordinator with two promise batches: one active and one pending. The active run remains the sole mutex retry loop; all triggers arriving during it join exactly one pending batch. When active completes, its callers receive that run’s result, then the pending batch performs a fresh ledger scan, ensuring newly rolled/eligible ledgers are included. The manual
asyncOffloadPrefixpath and its immediateOffloadInProgressExceptionbehavior will remain untouched. - Assistant
Because
executoris an ordered per-ledger executor, coordinator state can be confined to it: requests and completion transitions are both posted there. I’ll add pending promise batches, replace recursive public retries with a private retry of the single active run, and keep policy validation at each follow-up start. I’ll also guard completion propagation so one caller cancelling/completing its future does not affect others. - Assistant
I’m now applying the coordinator. The thresholds from the latest coalesced trigger will govern the follow-up (matching the idea that it is a new automatic run), while eligibility itself is always recomputed when that run starts. A single private retry remains associated with the active batch, preventing retry fan-out.
- Assistant
The first range edit collided with shifted line numbers and accidentally removed the closing brace/deferred-trim helper while leaving the old retry block. I caught this in review before compiling. I’ll repair the whole contiguous section by replacing it from the trim helper through mutex acquisition, then inspect the resulting method boundaries.
- Assistant
Python is unavailable in this image, so the scripted replacement did not run and no further damage occurred. I’ll use the repository’s line editor with freshly numbered boundaries to make the same repair safely.
- Assistant
The minimal repair is now unambiguous: close the boolean trim overload, restore
scheduleDeferredTrimming, and remove the orphaned original retry block. - Assistant
The repaired code is structurally clean. Before tests, I’ll compile the managed-ledger module and run formatting/checkstyle checks implicitly included by its Maven lifecycle. This will also reveal whether posting completion back to the selected executor and the new generic fields conform to project APIs and style.
- Assistant
The root reactor does not expose the directory name as a selectable module (this repository likely uses a profile or a different artifact ID), so that command did not compile anything. I’ll inspect the root/module POM metadata and invoke Maven from the module or select its actual artifact ID.
- Assistant
This checkout uses Gradle rather than Maven. I’ll inspect available wrapper/tasks and then compile and run the focused managed-ledger tests through Gradle.
- Assistant
I’ll run
:managed-ledger:compileJavafirst for fast feedback, then the focused offload test classes. - Assistant
Compilation succeeds. I’ll run all four managed-ledger offload-focused test classes, including manual prefix tests (to validate explicit callback/future behavior) and the existing automatic offload test in
OffloadLedgerDeleteTest. - Assistant
All focused offload tests pass, including manual offload coverage. I’ll now inspect the exact diff for accidental unrelated edits and run the repository’s formatter/check task for this module. I’ll also consider shutdown and trigger-race edge cases visible in the final code before submission.
- Assistant
The diff contains only the intended source changes. One style improvement is to separate the new coordinator fields from the existing public sentinel with a blank line; Spotless will determine exact formatting. I’ll run Spotless and Checkstyle now.
- Assistant
The concurrency edge cases are sound under the ledger’s ordered executor:
- triggers before completion join one pending batch;
- a trigger racing completion either joins that batch or starts the next run after state clears, with no lost trigger;
- triggers during a follow-up can create only one subsequent pending batch;
- manual offload never enters this coordinator and still contends directly on
offloadMutex; - each non-sentinel automatic future is completed with the result of the run that processes its batch.
I’ll perform a final status/diff check and rerun the focused test task once more after style validation (it should be up-to-date but confirms the final tree).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.