-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Broker] Fix the backlog issue with --precise-backlog=true #10966
[Broker] Fix the backlog issue with --precise-backlog=true #10966
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
LGTM
I left a comment about a missing test.
can you please take a look ?
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
Show resolved
Hide resolved
@@ -3526,5 +3528,26 @@ public void testCursorCheckReadPositionChanged() throws Exception { | |||
ledger.close(); | |||
} | |||
|
|||
|
|||
@Test // (timeOut = 20000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The param timeOut
is need or not?
@Test // (timeOut = 20000) | ||
public void testCursorGetBacklog() throws Exception { | ||
ManagedLedgerConfig managedLedgerConfig = new ManagedLedgerConfig(); | ||
managedLedgerConfig.setMaxEntriesPerLedger(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need test the scenario that one ledger maintain multiple entries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea.
Field field = ManagedLedgerImpl.class.getDeclaredField("ledgers"); | ||
field.setAccessible(true); | ||
|
||
((ConcurrentSkipListMap<Long, MLDataFormats.ManagedLedgerInfo.LedgerInfo>) field.get(ledger)).remove(position.getLedgerId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's better to change the markDeletePosition
at the same time, due to the range start position is markDeletePosition
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is for when the ledger have been deleted and the markDeletePosition is still the deleted ledger we can get the correct backlog.
I looked at the method |
yes, now after use |
} | ||
|
||
long backlog = ManagedLedgerImpl.ENTRIES_ADDED_COUNTER_UPDATER.get(ledger) - messagesConsumedCounter; | ||
if (backlog < 0) { | ||
// In some case the counters get incorrect values, fall back to the precise backlog count | ||
backlog = getNumberOfEntries(Range.closed(markDeletePosition, ledger.getLastPosition())) - 1; | ||
backlog = getNumberOfEntries(Range.openClosed(markDeletePosition, ledger.getLastPosition())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we handle this situation inside the method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The range openClosed
may be the appropriate select due to that the backlog metric doesn't include the markDeletePosition
position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change LGTM, @congbobo184 could you please update the PR title and the description since the PR only fixes the backlog issue with --precise-backlog=true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
) fix backlog issuse with --precise-backlog=true. Now when `managedLedger` create a new `ledger` complete. if `markDelete` is the `previousLedger` LAC it will delete the previousLedger from `managedLedger` . when get backlog we will use range.close to get `getNumberOfEntries` -1, if previousLedger not exist will get the wrong number. ![image](https://user-images.githubusercontent.com/39078850/122502847-fce47800-d029-11eb-81b3-abc9e595d93e.png) use range.openClose() to `getBacklog`. Add the tests for it (cherry picked from commit e3a97ee)
) ## Motivation fix backlog issuse with --precise-backlog=true. Now when `managedLedger` create a new `ledger` complete. if `markDelete` is the `previousLedger` LAC it will delete the previousLedger from `managedLedger` . when get backlog we will use range.close to get `getNumberOfEntries` -1, if previousLedger not exist will get the wrong number. ![image](https://user-images.githubusercontent.com/39078850/122502847-fce47800-d029-11eb-81b3-abc9e595d93e.png) ## implement use range.openClose() to `getBacklog`. ### Verifying this change Add the tests for it (cherry picked from commit e3a97ee)
## Motivation fix backlog issuse with --precise-backlog=true. Now when `managedLedger` create a new `ledger` complete. if `markDelete` is the `previousLedger` LAC it will delete the previousLedger from `managedLedger` . when get backlog we will use range.close to get `getNumberOfEntries` -1, if previousLedger not exist will get the wrong number. ![image](https://user-images.githubusercontent.com/39078850/122502847-fce47800-d029-11eb-81b3-abc9e595d93e.png) ## implement use range.openClose() to `getBacklog`. ### Verifying this change Add the tests for it (cherry picked from commit e3a97ee)
) ## Motivation fix backlog issuse with --precise-backlog=true. Now when `managedLedger` create a new `ledger` complete. if `markDelete` is the `previousLedger` LAC it will delete the previousLedger from `managedLedger` . when get backlog we will use range.close to get `getNumberOfEntries` -1, if previousLedger not exist will get the wrong number. ![image](https://user-images.githubusercontent.com/39078850/122502847-fce47800-d029-11eb-81b3-abc9e595d93e.png) ## implement use range.openClose() to `getBacklog`. ### Verifying this change Add the tests for it
) ## Motivation fix backlog issuse with --precise-backlog=true. Now when `managedLedger` create a new `ledger` complete. if `markDelete` is the `previousLedger` LAC it will delete the previousLedger from `managedLedger` . when get backlog we will use range.close to get `getNumberOfEntries` -1, if previousLedger not exist will get the wrong number. ![image](https://user-images.githubusercontent.com/39078850/122502847-fce47800-d029-11eb-81b3-abc9e595d93e.png) ## implement use range.openClose() to `getBacklog`. ### Verifying this change Add the tests for it (cherry picked from commit e3a97ee) (cherry picked from commit b61832d)
) ## Motivation fix backlog issuse with --precise-backlog=true. Now when `managedLedger` create a new `ledger` complete. if `markDelete` is the `previousLedger` LAC it will delete the previousLedger from `managedLedger` . when get backlog we will use range.close to get `getNumberOfEntries` -1, if previousLedger not exist will get the wrong number. ![image](https://user-images.githubusercontent.com/39078850/122502847-fce47800-d029-11eb-81b3-abc9e595d93e.png) ## implement use range.openClose() to `getBacklog`. ### Verifying this change Add the tests for it
Motivation
fix backlog issuse with --precise-backlog=true.
Now when
managedLedger
create a newledger
complete. ifmarkDelete
is thepreviousLedger
LAC it will delete the previousLedger frommanagedLedger
. when get backlog we will use range.close to getgetNumberOfEntries
-1, if previousLedger not exist will get the wrong number.implement
use range.openClose() to
getBacklog
.Verifying this change
Add the tests for it
Does this pull request potentially affect one of the following parts:
If yes was chosen, please highlight the changes
Dependencies (does it add or upgrade a dependency): (no)
The public API: (no)
The schema: (no)
The default values of configurations: (no)
The wire protocol: (no)
The rest endpoints: (no)
The admin cli options: (no)
Anything that affects deployment: (no)