Skip to content
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

Merged

Conversation

congbobo184
Copy link
Contributor

@congbobo184 congbobo184 commented Jun 18, 2021

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

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)

Copy link
Contributor

@eolivelli eolivelli left a 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 ?

@@ -3526,5 +3528,26 @@ public void testCursorCheckReadPositionChanged() throws Exception {
ledger.close();
}


@Test // (timeOut = 20000)
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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());
Copy link
Contributor

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.

Copy link
Contributor Author

@congbobo184 congbobo184 Jun 19, 2021

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.

@gaoran10
Copy link
Contributor

I looked at the method getNumberOfEntries of the class ManagedLedgerImpl, if the fromPosition or toPosition is invalid, such as 3:-1, the compute result will be wrong. If use the openClosed range will work around the problem. Maybe we could refine this method in next PR.

@congbobo184
Copy link
Contributor Author

congbobo184 commented Jun 19, 2021

I looked at the method getNumberOfEntries of the class ManagedLedgerImpl, if the fromPosition or toPosition is invalid, such as 3:-1, the compute result will be wrong. If use the openClosed range will work around the problem. Maybe we could refine this method in next PR.

yes, now after use getNumberOfEntries will -1 so we should find all the place where use getNumberOfEntries change it don't -1 in the next pr

}

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()));
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

@codelipenghui codelipenghui left a 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?

@congbobo184 congbobo184 changed the title [Broker] Fix get wrong backlog number. [Broker] Fix the backlog issue with --precise-backlog=true Jun 20, 2021
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@codelipenghui codelipenghui merged commit e3a97ee into apache:master Jun 21, 2021
codelipenghui pushed a commit to codelipenghui/incubator-pulsar that referenced this pull request Jun 22, 2021
)

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)
codelipenghui pushed a commit to codelipenghui/incubator-pulsar that referenced this pull request Jun 22, 2021
)

## 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)
@codelipenghui codelipenghui added cherry-picked/branch-2.7 Archived: 2.7 is end of life cherry-picked/branch-2.8 Archived: 2.8 is end of life labels Jun 22, 2021
eolivelli pushed a commit that referenced this pull request Jun 22, 2021
## 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)
yangl pushed a commit to yangl/pulsar that referenced this pull request Jun 23, 2021
)

## 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
eolivelli pushed a commit to datastax/pulsar that referenced this pull request Jul 5, 2021
)

## 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)
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
)

## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.7 Archived: 2.7 is end of life cherry-picked/branch-2.8 Archived: 2.8 is end of life release/2.7.3 release/2.8.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants