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 start by exploring the repository to understand the codebase and locate relevant files related to managed-ledger offloading. Let's first see what kind of project this is.
- Assistant
This appears to be the Apache Pulsar repository. The issue is about managed-ledger offloading. Let me search for relevant files.
- Assistant
Let me search for "managed ledger offload" or similar patterns to find the main code that handles offloading triggers.
- Assistant
The key file is likely
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java. Let me look at it. - Assistant
Let me look at ManagedLedgerImpl.java to understand the offloading mechanism.
- Assistant
Let me look at the offloading-related methods in ManagedLedgerImpl.java. I need to understand the current offloading mechanism.
- Assistant
Let me look at the key offloading methods more closely, especially
maybeOffloadandoffloadLoop. - Assistant
Now let me read the key methods in detail:
- Assistant
Let me continue reading the maybeOffload method:
- Assistant
Now let me look at the
offloadMutexand how it's used to understand the current behavior: - Assistant
Let me search for where automatic offloading is triggered:
- Assistant
Now let me examine the
offloadPrefixmethod and other places to understand manual vs automatic offload: - Assistant
Let me see the rest of the asyncOffloadPrefix method and the offloadLoop method:
- Assistant
Let me continue reading the offloadLoop method:
- Assistant
Let me check the context around line 1971 where
maybeOffloadInBackgroundis called: - Assistant
Let me look for the
NULL_OFFLOAD_PROMISEand see how automatic offload triggers are used: - Assistant
Let me look at the full definition of NULL_OFFLOAD_PROMISE and how it's used:
- Assistant
Let me examine the ManagedLedgerFactoryImpl to see the other caller of
maybeOffloadInBackground: - Assistant
Let me look at the trimming code to understand the interaction between trimming and offloading:
- Assistant
Now let me look at existing tests to understand how offloading is tested:
- Assistant
Now I understand the issue. Let me examine the exact flow to understand the redundant retry problem:
- Assistant
Now I understand the issue. Let me create a script to reproduce the problem first:
- Assistant
Let me also look at the
asyncOffloadPrefixmethod more carefully to understand how manual offloads work differently: - Assistant
Now I have a clear understanding of the issue. Let me design and implement the solution. The key change is to replace the retry scheduling pattern in
maybeOffloadwith a coalescing mechanism that ensures at most one follow-up run.Let me first look at the existing tests for offloading to understand what I might need to check:
- Assistant
Now I have a clear understanding of the problem. Let me design the solution:
Problem Analysis:
maybeOffloadInBackgroundis called automatically on ledger close and topic load- When an automatic offload is running and another trigger arrives,
maybeOffloadschedules a retry after 100ms - Multiple triggers while an offload is running create multiple retries, each of which may create more retries
- This creates "redundant retry work"
Solution:
- Add a flag to track that a follow-up automatic offload is pending
- In
maybeOffload, when mutex is held, set the flag instead of scheduling a retry - When the automatic offload completes, check the flag and schedule exactly one follow-up
- Manual offloads (via
asyncOffloadPrefix) retain their existing behavior
Let me implement this solution:
- Assistant
Now let me add the
automaticOffloadPendingflag. I'll add it after theoffloadMutexfield: - Assistant
Now let me modify the
maybeOffloadmethod to implement the coalescing logic. First, let me view the exact current code: - Assistant
Now I understand the full picture. Let me implement the coalescing logic. I'll modify the
maybeOffloadmethod to: - Assistant
Now I need to consider the manual offload path as well. When a manual offload completes, if there's a pending automatic offload, we should schedule a follow-up. Let me update the
asyncOffloadPrefixmethod: - Assistant
Now I need to also update the manual offload path. When a manual offload completes, it should also check if there's a pending automatic offload and schedule a follow-up:
- Assistant
I see there's a duplicate line. Let me fix that:
- Assistant
Good. Now let me verify the changes look correct by checking the git diff:
- Assistant
Good. The changes look correct. Now let me run the existing offload tests to make sure they pass:
- Assistant
Let me check the project structure to see how to run tests.
- Assistant
Let me check the project structure to understand the build system.
- Assistant
Let me find the build file for managed-ledger.
- Assistant
No pom.xml for managed-ledger. Let me check the build system.
- Assistant
This is a Gradle project. Let me check how to run tests.
- Assistant
Let me check what build system is used.
- Assistant
Good, it's a Gradle project. Let me try to compile the code first to verify my changes are correct:
- Assistant
Great! The code compiles successfully. Now let me run the offload tests to make sure they pass:
- Assistant
The OffloadPrefixTest passed. Let me also run the other offload-related tests:
- Assistant
Let me also run the other offload-related tests:
- Assistant
Let me also run the general ManagedLedgerTest to make sure nothing is broken:
- Assistant
All tests pass. Let me verify my changes one final time by reviewing the complete diff:
- Assistant
Now let me verify the logic of my solution with a simple analysis:
- Assistant
Let me run the full managed-ledger test suite to make sure nothing is broken:
- Assistant
All tests pass. Let me now create a comprehensive summary of the changes:
- Assistant
Now let me review the final diff once more to ensure everything is correct:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.