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

Fix BenchReadThroughputLatency batch read can't stop problems. #4220

Merged

Conversation

horizonzy
Copy link
Member

Fix BenchReadThroughputLatency batch read can't stop problems.

@@ -89,7 +89,7 @@ private static void readLedger(ClientConfiguration conf, long ledgerId, byte[] p
lh = bk.openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32,
passwd);
long lastConfirmed = Math.min(lh.getLastAddConfirmed(), absoluteLimit);
if (lastConfirmed == lastRead) {
if (lastConfirmed <= lastRead) {
Copy link
Member Author

Choose a reason for hiding this comment

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

if the read is batched, the lastRead may be greater than lastConfirmed.

@@ -102,14 +102,14 @@ private static void readLedger(ClientConfiguration conf, long ledgerId, byte[] p
}
long starttime = System.nanoTime();

while (entriesRead <= lastConfirmed) {
while (entriesRead < lastConfirmed) {
long nextLimit = lastRead + 100000;
Enumeration<LedgerEntry> entries;
if (batchEntries <= 0) {
long readTo = Math.min(nextLimit, lastConfirmed);
entries = lh.readEntries(lastRead + 1, readTo);
Copy link
Member Author

Choose a reason for hiding this comment

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

If the read is single read, we should make sure that entriesRead is less than lastConfirmed. Or the lastRead + 1 will be greater than readTo.

long nextLimit = lastRead + 100000;
Enumeration<LedgerEntry> entries;
if (batchEntries <= 0) {
long readTo = Math.min(nextLimit, lastConfirmed);
entries = lh.readEntries(lastRead + 1, readTo);
} else {
entries = lh.batchReadEntries(lastRead, batchEntries, -1);
entries = lh.batchReadEntries(lastRead + 1, batchEntries, -1);
Copy link
Member Author

Choose a reason for hiding this comment

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

The lastRead entry already be read, so we should read next entry at the next read.

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 init the lastRead to -1 instead of 0, otherwise the entry 0 can't be read

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch.

while (entriesRead <= lastConfirmed) {
long nextLimit = lastRead + 100000;
while (entriesRead < lastConfirmed) {
long nextLimit = lastRead + 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why change it to 10?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, that's a test at my local, I will revert it.

@@ -89,7 +89,7 @@ private static void readLedger(ClientConfiguration conf, long ledgerId, byte[] p
lh = bk.openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32,
passwd);
long lastConfirmed = Math.min(lh.getLastAddConfirmed(), absoluteLimit);
if (lastConfirmed == lastRead) {
if (lastConfirmed <= lastRead + 1) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Because we from the entry 0 to start read, so here we should make lastRead + 1 to compare with lastConfirmed.

@hangc0276 hangc0276 merged commit ad06dfb into apache:master Mar 18, 2024
20 checks passed
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
…e#4220)

Fix BenchReadThroughputLatency batch read can't stop problems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants