-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] PulsarLedgerManager to pass correct error code to BK client #16857
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
Conversation
…eletion of already deleted ledger
58bb354 to
bd7cbbe
Compare
eolivelli
left a comment
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.
Overall lgtm
I have left two minor comments
|
|
||
| CompletableFuture<Versioned<LedgerMetadata>> future = store.put(getLedgerPath(ledgerId), data, Optional.of(-1L)) | ||
| .thenApply(stat -> new Versioned(metadata, new LongVersion(stat.getVersion()))); | ||
| .thenApply(stat -> { |
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.
Nit:
We can replace this with thenAccept
or the both of the two calls (apply and exceptionally) with whenComplete
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.
+1 for simplifying the code.
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.
fixed
|
|
||
| private static Throwable mapToBkException(Throwable ex) { | ||
| if (ex instanceof MetadataStoreException.NotFoundException) { | ||
| return BKException.create(BKException.Code.NoSuchLedgerExistsOnMetadataServerException); |
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.
What about calling initCause and add the original error to the chain?
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.
fixed
|
@codelipenghui @BewareMyPower I think that we should include this in 2.10 |
|
@eolivelli You can add the |
hangc0276
left a comment
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.
Overall LGTM.
|
|
||
| CompletableFuture<Versioned<LedgerMetadata>> future = store.put(getLedgerPath(ledgerId), data, Optional.of(-1L)) | ||
| .thenApply(stat -> new Versioned(metadata, new LongVersion(stat.getVersion()))); | ||
| .thenApply(stat -> { |
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.
+1 for simplifying the code.
mattisonchao
left a comment
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 left some minor concerns.
| log.info("Ledger {} does not exist, ignoring", cursor.cursorsLedgerId); | ||
| return null; | ||
| } | ||
| throw new CompletionException(ex); |
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.
If the exception is CompletionException we don't need to wrap it again. please see FutureUtil#wrapToCompletionException
| log.error("Failed to create ledger {}: {}", ledgerId, ex.getMessage()); | ||
| return null; | ||
| }); | ||
| CompletableFuture<Versioned<LedgerMetadata>> promise = new CompletableFuture<>(); |
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.
Just a small concern:
I prefer the original chain-style CompletableFuture. it has two benefits than current:
- If we use a chain-style future, we don't need to create a separate
CompletableFuture. - In the current approach, it has risks cause the future can not complete yet. for example, throw an exception before we complete the
promise. (But this method looks fine.
Please let me know if you have any good suggestions. thanks a lot!
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.
yes, agree. Why create a new future here?
eolivelli
left a comment
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
RobertIndie
left a comment
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.
Overall looks good to me.
| try { | ||
| bookKeeper.deleteLedger(firstLedgerToDelete); | ||
| } catch (BKException.BKNoSuchLedgerExistsOnMetadataServerException bke) { | ||
| // pass | ||
| } |
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.
| try { | |
| bookKeeper.deleteLedger(firstLedgerToDelete); | |
| } catch (BKException.BKNoSuchLedgerExistsOnMetadataServerException bke) { | |
| // pass | |
| } | |
| try { | |
| bookKeeper.deleteLedger(firstLedgerToDelete); | |
| fail(); | |
| } catch (BKException.BKNoSuchLedgerExistsOnMetadataServerException bke) { | |
| // pass | |
| } |
Please use fail() here.
Technoboy-
left a comment
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.
Merge this patch first, let it go 2.11, and then we can fix it with @RobertIndie comment given in the test of ml.
…ient (apache#16857) (cherry picked from commit 2e8bd3d) (cherry picked from commit 796dd62)
Motivation
In some situations it is possible to encounter case when deletion of a ManagedLedger deals with cases of already deleted bookie ledgers.
Such cases currently handled as errors even though they are safe to ignore.
Currently, it is impossible to handle these cases because PulsarManagedLedger returns error that's not mappable into the BK error code end the end user ends up with obscure
UnexpectedConditionException(error code -999) that cannot be distinguished from ledger already deleted case.Modifications
This takes over #16664
Verifying this change
This change added tests and can be verified as follows:
Does this pull request potentially affect one of the following parts:
If
yeswas chosen, please highlight the changesNothing that I can think of.
Documentation
Check the box below or label this PR directly.
Need to update docs?
doc-required(Your PR needs to update docs and you will update later)
doc-not-needed(Please explain why)
doc(Your PR contains doc changes)
doc-complete(Docs have been already added)