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 related tests, then identify how automatic and manual requests are scheduled. I’ll reproduce the redundant scheduling in an existing or focused test if possible, implement coalescing without changing manual future semantics, and run the relevant test suite.
- Assistant
The initial phrase search found nothing, so I’ll inspect the repository modules and search broadly for offload APIs, scheduling flags, and managed-ledger implementations.
- Assistant
rgis unavailable in this environment, so I’ll usefind/grepand narrow the results to managed-ledger source and tests. - Assistant
The likely defect is in
ManagedLedgerImpl’s automatic trigger method. I’ll inspect that implementation, its callers, state fields, and nearby offload tests to understand threading and future behavior before changing it. - Assistant
Current automatic contention retries every 100 ms, creating unbounded scheduled work; manual offload uses the same mutex but immediately returns
OffloadInProgressException. I’ll read all concurrency tests and invocation points to preserve these distinctions and determine whether automatic promises are externally observed. - Assistant
Automatic calls normally pass a shared already-completed sentinel, but a package-visible test also supplies a real future. The requested “explicit/manual offload futures retain behavior” likely refers
asyncOffloadPrefix, while coalesced automatic promises still need sensible completion. I’ll inspect the remaining automatic test and executor serialization model, then design a small synchronized state machine with one running run plus one pending rerun rather than timer retries. - Assistant
I’ll implement per-ledger automatic-run state protected by a dedicated monitor. The first trigger starts one run; triggers during it only mark one pending run and attach their completion promises to that run. Completion atomically promotes the pending run. The existing mutex and immediate manual
OffloadInProgressExceptionpath remain untouched. The mutex retry will call the internal run directly so it cannot accidentally enqueue itself as follow-up. - Assistant
The line-number edit was offset by the newly inserted fields and partially overlapped the old method, leaving a malformed boundary. I’ve detected this in review before compiling. I’ll replace the entire automatic-offload section as one unit, from the public trigger through the end of the scan, to restore the original scan logic plus the new state machine cleanly.
- Assistant
Compilation now succeeds. Before tests, I’ll make one small robustness refinement: production rollover triggers repeatedly pass the same completed sentinel future, so retaining that sentinel once per trigger would itself create avoidable memory/completion work. The pending boolean is sufficient to preserve the follow-up; only real, distinct caller futures need collection. Then I’ll run the focused offload concurrency tests.
- Assistant
The focused concurrency tests pass across their data-provider cases, confirming follow-up processing and unchanged manual fail-fast behavior. I’ll now review the exact diff for accidental changes, run the module’s formatting/static checks if available, and run the broader
OffloadPrefixTestbecause threshold edge cases share this code. - Assistant
The full offload-prefix suite passes and the diff is isolated. I noticed two purely stylistic scan rewrites introduced while repairing the section; I’ll restore those lines to their original form to keep the patch focused. Then I’ll run Checkstyle and the test that directly waits on a real automatic-offload future, validating that coalescing did not alter observable future completion.
- Assistant
Checkstyle and the real-future test both pass. The cosmetic replacement did not apply because the editor was scoped away from the occurrence, so I’ll use the exact current line range, verify only the intended scheduling/state changes remain, and inspect repository status for generated artifacts.
- Assistant
Final review shows only the coalescing state machine and the crucial retry redirection differ from the original. The monitor transition is race-safe: pending requests are captured before promotion, triggers during the promoted run create only the next single pending run, and real automatic futures are completed with their assigned run. Manual offload code and its callback/future behavior are unchanged. I’ll do one final compile/diff check after the cosmetic restoration, then submit if clean.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.