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 delete_when_subscriptions_caught_up doesn't work while have active consumers #18283

Conversation

codelipenghui
Copy link
Contributor

Motivation

The current behavior for the delete_when_subscriptions_caught_up strategy is not expected. The active consumer will not be closed even if users enable delete_when_subscriptions_caught_up and there are no backlogs for the topic.

It should be the part that #6077 has missed. And Sijie has mentioned in the comment #6077 (review).

To correct the behavior of delete_when_subscriptions_caught_up

Modifications

Close active consumers if delete_when_subscriptions_caught_up is applied and there are no backlogs for the topic. So that the topic can be cleaned up properly by the topic GC thread.

Verifying this change

Updated the existing test.

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

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • Anything that affects deployment

Documentation

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

Matching PR in forked repository

PR in forked repository: codelipenghui#17

@codelipenghui codelipenghui added this to the 2.12.0 milestone Nov 1, 2022
@codelipenghui codelipenghui self-assigned this Nov 1, 2022
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Nov 1, 2022
@Technoboy- Technoboy- closed this Nov 2, 2022
@Technoboy- Technoboy- reopened this Nov 2, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 2, 2022

Codecov Report

Attention: Patch coverage is 52.38095% with 30 lines in your changes missing coverage. Please review.

Project coverage is 40.13%. Comparing base (0866c3a) to head (f8169c9).
Report is 2237 commits behind head on master.

Files with missing lines Patch % Lines
...sar/broker/service/persistent/PersistentTopic.java 52.38% 27 Missing and 3 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #18283      +/-   ##
============================================
+ Coverage     38.97%   40.13%   +1.15%     
- Complexity     8311     8651     +340     
============================================
  Files           683      687       +4     
  Lines         67325    67437     +112     
  Branches       7217     7225       +8     
============================================
+ Hits          26239    27063     +824     
+ Misses        38079    37349     -730     
- Partials       3007     3025      +18     
Flag Coverage Δ
unittests 40.13% <52.38%> (+1.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...sar/broker/service/persistent/PersistentTopic.java 60.90% <52.38%> (+3.92%) ⬆️

... and 71 files with indirect coverage changes

// 2. We want to kick out everyone and forcefully delete the topic.
// In this case, we shouldn't care if the usageCount is 0 or not, just proceed
if (currentUsageCount() == 0 || (closeIfClientsConnected && !failIfHasSubscriptions)) {
if (currentUsageCount() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems we need to keep the original condition (closeIfClientsConnected && !failIfHasSubscriptions))

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel the current code is correct. Because we have called disconnection operation before. If there are still any connections at the current time, it means that a new connection has come in, we should consider that there is a concurrency problem and give up deleting the topic.

Copy link
Contributor 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 @poorbarcode

The closeIfClientsConnected and failIfHasSubscriptions is validated before we reach here. It looks like duplicated validation.

// 2. We want to kick out everyone and forcefully delete the topic.
// In this case, we shouldn't care if the usageCount is 0 or not, just proceed
if (currentUsageCount() == 0 || (closeIfClientsConnected && !failIfHasSubscriptions)) {
if (currentUsageCount() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel the current code is correct. Because we have called disconnection operation before. If there are still any connections at the current time, it means that a new connection has come in, we should consider that there is a concurrency problem and give up deleting the topic.

Comment on lines 1182 to 1184
} else if (!closeIfClientsConnected && currentUsageCount() != 0 && !failIfHasBacklogs) {
return FutureUtil.failedFuture(new TopicBusyException(
"Topic has " + currentUsageCount() + " connected producers/consumers"));
Copy link
Contributor

Choose a reason for hiding this comment

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

It needs to fail as long as there are connections, so it has nothing to do with !failIfHasBacklogs.

Or if failIfHasBacklogs is triggered, the error message returned should not be like this

Copy link
Contributor

@poorbarcode poorbarcode Nov 2, 2022

Choose a reason for hiding this comment

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

Hi @315157973

When failIfHasBacklogs is true, the expected behavior is that:

  • failure of any producer exists
  • if any consumer exists, close connections

Actually, the code should be like this:

if ( !closeIfClientsConnected && currentUsageCount() ){
   fail...
} else if ( !closeIfClientsConnected !failIfHasBacklogs && anyProducerExists() ){
   fail...
}

This code may not be easy to understand from the context, but the logic is correct

Copy link
Contributor

Choose a reason for hiding this comment

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

There is also a concurrency problem that may lead to the incorrect deletion of existing producer topics. E.g:

checkGC new producer registry
ensure no producer exists
delete topic ( false, true, false)
ensure no backlog
new producer registry
fence topic
disconnect all clients
delete topic

The above flow shows the case: producer exists but the topic is deleted. Would it be better to add a double-check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@poorbarcode poorbarcode Nov 2, 2022

Choose a reason for hiding this comment

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

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

@codelipenghui codelipenghui merged commit 67d9d63 into apache:master Nov 3, 2022
@congbobo184
Copy link
Contributor

could you please cherry-pick this PR to branch-2.9? thanks.

@codelipenghui
Copy link
Contributor Author

codelipenghui commented Nov 16, 2022

#18320 has cherry-picked this one to branch-2.11

@codelipenghui
Copy link
Contributor Author

f5c9354 cherry-picked to branch-2.10

@codelipenghui codelipenghui added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Nov 16, 2022
@codelipenghui
Copy link
Contributor Author

3cf167a cherry-picked to branch-2.9

congbobo184 pushed a commit that referenced this pull request Nov 27, 2022
…ile have active consumers (#18283)

(cherry picked from commit 67d9d63)
@codelipenghui codelipenghui deleted the penghui/fix-subscription-catchup-deletion branch March 26, 2024 00:58
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.

8 participants