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] Topic policy reader can't recover when get any exception. #17562

Merged
merged 3 commits into from
Sep 13, 2022
Merged

[fix][broker] Topic policy reader can't recover when get any exception. #17562

merged 3 commits into from
Sep 13, 2022

Conversation

mattisonchao
Copy link
Member

@mattisonchao mattisonchao commented Sep 9, 2022

Fix #15891

Motivation

When creating the topic policy reader got any problem(maybe a network problem), and we can not clear the current state, which will let the broker can not retry to init the topic policy reader again until we unload the namespace.

Please see the details in the code. https://github.com/apache/pulsar/pull/17562/files#r966658816

Modifications

  • Fix the wrong logic and make the method more safety.

Verifying this change

  • Make sure that the change passes the CI checks.

I think it's not a logical error. we don't need to add the unit test.

Documentation

  • 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)

initPolicesCache(reader, result);
result.thenRun(() -> readMorePolicies(reader));
}
readerCompletableFuture.thenAccept(reader -> {
Copy link
Member Author

@mattisonchao mattisonchao Sep 9, 2022

Choose a reason for hiding this comment

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

Use thenAccept to avoid using the null value in whenComplete again. because we will pass the result future to the next operation. So, we don't need thenCompose

if (ex != null) {
log.error("[{}] Failed to create reader on __change_events topic", namespace, ex);
result.completeExceptionally(ex);
cleanCacheAndCloseReader(reader.getSystemTopic().getTopicName().getNamespaceObject(), false);
Copy link
Member Author

@mattisonchao mattisonchao Sep 9, 2022

Choose a reason for hiding this comment

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

In the current time reader is null, So we can't clean the cache and close the reader.

result.thenRun(() -> readMorePolicies(reader));
}).exceptionally(ex -> {
log.error("[{}] Failed to create reader on __change_events topic", namespace, ex);
cleanCacheAndCloseReader(namespace, false);
Copy link
Member Author

Choose a reason for hiding this comment

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

This method won't have any chance to throw an exception. I think it's safe enough and don't need try-catch.

readerFuture.thenAccept(SystemTopicClient.Reader::closeAsync);
readerFuture.thenCompose(SystemTopicClient.Reader::closeAsync)
.exceptionally(ex -> {
log.warn("[{}] Close change_event reader fail.", namespace, ex);
Copy link
Member Author

Choose a reason for hiding this comment

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

We can add a log to help debug. Maybe we can introduce more mechanisms to clean up the resource. But it's not the current PR focus.

Copy link
Contributor

@poorbarcode poorbarcode left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Sep 9, 2022
zymap pushed a commit that referenced this pull request Sep 15, 2022
@zymap zymap added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Sep 15, 2022
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Sep 16, 2022
dragonls pushed a commit to dragonls/pulsar that referenced this pull request Oct 21, 2022
dragonls pushed a commit to dragonls/pulsar that referenced this pull request Oct 21, 2022
…rge request !44)

[fix][broker] Topic policy reader can't recover when get any exception (apache#17562)
touchkey pushed a commit to sajithsebastian/pulsar that referenced this pull request May 24, 2023
touchkey pushed a commit to sajithsebastian/pulsar that referenced this pull request May 26, 2023
@fmiguelez
Copy link
Contributor

fmiguelez commented Sep 21, 2023

@mattisonchao @zymap Do we have any plan to release 2.8.5 shortly?
This is issue is critical for us and we are currently working with Puslar 2.8.4.

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.

"Topic policies cache have not init" randomly happen on different topics in the same namespace
7 participants