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 distinguish automatic from explicit/manual calls. Then I’ll inspect existing concurrency tests, reproduce the redundant scheduling behavior if practical, implement coalescing without changing the public API, and run the focused test suite.
- Assistant
rgis unavailable, so I’ll usefind/grepto identify the implementation and tests. - Assistant
The likely logic is in
ManagedLedgerImpl. I’ll inspect the automatic offload method, its callers, state fields, and nearby explicit offload implementation to preserve manual future semantics. - Assistant
Current contention behavior schedules an independent 100 ms retry for every trigger, which explains the redundant work. I’ll inspect the mutex type, sentinel promise, trigger call sites, and tests around automatic/manual interactions before choosing state synchronization.
- Assistant
I need the complete state declarations and manual lock branch. This will show whether automatic coalescing should be independent of the shared offload mutex (it should, so manual requests still receive their existing retry/completion behavior).
- Assistant
The internal automatic callers are identifiable by the shared
NULL_OFFLOAD_PROMISE; callers supplying a real future are distinct and must retain the existing retry/completion path. I’ll add a private atomic three-state coordinator (idle,running,follow-up requested) only for sentinel-triggered runs. Each automatic run will use its own future, and completion will launch at most one fresh run so it re-evaluates policies and newly eligible ledgers. - Assistant
I’ll implement the coordinator adjacent to the existing mutex and refactor policy-based scheduling into a boolean helper. The helper keeps real-future behavior unchanged when offload is disabled (it still returns without completing), while the internal automatic future is explicitly completed so coordinator state cannot get stuck if policies disappear between triggers.
- Assistant
Python is not installed. I’ll apply the same targeted changes using the repository editor commands instead.
- Assistant
I’ll insert the atomic state fields, then replace the scheduling method with the coordinated automatic path.
- Assistant
Now I’ll replace lines 2812–2825 with the automatic coordinator and retain the existing
maybeOffloadoperation below it. - Assistant
The retry callback now carries the per-run internal future, so it bypasses trigger coalescing and remains the same single active run while waiting for the shared mutex. Real caller futures also continue their old path. I’ll compile and run the focused offload tests to catch formatting, race-path, or behavioral regressions.
- Assistant
The root reactor does not expose the directory name as a selected module. I’ll inspect the root and module POM artifact IDs, then run Maven from the module directly or with the correct reactor selector.
- Assistant
This checkout uses Gradle rather than Maven. I’ll identify the managed-ledger Gradle project name and available test tasks.
- Assistant
I’ll use
:managed-ledger:compileJavaand filtered Gradle tests. - Assistant
Compilation and the two broad offload test classes pass. I’ll now run style/static checks available for the module and inspect the final diff. I’ll also consider executor rejection and state transitions; the atomic CAS design preserves the invariant under completion/trigger races, and a follow-up recomputes thresholds rather than reusing the prior run’s snapshot.
- Assistant
The style check passes and only the intended production file is modified. I’ll perform a final diff review for accidental API changes or unrelated edits, then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.