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 understand the issue:
- This is about Apache Pulsar, specifically about managed-ledger offload triggers.
- The problem is that automatic managed-ledger offload triggers create redundant retry work.
- The solution should 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.
- Explicit/manual offload futures must retain their existing behavior.
Let me explore the repository structure to understand how it's organized.
Assistant
Let me look at the core offload-related files, especially the ones related to managed ledger offload triggers.
Assistant
Let me find the core managed ledger files related to offloading:
Assistant
The key file is
ManagedLedgerImpl.java. Let me read it to understand the offload trigger logic.Assistant
Let me use the correct syntax for the open command.
Assistant
Let me search for offload-related methods in
Assistant
Let me look at the
maybeOffloadmethod and theoffloadMutexmoreAssistant
Let me use the correct approach.
Assistant
Now let me look at the
CallbackMutexclass and understand the current flowAssistant
Let me look at CallbackMutex.
Assistant
Now let me understand all the places where
maybeOffloadInBackgroundis called and how explicit offloads work:Assistant
Let me look at the explicit offload around line 3658 and the
offloadLoopmethodAssistant
Let me see all the call sites of
maybeOffloadInBackgroundAssistant
Let me look at the
NULL_OFFLOAD_PROMISEand also check wheremaybeOffloadInBackgroundis called from in the main fileAssistant
Let me see the context around line 1971 to understand what triggers the automatic offload
Assistant
Let me look at the trigger in `ManagedLedgerFactoryImpl
Assistant
Now I have a clear picture. Let me summarize the problem and plan:
Problem: When an automatic offload is running and new triggers arrive, each trigger schedules its own retry via
scheduledExecutor.schedule(). This creates redundant retry work.Plan:
- Add an
AtomicBooleanfieldoffloadFollowUpScheduledto track if a follow-up is already pending - In
maybeOffload, whenoffloadMutex.tryLock()fails, check if a follow-up is already scheduled. If yes, coalesce (skip). If no, set the flag and schedule one follow-up. - After the offload completes, if
offloadFollowUpScheduledis true, clear it and trigger a new automatic offload. - The explicit/manual offload path (lines ~3642-3662) uses
offloadMutex.tryLock()directly and returnsOffloadInProgressExceptionon failure, so it's unaffected.
Let me look at the field declarations to find the right place to add the new field.
- Add an
Assistant
Now I have a clear understanding. Let me look at where the fields are declared to add the new
Assistant
Let me verify the full
maybeOffloadmethod to make sure I have itAssistant
Now I'll implement the changes. First, let me add the
offloadFollowUpPendingfieldAssistant
Good, field added. Now let me modify the
maybeOffloadmethod to coalesce instead of scheduling multiple retries:Assistant
Now I need to:
- Clear the
offloadFollowUpPendingflag right after acquiring the mutex - Modify the
whenCompleteto schedule a follow-up after offload completes if one was pending
- Clear the
Assistant
I see there's a duplicate line issue. Let me view the current state and fix
Assistant
I need to fix the broken code. Let me replace the problematic section:
Assistant
Now I need to modify the
whenCompletecallback to trigger a follow-up after offloadAssistant
Let me verify the explicit offload path to see if it also needs to check the follow-up flag
Assistant
I notice that the explicit offload path also acquires the mutex but doesn't check for a pending follow-up. If an automatic trigger arrives while an explicit offload is running, the follow-up should still run after the explicit offload completes. Let me fix this
Assistant
I have another duplicate issue. Let me see the full state
Assistant
I need to fix the entire section. Let me replace the corrupted block:
Assistant
Now the code looks correct. Let me verify both sections are correct and then verify the complete changes with
git diffAssistant
Let me see the full diff of all
Assistant
The diff looks correct. Let me now verify the build compiles by checking just the modified file:
Assistant
Let me find the correct module
Assistant
Let me check the directory structure.
Assistant
It's a Gradle project. Let me try to compile with Gradle.
Assistant
Build successful. Now let me find and run the related tests.
Assistant
Tests passed. Let me also run the ManagedLedger tests and the OffloadLedgerDelete tests.
Assistant
Let me also run the other offload-related tests.
Assistant
All managed-ledger tests pass. Let me also run the broker offload test.
Assistant
All tests pass. Let me verify the final state of my changes one more time.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.