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
Let me start by understanding the repository structure and the issue. The issue is about "Automatic managed-ledger offload triggers create redundant retry work". I need to 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.
Let me first explore the repository structure to understand the codebase.
Assistant
This is a Pulsar repository. The issue is about managed-ledger offload. Let me explore the managed-ledger module and find relevant files
Assistant
Let me look at the ManagedLedgerImpl.java file which likely contains the offload logic:
Assistant
That's a large file. Let me search for "offload" related methods and logic within it.
Assistant
Let me look at the key methods in
Assistant
Let me try again with the full path.
Assistant
Let me try using the bash_terminal with the open command.
Assistant
Let me see the rest of
maybeOffload:Assistant
Let me search for all callers of `maybeOffloadInBackground
Assistant
Let me look at the context around line 1971
Assistant
Now let me look at the ManagedLedgerFactoryImpl call at line 499:
Assistant
Let me look at the NULL_OFFLOAD_PROMISE definition and the field declarations regarding offload:
Assistant
Let me look at the class fields:
Assistant
Let me look at the CallbackMutex class
Assistant
Let me look at CallbackMutex:
Assistant
Let me open the file around the relevant methods:
Assistant
Now I have a thorough understanding of the issue. Let me look at the specific section I need to modify again:
Assistant
Now I have a clear understanding. Let me implement the fix.
The plan:
- Add a
private volatile boolean offloadFollowupScheduled = false;field to track if a follow-up is already scheduled - In
maybeOffload, whenoffloadMutex.tryLock()fails, check this flag: if already scheduled, return without scheduling another; if not, set it and schedule one follow-up - When the lock is acquired successfully, reset the flag
Let's first add the field
- Add a
Assistant
Let me try again with the bash terminal command format.
Assistant
Good, the field is added. Now let me modify the
maybeOffloadmethod. Let me first update the lock failure path (lines 2836-2840):Assistant
Now let me modify the lock acquisition failure handling to coalesce follow-ups
Assistant
Let me use the heredoc syntax for multi-line edits
Assistant
I realized there's a subtle bug with my approach. When the follow-up fires and the mutex is still locked, the flag is still true and the follow-up is lost. I need to use a different approach: set the flag when triggers arrive, and check it when the offload completes to schedule a follow-up then.
Let me fix this properly
Assistant
Now I need to update the
unlockingPromise.whenCompleteto schedule a followAssistant
Now let me verify the changes are correct by looking at the final state of the method
Assistant
Let me also check the manual offload path to see if it needs the follow-up check too. Let me look at `asyncOffloadPrefix
Assistant
I need to update the manual offload path too, to ensure automatic triggers that arrive during a manual offload are also coalesced properly. Let me update the
asyncOffloadPrefixmethodAssistant
Let me verify the changes look correct by viewing the diff
Assistant
The diff looks correct. Let me now try to compile the managed-ledger module to ensure there are no errors
Assistant
Compilation succeeded. Now let me run the existing offload-related tests to make sure nothing is broken
Assistant
All offload tests passed. Let me also run the full managed-ledger test suite to check for regressions
Assistant
All tests pass. Let me also check the
OffloadLedgerDeleteTestto make sure the test that directly callsmaybeOffloadInBackgroundis compatibleAssistant
Let me check the test context around line 249
Assistant
The test uses a custom CompletableFuture with
maybeOffloadInBackground. Since there's no contention in the test, the lock will be acquired and the custom future will be completed as before. The test passed in our earlier run.Let me do a final review of the complete changes
Assistant
The diff looks correct. Let me run all the tests one final time to make sure everything still
Assistant
Let me also check if
ShadowManagedLedgerImploverrides any of the methods I modifiedAssistant
Let me check the interface definition of `maybeOffloadInBackground
Assistant
maybeOffloadInBackgroundis not in theManagedLedgerinterface. Let me checkAsyncCallbacks:Actually, looking at the code,
maybeOffloadInBackgroundis defined directly inManagedLedgerImpl. Let me check theManagedLedgerinterface:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →