Skip to content

[Broker] Fix race condition in BrokerService topic cache #9565

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

Merged

Conversation

lhotari
Copy link
Member

@lhotari lhotari commented Feb 11, 2021

Fixes #9564

Motivation

There's a concurrency bug in org.apache.pulsar.broker.service.BrokerService.getTopic method.
When the topic has been retried with createIfMissing=false, for example by getting the statistics, for the topic, the pending future for this call will be in the cache and it's result will be returned for the call which currently calls this method with createIfMissing=true.

Modifications

Address the race condition and if createIfMissing=true, retry calling getTopic when the current result is Optional.empty().

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Lgtm

@lhotari
Copy link
Member Author

lhotari commented Feb 11, 2021

/pulsarbot run-failure-checks

2 similar comments
@lhotari
Copy link
Member Author

lhotari commented Feb 11, 2021

/pulsarbot run-failure-checks

@lhotari
Copy link
Member Author

lhotari commented Feb 11, 2021

/pulsarbot run-failure-checks

@sijie sijie added area/broker release/2.7.1 type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages labels Feb 12, 2021
@sijie sijie added this to the 2.8.0 milestone Feb 12, 2021
@lhotari
Copy link
Member Author

lhotari commented Feb 12, 2021

/pulsarbot run-failure-checks

- remove timeout
- show thread info in log statement
  - add index of thread as part of thread's name
@merlimat merlimat merged commit cee6377 into apache:master Feb 12, 2021
@codelipenghui codelipenghui added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Feb 18, 2021
codelipenghui pushed a commit that referenced this pull request Feb 18, 2021
* Fix race condition in BrokerService topic cache

* Add test that reproduces the topic cache race condition

* Use logger for logging exception

* Address review comments

- remove timeout
- show thread info in log statement
  - add index of thread as part of thread's name

* Reset state before running BrokerServiceTests that check stats

(cherry picked from commit cee6377)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker cherry-picked/branch-2.7 Archived: 2.7 is end of life release/2.7.1 type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Broker] Topic auto-creation fails due to a race condition
6 participants