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][broker] Fix pulsarLedgerIdGenerator can't delete index path when zk metadata store config rootPath. #17192

Merged
merged 2 commits into from
Aug 24, 2022

Conversation

horizonzy
Copy link
Member

@horizonzy horizonzy commented Aug 20, 2022

(If this PR fixes a github issue, please add Fixes #<xyz>.)

Fixes #17191

Motivation

Fix pulsarLedgerIdGenerator can't delete index path when zk metadata store config rootPath.

This problem may lead zk oom if the ManagedLedgerImpl create new ledger too frequent.

Documentation

  • doc-not-needed
    (Please explain why)

@github-actions
Copy link

@horizonzy Please provide a correct documentation label for your PR.
Instructions see Pulsar Documentation Label Guide.

@github-actions github-actions bot added doc-label-missing doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Aug 20, 2022
@hangc0276 hangc0276 added release/blocker Indicate the PR or issue that should block the release until it gets resolved release/2.10.2 release/2.11.0 labels Aug 20, 2022
@hangc0276 hangc0276 added this to the 2.11.0 milestone Aug 20, 2022
@hangc0276 hangc0276 added type/bug The PR fixed a bug or issue reported a bug area/broker labels Aug 20, 2022
@@ -173,7 +174,7 @@ private CompletableFuture<Long> generateLongLedgerId() {
if (log.isDebugEnabled()) {
log.debug("DELETING HIGH ORDER DIR: {}", path);
}
store.delete(path, Optional.of(0L));
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a relative path we build ourself and won't have the problem of carrying root path when getting path from stats.getPath()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you are right. Thanks for reminder.

return path.replaceFirst(rootPath, "");
}
return path;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make this in the constructor to avoid calling replaceFirst every time?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a fixed path, it looks like we can't avoid replacing operation.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not a fixed path, it looks like we can't avoid replacing operation.

+1

return path.replaceFirst(rootPath, "");
}
return path;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a fixed path, it looks like we can't avoid replacing operation.

//So when we get the path from the stat, we should truncate the rootPath.
private String handleTheDeletePath(String path) {
if (store instanceof ZKMetadataStore) {
String rootPath = ((ZKMetadataStore) store).getRootPath();
Copy link
Contributor

Choose a reason for hiding this comment

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

I see we already have ledgersRoot of PulsarLedgerIdGenerator constructor, it's better to use it directly to avoid such checks here.

Copy link
Contributor

Choose a reason for hiding this comment

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

And we don't need to introduce a new method in ZKMetadataStore.java

Copy link
Member Author

Choose a reason for hiding this comment

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

I see we already have ledgersRoot of PulsarLedgerIdGenerator constructor, it's better to use it directly to avoid such checks here.

It's not the zk rootPath, the ledgersRoot is /ledegrs.

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 metadataServiceUriStr is metadata-store:127.0.0.1:2181/test, it's not a standard schema, so we can't resolve the path correctly in AbstractMetadataDriver#resolveLedgersRootPath.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see.

//So when we get the path from the stat, we should truncate the rootPath.
private String handleTheDeletePath(String path) {
if (store instanceof ZKMetadataStore) {
String rootPath = ((ZKMetadataStore) store).getRootPath();
Copy link
Contributor

Choose a reason for hiding this comment

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

I see.

@horizonzy
Copy link
Member Author

horizonzy commented Aug 22, 2022

This problem may lead zk oom if the ManagedLedgerImpl create new ledger too frequent.

@Technoboy- Technoboy- added cherry-picked/branch-2.11 and removed release/blocker Indicate the PR or issue that should block the release until it gets resolved cherry-picked/branch-2.11 labels Aug 22, 2022
@Technoboy- Technoboy- force-pushed the zk-root-patch-problem branch from 789781e to 365938c Compare August 23, 2022 06:50
Copy link
Contributor

@Jason918 Jason918 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 a minor suggestion.

@Test
public void testGenerateLedgerIdWithZkPrefix() throws Exception {
@Cleanup
MetadataStoreExtended store =
Copy link
Contributor

Choose a reason for hiding this comment

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

If this line is the only difference between testGenerateLedgerId and testGenerateLedgerIdWithZkPrefix, we can reuse the common codes here.

Copy link
Member Author

Choose a reason for hiding this comment

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

In testGenerateLedgerIdWithZkPrefix, we need check the index path is still exists.

@Jason918
Copy link
Contributor

This problem may lead zk oom if the ManagedLedgerImpl create new ledger too frequent.

You can add this to the Motivation.

@Technoboy- Technoboy- merged commit 9445fa7 into apache:master Aug 24, 2022
Technoboy- pushed a commit that referenced this pull request Aug 24, 2022
hangc0276 pushed a commit that referenced this pull request Aug 24, 2022
…n zk metadata store config rootPath. (#17192)

(cherry picked from commit 9445fa7)
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Aug 30, 2022
…n zk metadata store config rootPath. (apache#17192)

(cherry picked from commit 9445fa7)
(cherry picked from commit 805f985)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] PulsarLedgerIdGenerator can't delete the index path when zk metadata store config rootPath.
6 participants