Skip to content

[fix] [broker] Fix thousands orphan PersistentTopic caused OOM - #21540

Merged
Technoboy- merged 8 commits into
apache:masterfrom
poorbarcode:fix/orphan_topics
Nov 11, 2023
Merged

Technoboy- merged 8 commits into
apache:masterfrom
poorbarcode:fix/orphan_topics

Conversation

@poorbarcode

Copy link
Copy Markdown
Contributor

Motivation

In the current implementation, the Broker just removes topicFuture from the mapping BrokerService.topics and never closes it[1].

The orphan topics will be depended on by SystemTopicBasedTopicPoliciesService.listeners, which is for notice of topic policy changes. This issue would cause OOM[2].

[1]: https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java#L1725-L1748

...
    persistentTopic.stopReplProducers().whenCompleteAsync((v, exception) -> {
        topics.remove(topic, topicFuture);
    }, executor());
}).exceptionally((ex) -> {
    ...
    persistentTopic.stopReplProducers().whenCompleteAsync((v, exception) -> {
        topics.remove(topic, topicFuture);
        topicFuture.completeExceptionally(ex);
    }, executor());
    ...
});

[2]: Thousands of orphan PersistentTopics
Screenshot 2023-11-08 at 00 54 24

Modifications

  • close the PersistentTopic if creating failed due to timeout.
  • close the PersistentTopic if initialize failed.

Documentation

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

Matching PR in forked repository

PR in forked repository: x

@poorbarcode poorbarcode changed the title [fix] [broker] Fix orphan PersistentTopic after create error [fix] [broker] Fix thousands orphan PersistentTopic caused OOM Nov 7, 2023
@poorbarcode poorbarcode self-assigned this Nov 7, 2023
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Nov 7, 2023
@poorbarcode poorbarcode added this to the 3.2.0 milestone Nov 7, 2023
@poorbarcode poorbarcode added release/2.10.6 release/3.0.3 release/2.11.4 type/bug The PR fixed a bug or issue reported a bug labels Nov 7, 2023
persistentTopic.stopReplProducers()
.whenCompleteAsync((v, exception) -> {
topics.remove(topic, topicFuture);
persistentTopic.close();

@mattisonchao mattisonchao Nov 8, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aha, I wanted to fix it there before.

If you chose the topic close method. You don't need the following codes. Because topic#close already does it.

 persistentTopic.getTransactionBuffer()
              .closeAsync()
              .exceptionally(t -> {
                  log.error("[{}] Close transactionBuffer failed", topic, t);
                  return null;
               });
       persistentTopic.stopReplProducers()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Plus, please give good log information if the closing operation has errors. :)

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.

@mattisonchao

Aha, I wanted to fix it there before.

Yes, it is #21445

If you chose the topic close method. You don't need the following codes. Because topic#close already does it.
Plus, please give good log information if the closing operation has errors. :)

Sure, fixed.

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good work!

@lhotari

lhotari commented Nov 8, 2023

Copy link
Copy Markdown
Member

/pulsarbot rerun-failure-checks

@poorbarcode poorbarcode added the category/reliability The function does not work properly in certain specific environments or failures. e.g. data lost label Nov 8, 2023

@codelipenghui codelipenghui 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.

Nice catch!

@codecov-commenter

codecov-commenter commented Nov 11, 2023 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.26%. Comparing base (44abba9) to head (de15242).
⚠️ Report is 1777 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #21540      +/-   ##
============================================
- Coverage     73.27%   73.26%   -0.01%     
- Complexity    32676    32689      +13     
============================================
  Files          1892     1892              
  Lines        140632   140710      +78     
  Branches      15467    15480      +13     
============================================
+ Hits         103044   103090      +46     
- Misses        29497    29521      +24     
- Partials       8091     8099       +8     
Flag Coverage Δ
inttests 24.17% <100.00%> (-0.18%) ⬇️
systests 24.76% <83.33%> (-0.22%) ⬇️
unittests 72.53% <100.00%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
...rg/apache/pulsar/broker/service/BrokerService.java 81.09% <100.00%> (+0.10%) ⬆️

... and 95 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

nborisov pushed a commit to nborisov/pulsar that referenced this pull request Nov 13, 2023
poorbarcode added a commit that referenced this pull request Dec 13, 2023
poorbarcode added a commit that referenced this pull request Dec 13, 2023
nodece pushed a commit to nodece/pulsar that referenced this pull request Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category/reliability The function does not work properly in certain specific environments or failures. e.g. data lost cherry-picked/branch-2.10 cherry-picked/branch-2.11 cherry-picked/branch-3.0 cherry-picked/branch-3.1 doc-not-needed Your PR changes do not impact docs release/2.10.6 release/2.11.3 release/3.0.2 release/3.1.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.

7 participants