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 explore the repository structure to understand the codebase and find the relevant files for managed-ledger offloading.
Assistant
Let me run one command at a time.
Assistant
Let me find the managed ledger offload related files.
Assistant
Let me look at the ManagedLedgerImpl.java file, which is the main file for managed ledger operations, focusing on offload-related methods.
Assistant
Let me look at the offload-related methods in detail.
Assistant
Let me understand where
maybeOffloadInBackgroundis called and the offloadLoop method.Assistant
Let me look at where maybeOffloadInBackground is called (line 1971) and the manual offload path (lines 3640-3760).
Assistant
I need to run one command at a time.
Assistant
Let me search for all callers of
maybeOffloadInBackground.Assistant
Let me check the test usage and the ManagedLedgerFactoryImpl usage.
Assistant
Now let me look at the CallbackMutex class and how offloadMutex is used.
Assistant
Now let me understand the problem. The issue is about automatic offload triggers creating redundant retry work. Currently, when
maybeOffloadInBackgroundis called while an offload is running, themaybeOffloadmethod detects that the mutex is locked and reschedules itself viascheduledExecutor.schedule— creating a recurring retry loop that keeps trying every 100ms. When many triggers arrive during one offload, each one keeps retrying, creating redundant work.Let me look at the full maybeOffloadInBackground and maybeOffload more carefully, along with the NULL_OFFLOAD_PROMISE definition.
Assistant
Let me look at how trimming handles a similar coalescing pattern for reference.
Assistant
Let me look at the trim pattern for the tryLock failure.
Assistant
Let me look at existing offload tests to understand expected behaviors.
Assistant
Let me look at the full OffloadPrefixTest to understand the test scenarios that could be affected.
Assistant
Let me read the
multipleAutoTriggerstest fully.Assistant
Let me look at the OffloadLedgerDeleteTest setup to verify the mutex state when
maybeOffloadInBackgroundis called.Assistant
Now I have a clear understanding. Let me implement the coalescing solution. First, let me add the field to track pending follow-up triggers.
Assistant
Let me use the
editcommand directly instead.Assistant
Now let me modify the
maybeOffloadmethod. Let me view the current line numbers.Assistant
There's a duplicate
});at line 2862. Let me remove it.Assistant
Now let me add the helper method
triggerPendingAutomaticOffload. Let me add it right aftermaybeOffload(after line 2910).Assistant
Now let me modify the manual offload path. Let me find its current line numbers.
Assistant
There's a duplicate
});andoffloadLoopat lines 3683-3684. Let me remove them.Assistant
Now let me check the ShadowManagedLedgerImpl to see if it overrides offload-related methods.
Assistant
Let me compile the managed-ledger module to verify the changes compile.
Assistant
Compilation succeeded. Now let me run the relevant offload tests.
Assistant
All OffloadPrefixTest tests pass. Let me also run the other offload-related tests.
Assistant
All passing. Now let me write a temporary reproduction/test script to verify the coalescing behavior — that multiple automatic triggers during a running offload produce at most one follow-up rather than redundant retries.
Assistant
Let me look at the test class setup to write a proper temporary verification test.
Assistant
Let me write a temporary test to verify the coalescing behavior directly. First, let me check the test base class.
Assistant
Let me create a temporary test to verify the coalescing behavior.
Assistant
The
getOffloadPolicies()returnsOffloadPoliciesinterface. Let me cast toOffloadPoliciesImpl.Assistant
The temp test passes, confirming the coalescing mechanism works. Now let me remove the temporary test file.
Assistant
Now let me run the broader managed-ledger test suite to ensure nothing is broken.
Assistant
The full managed-ledger test suite passes. Let me also run the broker AdminApiOffloadTest which tests offloading from the admin perspective, since the manual offload path was modified.
Assistant
All tests pass. Let me review the final diff to ensure the changes are clean.
Assistant
The diff is clean. Let me run the three most relevant tests once more to confirm correctness of the coalescing scenarios.
Assistant
All tests pass. Let me verify the final state of the changed methods one more time to confirm correctness.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.