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

Avoid potentially blocking calls to metadata on critical threads #12339

Merged
merged 6 commits into from
Oct 14, 2021

Conversation

merlimat
Copy link
Contributor

Motivation

We have several places that are accessing the namespace policies in a synchronous way from the critical IO threads of the broker. These accesses are almost always non-blocking calls since the policies are already cached (given that the topic was just loaded and the policies were checked then).

There are few corner cases though in which we would incur in cache misses and that could have a big impact, up to result in a complete deadlock, if we exhaust all the threads in the ordered executors.

For example this can happen when there are thousands of producers/consumers connecting and there is a change in the policies that triggers a cache invalidation.

We must have no potentially blocking calls in the critical path.

@merlimat merlimat added the type/bug The PR fixed a bug or issue reported a bug label Oct 12, 2021
@merlimat merlimat added this to the 2.10.0 milestone Oct 12, 2021
@merlimat merlimat self-assigned this Oct 12, 2021
Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

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

Looks good. Left some minor comments.

@codelipenghui
Copy link
Contributor

@michaeljmarshall Please help review again

Copy link
Contributor

@hangc0276 hangc0276 left a comment

Choose a reason for hiding this comment

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

Great Job!

merlimat added a commit to streamnative/pulsar-archived that referenced this pull request Oct 13, 2021
merlimat added a commit that referenced this pull request Oct 13, 2021
… threads (#12339) (#12340)

* Avoid potentially blocking calls to metadata on critical threads (#12339)

* Fixed NPE

* Addressed comments

* Fixed issue with mocked tests

* Fixed behavior in BacklogQuotaManager to be like before

* Fixed AuthorizationProducerConsumerTest

* Fixed PersistentTopicTest

* Fixed PersistentTopicTest
@eolivelli eolivelli modified the milestones: 2.10.0, 2.9.0 Oct 13, 2021
Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

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

LGTM. Left one question about exception handling.

Comment on lines 785 to 787
policies = brokerService.pulsar().getPulsarResources().getNamespaceResources().getPoliciesIfCached(
TopicName.get(topic).getNamespaceObject())
.orElseGet(() -> new Policies());
Copy link
Member

Choose a reason for hiding this comment

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

I see this was added in the most recent commit to help with a mocked test. This block doesn't throw any checked exceptions. Do we expect RuntimeExceptions from it? If we do, should we wrap other similar code blocks in this PR with try and catch? If we don't, perhaps we should update the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Many tests are using mocked versions which would throw exception... then the try/catch was the thing that was making all these tests to work..

@merlimat merlimat merged commit da27b9e into apache:master Oct 14, 2021
@merlimat merlimat deleted the blocking-calls branch October 14, 2021 19:33
merlimat added a commit that referenced this pull request Oct 14, 2021
)

* Avoid potentially blocking calls to metadata on critical threads

* Fixed log arguments order

* Addressed comments

* Fixed mock in PersistentSubscriptionTest

* Fixed issue in mocked tests

* Fixed test that was force policies modification under the hood
merlimat added a commit that referenced this pull request Oct 15, 2021
)

* Avoid potentially blocking calls to metadata on critical threads

* Fixed log arguments order

* Addressed comments

* Fixed mock in PersistentSubscriptionTest

* Fixed issue in mocked tests

* Fixed test that was force policies modification under the hood
@hangc0276 hangc0276 added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Oct 17, 2021
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Oct 27, 2021
…che#12339)

* Avoid potentially blocking calls to metadata on critical threads

* Fixed log arguments order

* Addressed comments

* Fixed mock in PersistentSubscriptionTest

* Fixed issue in mocked tests

* Fixed test that was force policies modification under the hood

(cherry picked from commit c0e87c0)
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
…che#12339)

* Avoid potentially blocking calls to metadata on critical threads

* Fixed log arguments order

* Addressed comments

* Fixed mock in PersistentSubscriptionTest

* Fixed issue in mocked tests

* Fixed test that was force policies modification under the hood
Jason918 pushed a commit to Jason918/pulsar that referenced this pull request Jul 31, 2022
…ause org.apache.pulsar.broker.admin.AdminApiTest#testTopicStatsLastExpireTimestampForSubscription failing.
Jason918 pushed a commit to Jason918/pulsar that referenced this pull request Jul 31, 2022
Jason918 added a commit that referenced this pull request Jul 31, 2022
* Revert "[fix][proxy] Fix client service url (#16834)"

This reverts commit 10b4e99.

* Revert "[Build] Use grpc-bom to align grpc library versions (#15234)"

This reverts commit 99c93d2.

* Revert "upgrade aircompressor to 0.20 (#11790)"

This reverts commit 5ad16b6.

* Revert "[Branch-2.7] Fixed deadlock on metadata cache missing while doing checkReplication (#12484)"

This reverts commit 32fe228.

* Revert changes of PersistentTopic#getMessageTTL in #12339.

Co-authored-by: JiangHaiting <janghaiting@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.8 Archived: 2.8 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.2 release/2.9.0 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.

None yet

6 participants