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 exploring the repository structure to understand what we're dealing with. This appears to be related to Apache Pulsar's managed-ledger offload mechanism. The issue is about coalescing automatic offload triggers while an automatic offload is running.
Let me first explore the repository structure and find relevant files.
Assistant
Let me look for the managed-ledger module specifically, as that's where the main offload logic likely resides.
Assistant
The key file is likely
ManagedLedgerImpl.javasince the issue is about "automatic managed-ledger offload triggers". Let me look at thatAssistant
Let me try with the correct parameter name.
Assistant
Let me try just
open.Assistant
Let me search for offload-related code in this file.
Assistant
Let me use grep to find offload-related code in this file.
Assistant
Let me look at the key methods more
Assistant
Let me try the correct syntax.
Assistant
Let me look at the
CallbackMutexclass and the fields used for offloadingAssistant
Let me look at the CallbackMutex implementation.
Assistant
Let me see the field declarations around line 230-250.
Assistant
Let me look at where
maybeOffloadInBackgroundis called from.Assistant
Let me look at line 1971 context to understand when automatic offload is triggered.
Assistant
Let me check the
ManagedLedgerFactoryImpl.javaline 499 to see the other call siteAssistant
Let me see the complete
maybeOffloadmethod.Assistant
Let me check the imports and class fields to plan my changes.
Assistant
Now I have a clear understanding of the issue and the solution. Let me look at a bit more context to ensure I understand the complete
Assistant
Now I have a thorough understanding. Let me implement the changes.
The key changes:
-
Add a field:
private final AtomicBoolean offloadFollowUpNeeded = new AtomicBoolean(false); -
In
maybeOffload, change the lock failure handling:- Instead of scheduling a retry directly, use
offloadFollowUpNeeded.compareAndSet(false, true)to coalesce - If we successfully set the flag, schedule a single follow-up
- Complete the promise
- Instead of scheduling a retry directly, use
-
In the `unlockingPromise.whenComplete
-
Assistant
Let me now implement the changes. First, let me add the
offloadFollowUpNeededfield near the other offload-relatedAssistant
Now let me add the new field and then modify the
maybeOffloadmethod. First, the field:Assistant
Let me try using the replace command instead
Assistant
Let me use the
--fileoption for the replace commandAssistant
Let me use goto to navigate to the right location first
Assistant
Now let me use replace again.
Assistant
Good, field added. Now let me modify the
maybeOffloadmethod. Let me go to that sectionAssistant
Now let me modify the
maybeOffloadmethod. First, the lock failure handling blockAssistant
Wait, I need to reconsider my approach. There's a race condition: if the scheduled follow-up runs before the current offload completes, it will find the mutex still locked and silently give up. Let me revise the approach:
- When a trigger arrives and the mutex is locked, just set the flag (don't schedule)
- In the
unlockingPromise.whenCompletecallback, after unlocking, check the flag and schedule a follow-up if needed
Let me revert my earlier change to
maybeOffloadand redo it properlyAssistant
Now let me modify the
unlockingPromise.whenCompletecallback to schedule a follow-up after the current offAssistant
Now I also need to handle the case where a manual offload completes. If automatic triggers arrived during a manual offload, the follow-up flag would be set but never checked. Let me update the manual offload's callback too.
Assistant
Let me verify the changes compile and check imports. Let me also look at the existing tests to make sure I understand the expected
Assistant
Good,
AtomicBooleanis already imported. Let me try to compile the project to check for errors.Assistant
Let me find the correct module name.
Assistant
Let me find the pom.xml files.
Assistant
Let me try looking at the directory
Assistant
It uses Gradle. Let me try to compile with Gradle.
Assistant
Build successful. Now let me run the relevant tests to verify my changes.
Assistant
There's a failing test. Let me look at it to understand what it expects.
Assistant
Let me look at the test.
Assistant
Let me see the rest of the test.
Assistant
I see - the test expects that after a manual offload completes, automatic triggers that arrived during the manual offload should be processed. I need to add the follow-up check to the manual offload's completion callback as well. Let me update
Assistant
Now let me compile and run the tests again.
Assistant
Compilation succeeds. Now let me run the offload tests again.
Assistant
All offload tests pass. Let me also run the full managed-ledger test suite to make sure I didn't break anything.
Assistant
All tests pass. Let me review my changes to make sure they're correct.
Assistant
Let me double-check that all tests still pass by running them again.
Assistant
All tests pass. Let me review my changes one final time to confirm they satisfy all requirements:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.