-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[improve] Refresh ns policy when deciding auto topic creation eligibility #19097
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
[improve] Refresh ns policy when deciding auto topic creation eligibility #19097
Conversation
|
@aymkhalil Please add the following content to your PR description and select a checkbox: |
eolivelli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you found a valid case in which we need to use "refresh" (sync()), but the current patch is using refresh too eagerly (probably)
I have left one comment, please check
| } | ||
|
|
||
| return pulsar.getPulsarResources().getNamespaceResources() | ||
| .getPoliciesAsync(topicName.getNamespaceObject(), true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that there maybe some case in which it is good to use the local version of the Policies object.
We need to use "refresh" only when we reach here from a HTTP API call,
I know that is looks pretty convoluted, but with this change in the current form we are going to use "refresh" (that is a heavyweight operation) probably in code paths that don't need it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I traced http vs binary protocol calls that invoke this code:
http calls:
- resetCursorOnPosition
- lookupTopic
- createSubscription
- grantPermissionsOnTopic
- getPartitionedMetadata
- Basically any method calling the AdminResource#getPartitionedTopicMetadataAsync with
checkAllowAutoCreationtrue
binary protocol calls:
- handlePartitionMetadataRequest
- handleSubscribe
- handleProducer
I isolated the calls with as minimum code changes as possible. Please evaluate the value of the change vs the introduced code branches.
PTAL.
| }); | ||
| } | ||
|
|
||
| public static CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadata( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not used anywhere, removed it to minimize the code paths we need to think about.
|
At first glance now the patch looks good, but I will review it more carefully next week |
|
The pr had no activity for 30 days, mark with Stale label. |
eolivelli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
dlg99
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I don't think this change alone can completely prevent the topic creation during ns deletion: one can sync the policy and get the latest one, then ns deletion starts, then we create a topic - there is no locking/distributed locking for these operations.
It might reduce frequency of the problem occurrence.
|
Have you considered the double-check: |
+1. If fact, any "read" based solution to achieve consistency will be best effort only. I don't see how it could be solved for good without conditional writes which are not well supported. For example, in ZK the setData API does not support something like "fail if any version exists" but also there will be need to coordinate updates because the metadata for policy and topic (managed ledger) are under different nodes. So, I couldn't find an easy way to do it that fits in the scope/purpose of this patch... |
I didn't explicitly, the approach was to trace all http calls that touches the ns policy (here) so we cover more cases, but not cases where this could add unnecessary overhead (hence the distinction between http vs binary calls). But you made me think, actually the automatic topic creation triggered by a producer is actually on the binary protocol path so I either have to make all Regarding the latter approach, any overhead concerns to refreshing the policy metadata before ANY attempt to call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern about the solution is that it will degrade performance significantly for any hot paths where there's Zookeeper sync calls. We don't have performance benchmarks as part of the Pulsar CI pipeline and the performance benchmark would have to be done separately.
This potential performance problem is already introduced by
pulsar/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/NamespaceResources.java
Line 330 in 11073fd
| return getPartitionedTopicMetadataAsync(tn, true) |
I guess that the original goal was to prevent new topics from being created while the namespace is being deleted?
I believe that we could find a solution where we could combine eventual consistency for performance and use a way to ensure strong consistency with the tradeoff of having some delays in reaching this consensus. My assumption is that requiring strong consistency at all times using Zookeeper's "sync" would be too slow. I could be wrong.
I'm not exactly sure of the details, but I was thinking that perhaps the part that needs to delete the namespace waits a period of time until the eventual consistent data can be considered to be eventually reached a certain state. A better approach would be to have an explicit way to ensure that all distributed state has been replicated, but with the current Metadata Store design, waiting for a period of time could be a reasonable solution.
I suggest that we don't proceed further in merging this PR before this potential performance issue is resolved.
It seems that Matteo's comment #18518 (comment) in the original PR that introduced the ZK sync wasn't fully addressed.
I consider isAllowAutoTopicCreationAsync to be on the hot path and therefore using ZK sync is not a proper solution unless we are fine with performance regressions.
|
After collecting feedback, I'm closing this PR for now bc:
So the idea would be to:
|
Continuation of #18518 and #17609 to ensure the ns policy deleted is in consistent state between brokers when performing and
isAllowAutoTopicCreationAsyncMotivation
Modifications
Leveraged the MetadataStore sync api to have a consistent view of the ns policy that will feed into the
isAllowAutoTopicCreationAsync.Verifying this change
This change is already covered by existing tests, such as (please describe tests).
This change added tests and can be verified as follows:
(example:)
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: aymkhalil#5