-
Notifications
You must be signed in to change notification settings - Fork 974
Use readExplicitLAC instead of readEntry in order to get current LastAddConfirmed #1572
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
350c872
Use readExplicitLAC instead of readEntry in order to get current Last…
eolivelli 7a352bb
fix checkstyle
eolivelli 0872243
Rebases to latest master and add new configuration parameter
eolivelli 49914bf
Address comments and add tests
eolivelli 6988b16
Fix checkstyle
eolivelli bf948ad
Rename method
eolivelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/TryPendingReadLacOp.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.bookkeeper.client; | ||
|
|
||
| import io.netty.buffer.ByteBuf; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.bookkeeper.client.BKException.BKDigestMatchException; | ||
| import org.apache.bookkeeper.net.BookieSocketAddress; | ||
| import org.apache.bookkeeper.proto.BookieClient; | ||
| import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadLacCallback; | ||
| import org.apache.bookkeeper.proto.checksum.DigestManager.RecoveryData; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * This op is try to read last confirmed without involving quorum coverage checking. | ||
| * Use {@link PendingReadLacOp} if you need quorum coverage checking. | ||
| */ | ||
|
|
||
| class TryPendingReadLacOp implements ReadLacCallback { | ||
| static final Logger LOG = LoggerFactory.getLogger(TryPendingReadLacOp.class); | ||
| LedgerHandle lh; | ||
| LacCallback cb; | ||
| int numResponsesPending; | ||
| volatile boolean completed = false; | ||
| volatile boolean hasValidResponse = false; | ||
| int lastSeenError = BKException.Code.ReadException; | ||
| RecoveryData maxRecoveredData; | ||
| long maxLac; | ||
| final List<BookieSocketAddress> currentEnsemble; | ||
| final BookieClient bookieClient; | ||
|
|
||
| /* | ||
| * Wrapper to get Lac from the request | ||
| */ | ||
| interface LacCallback { | ||
| void getLacComplete(int rc, long lac); | ||
| } | ||
|
|
||
| TryPendingReadLacOp(LedgerHandle lh, BookieClient bookieClient, | ||
| List<BookieSocketAddress> ensemble, LacCallback cb) { | ||
| this.lh = lh; | ||
| this.cb = cb; | ||
| this.maxLac = lh.getLastAddConfirmed(); | ||
| this.numResponsesPending = lh.getLedgerMetadata().getEnsembleSize(); | ||
| this.bookieClient = bookieClient; | ||
| this.maxRecoveredData = new RecoveryData(maxLac, 0); | ||
| this.currentEnsemble = ensemble; | ||
| } | ||
|
|
||
| public void initiate() { | ||
| for (int i = 0; i < currentEnsemble.size(); i++) { | ||
| bookieClient.readLac(currentEnsemble.get(i), | ||
| lh.ledgerId, this, i); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void readLacComplete(int rc, long ledgerId, final ByteBuf lacBuffer, final ByteBuf lastEntryBuffer, | ||
| Object ctx) { | ||
| int bookieIndex = (Integer) ctx; | ||
|
|
||
| numResponsesPending--; | ||
|
|
||
| if (completed) { | ||
| return; | ||
| } | ||
|
|
||
|
|
||
| if (rc == BKException.Code.OK) { | ||
| try { | ||
| // Each bookie may have two store LAC in two places. | ||
| // One is in-memory copy in FileInfo and other is | ||
| // piggy-backed LAC on the last entry. | ||
| // This routine picks both of them and compares to return | ||
| // the latest Lac. | ||
|
|
||
| // lacBuffer and lastEntryBuffer are optional in the protocol. | ||
| // So check if they exist before processing them. | ||
| long newLac = LedgerHandle.INVALID_ENTRY_ID; | ||
| // Extract lac from FileInfo on the ledger. | ||
| if (lacBuffer != null && lacBuffer.readableBytes() > 0) { | ||
| long lac = lh.macManager.verifyDigestAndReturnLac(lacBuffer); | ||
| if (lac > maxLac) { | ||
| newLac = lac; | ||
| } | ||
| } | ||
| // Extract lac from last entry on the disk | ||
| if (lastEntryBuffer != null && lastEntryBuffer.readableBytes() > 0) { | ||
| RecoveryData recoveryData = lh.macManager.verifyDigestAndReturnLastConfirmed(lastEntryBuffer); | ||
| long piggyBackedLAC = recoveryData.getLastAddConfirmed(); | ||
| if (piggyBackedLAC > newLac) { | ||
| newLac = piggyBackedLAC; | ||
| } | ||
| } | ||
| if (newLac > maxLac) { | ||
| // as for TryReadLastConfirmedOp we will call the callback as soon as possible | ||
| cb.getLacComplete(rc, newLac); | ||
| completed = true; | ||
| } | ||
| maxLac = newLac; | ||
|
|
||
| hasValidResponse = true; | ||
| } catch (BKDigestMatchException e) { | ||
| // Too bad, this bookie did not give us a valid answer, we | ||
| // still might be able to recover. So, continue | ||
| LOG.error("Mac mismatch while reading ledger: " + ledgerId + " LAC from bookie: " | ||
| + currentEnsemble.get(bookieIndex)); | ||
| rc = BKException.Code.DigestMatchException; | ||
| } | ||
| } | ||
|
|
||
| if (rc == BKException.Code.NoSuchLedgerExistsException || rc == BKException.Code.NoSuchEntryException) { | ||
| hasValidResponse = true; | ||
| } | ||
|
|
||
| if (rc == BKException.Code.UnauthorizedAccessException && !completed) { | ||
| cb.getLacComplete(rc, maxLac); | ||
| completed = true; | ||
| return; | ||
| } | ||
|
|
||
| if (!hasValidResponse && BKException.Code.OK != rc) { | ||
| lastSeenError = rc; | ||
| } | ||
|
|
||
| if (numResponsesPending == 0 && !completed) { | ||
| if (!hasValidResponse) { | ||
| cb.getLacComplete(lastSeenError, maxLac); | ||
| } else { | ||
| cb.getLacComplete(BKException.Code.OK, maxLac); | ||
| } | ||
| completed = true; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I am not sure using a flag is the best choice here. the bookkeeper client should be smart to figure out whether it should be reading explicit lac or piggybacked lac.
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 the name is misleading but it is already here.
This function will compose explicit and piggybacked LAC.
So actually it would be better to use always readExplicitLAC RPC, but we cannot enable it by default because it works only with recent bookies and with v3 protocol
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.
Client knows it is using V3 protocol or not; so why not use the explicitLAC for >= v3 automatically without a conf option?
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.
ExplicitLAC is since 4.5. V3 protocol was already present. So we have bookies which talk v3 and do not know ExplicitLAC protocol: we will break compatibility from 4.9 clients and 4.4 bookies.
Honestly I don't think this is a real production problem because 4.4 is very old, but we don't have a clear EOL policy.
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.
@eolivelli I don't understand your comment here. if a bookie doesn't know ExplicitLAC, the request will be rejected and the client will know about that, right? when client know that, it can fallback to disable using explicit lac, no?
Uh oh!
There was an error while loading. Please reload this page.
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.
@sijie so you are suggesting to fallback to piggybackLac in case of "UnsupportedOperation" error from bookie.
We should keep track of this per-bookie. I think this is very tricky, we need to add a lot of code and runtime overhead for the sake of compatibility with very old bookies (4.4).
We can have this configuration flag, enabled by default in 4.9 in case of v3+ protocol and disable for v2 protocol, and then drop it as soon as we decide to drop support for compatibility with such old versions.
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.
@eolivelli
yes.
probably yes.
my main concern is with this change, we have so many different variants of reading lac operations in the main repo. it is very confusing and hard to maintain. I would suggest us holding on merging this PR and thinking of a better solution for it, rather than rushing at merging this and make things hard to maintain in future.
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.
@sijie I see your concern. There is no hurry, we can work on this topic for 4.10.
I think that current asyncReadExplicitLastConfirmed() is better because it is actually merging the two values (piggy backed + explicit)
bookkeeper/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingReadLacOp.java
Line 115 in e426547
I think this is the future, I am not dropping the legacy method only for compatibility with 4.4.
The best would be to not have the flag, not perform any compatibility effort, and say that 4.9 clients are able to read from 4.4 bookies only using v2 protocol (in v2 protocol we don't have ExplicitLAC so we cannot use PendingReadLacOp)
PendingReadLacOp is already here, I am not adding it, I am only suggesting to use PendingReadLacOp for regular readLastAddConfirmed() instead of ReadLastConfirmedOp.
Ideally we should merge PendingReadLacOp with ReadLastConfirmedOp and drop PendingReadLacOp, but it is greater work, because ReadLastConfirmedOp handles fencing stuff