Skip to content

Conversation

@dlg99
Copy link
Contributor

@dlg99 dlg99 commented Jul 28, 2022

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

  1. Made PulsarManagedLedger return BK error where possible so BK client has a chance to handle/return correct error.
  2. Ignored NoSuchLedgerExistsOnMetadataServerException on delete as it is safe there

This takes over #16664

Verifying this change

This change added tests and can be verified as follows:

  • Added unit tests

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

Nothing that I can think of.

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API: (yes / no)
  • The schema: (yes / no / don't know)
  • The default values of configurations: (yes / no)
  • The wire protocol: (yes / no)
  • The rest endpoints: (yes / no)
  • The admin cli options: (yes / no)
  • Anything that affects deployment: (yes / no / don't know)

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)

@dlg99 dlg99 requested review from eolivelli and merlimat July 28, 2022 22:18
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Jul 28, 2022
@dlg99 dlg99 force-pushed the metadata-rc-bk-take2 branch from 58bb354 to bd7cbbe Compare July 28, 2022 22:32
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.

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 -> {
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@eolivelli
Copy link
Contributor

@codelipenghui @BewareMyPower I think that we should include this in 2.10

@BewareMyPower
Copy link
Contributor

@eolivelli You can add the release/2.10.x label. Currently there is no 2.10.x release in progress.

@eolivelli eolivelli modified the milestones: 2.12.0, 2.11.0 Jul 29, 2022
@eolivelli eolivelli added type/bug The PR fixed a bug or issue reported a bug area/broker release/2.10.2 labels Jul 29, 2022
Copy link
Contributor

@hangc0276 hangc0276 left a 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 -> {
Copy link
Contributor

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.

Copy link
Member

@mattisonchao mattisonchao left a 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);
Copy link
Member

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

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:

  1. If we use a chain-style future, we don't need to create a separate CompletableFuture.
  2. 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!

Copy link
Contributor

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?

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

Copy link
Member

@RobertIndie RobertIndie left a 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.

Comment on lines +397 to +401
try {
bookKeeper.deleteLedger(firstLedgerToDelete);
} catch (BKException.BKNoSuchLedgerExistsOnMetadataServerException bke) {
// pass
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
try {
bookKeeper.deleteLedger(firstLedgerToDelete);
} catch (BKException.BKNoSuchLedgerExistsOnMetadataServerException bke) {
// pass
}
try {
bookKeeper.deleteLedger(firstLedgerToDelete);
fail();
} catch (BKException.BKNoSuchLedgerExistsOnMetadataServerException bke) {
// pass
}

Please use fail() here.

Copy link
Contributor

@Technoboy- Technoboy- left a 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.

@Technoboy- Technoboy- merged commit 2e8bd3d into apache:master Aug 3, 2022
codelipenghui pushed a commit that referenced this pull request Aug 8, 2022
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Aug 16, 2022
…ient (apache#16857)

(cherry picked from commit 2e8bd3d)
(cherry picked from commit 796dd62)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/broker cherry-picked/branch-2.10 doc-not-needed Your PR changes do not impact docs release/2.10.2 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants