Skip to content

[fix] [broker] Topic close failure leaves subscription in a permanent fence state - #19692

Merged
poorbarcode merged 9 commits into
apache:masterfrom
poorbarcode:fix/topic_not_work_after_close_fail
Mar 9, 2023
Merged

poorbarcode merged 9 commits into
apache:masterfrom
poorbarcode:fix/topic_not_work_after_close_fail

Conversation

@poorbarcode

Copy link
Copy Markdown
Contributor

Motivation

After a Topic close failure or a delete failure, the fence state will be reset to get the topic back to work,but it will not reset the fence state of the subscription, which will result in the consumer never being able to connect to the broker.

image

Modifications

Reset the fence state of subscriptions if the operation of topic close is failed.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@poorbarcode poorbarcode self-assigned this Mar 2, 2023
@poorbarcode poorbarcode added type/bug The PR fixed a bug or issue reported a bug release/2.9.6 release/2.10.5 labels Mar 2, 2023
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Mar 2, 2023
*/
public synchronized CompletableFuture<Void> resumeAfterFence() {
CompletableFuture<Void> result = new CompletableFuture<>();
fenceFuture.whenComplete((ignore, ignore2) -> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fenceFuture may be null here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Already fixed

result.complete(null);
} catch (Exception ex){
result.completeExceptionally(ex);
log.error("[{}] Resume subscription[{}] failure: {}", topicName, subName, ex.getMessage(), ex);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please move this before completeExceptionally, otherwise logs may be hard to understand

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Already fixed

}

private void unfenceTopicToResume() {
subscriptions.values().forEach(sub -> sub.resumeAfterFence());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

resumeAfterFence returns a CompletableFuture, don't we need to "wait"

@poorbarcode poorbarcode Mar 2, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

During the execution of the method resumeAfterFence, consumers will keep trying to reconnect. When the execution of method resumeAfterFence is complete, the consumer will automatically connect successfully and can consume the message. So it's okay not to wait.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Then you can make resumeAfterFence return "void", can't you ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. Already fixed.

@poorbarcode
poorbarcode requested a review from eolivelli March 2, 2023 09:56
return fenceFuture;
}
if (fenceFuture != null && fenceFuture.isDone() && !fenceFuture.isCompletedExceptionally()){
return fenceFuture;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems that if PersistentSubscription disconnect successfully, but PersistentTopic close failed and resume, the PersistentSubscription can't disconnect again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. already fixed.

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@gaoran10 gaoran10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@poorbarcode

Copy link
Copy Markdown
Contributor Author

/pulsarbot rerun-failure-checks

1 similar comment
@poorbarcode

Copy link
Copy Markdown
Contributor Author

/pulsarbot rerun-failure-checks

@codelipenghui codelipenghui added this to the 3.0.0 milestone Mar 7, 2023
Comment on lines +901 to +902
if (fenceFuture != null && !fenceFuture.isDone()){
return fenceFuture;
}
if (fenceFuture != null && fenceFuture.isDone() && !fenceFuture.isCompletedExceptionally()){
return fenceFuture;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like we can simplify to

if (fenceFuture != null && !fenceFuture.isCompletedExceptionally()) {
     return fenceFuture;
}

And why must we create a new future if the existing fenceFuture is completed with an exception? To make it retryable?

If yes, we'd better add a comment here to help us to understand why it should be retryable in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think you are right. There has no scenario that needs to retry.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

}
fenceFuture = null;
} catch (Exception ex) {
log.error("[{}] Resume subscription[{}] failure: {}", topicName, subName, ex.getMessage(), ex);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.error("[{}] Resume subscription[{}] failure: {}", topicName, subName, ex.getMessage(), ex);
log.error("[{}] Resume subscription [{}] failure", topicName, subName, ex);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

already changed

@poorbarcode
poorbarcode force-pushed the fix/topic_not_work_after_close_fail branch from 53a3f6a to 513f663 Compare March 7, 2023 15:25
@poorbarcode

Copy link
Copy Markdown
Contributor Author

/pulsarbot rerun-failure-checks

2 similar comments
@poorbarcode

Copy link
Copy Markdown
Contributor Author

/pulsarbot rerun-failure-checks

@poorbarcode

Copy link
Copy Markdown
Contributor Author

/pulsarbot rerun-failure-checks

@poorbarcode
poorbarcode merged commit cdeef00 into apache:master Mar 9, 2023
poorbarcode added a commit that referenced this pull request Mar 9, 2023
… fence state (#19692)

Motivation : After a Topic close failure or a delete failure, the fence state will be reset to get the topic back to work,but it will not reset the fence state of the subscription, which will result in the consumer never being able to connect to the broker.
Modifications: Reset the fence state of subscriptions if the operation of topic close is failed.
(cherry picked from commit cdeef00)
poorbarcode added a commit that referenced this pull request Mar 9, 2023
… fence state (#19692)

Motivation : After a Topic close failure or a delete failure, the fence state will be reset to get the topic back to work,but it will not reset the fence state of the subscription, which will result in the consumer never being able to connect to the broker.
Modifications: Reset the fence state of subscriptions if the operation of topic close is failed.
(cherry picked from commit cdeef00)
poorbarcode added a commit that referenced this pull request Mar 9, 2023
… fence state (#19692)

Motivation : After a Topic close failure or a delete failure, the fence state will be reset to get the topic back to work,but it will not reset the fence state of the subscription, which will result in the consumer never being able to connect to the broker.
Modifications: Reset the fence state of subscriptions if the operation of topic close is failed.
(cherry picked from commit cdeef00)
@poorbarcode
poorbarcode deleted the fix/topic_not_work_after_close_fail branch March 9, 2023 03:14
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Mar 9, 2023
… fence state (apache#19692)

Motivation : After a Topic close failure or a delete failure, the fence state will be reset to get the topic back to work,but it will not reset the fence state of the subscription, which will result in the consumer never being able to connect to the broker.
Modifications: Reset the fence state of subscriptions if the operation of topic close is failed.
(cherry picked from commit cdeef00)
(cherry picked from commit 751eeea)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants