Repository navigation
Conversation
lhotari
left a comment
There was a problem hiding this comment.
LGTM. Thanks for tracking down the namespace-scan cost and for keeping the backport scoped to the existence check rather than the whole of #24225.
I compared the new path with the old one for the cases that matter: non-persistent topics already went through NamespaceService.checkTopicExistsAsync, so nothing changes there; missing topics still get the same 404 and message; partitioned topics are covered by the metadata lookup; system topics are not filtered by either path; and the TopicExistsInfo is recycled. The ordering of the existence check, the partitioned-metadata lookup and the ownership validation is unchanged and nothing blocks. This also matches what master does in preValidation today. The regression test fails when the production change is reverted and passes with it.
One non-blocking observation is in the inline comment about an edge case where partition ledgers exist without metadata.
| .thenCompose(exist -> { | ||
| if (!exist) { | ||
| throw new RestException(Status.NOT_FOUND, getTopicNotFoundErrorMessage(topicName.toString())); | ||
| .thenCompose(__ -> internalCheckTopicExists(topicName)) |
There was a problem hiding this comment.
[QUALITY] A base topic whose only trace is orphan partition ledgers now gets 404 from topic-policy calls
Non-blocking: the old AdminResource.checkTopicExistsAsync list scan treated t as existing when any listed topic normalized to t (for example a t-partition-0 managed ledger) even without partitioned metadata for t. NamespaceService.checkTopicExistsAsync instead looks at the partitioned metadata and then at the managed-ledger node of t itself. If the metadata was lost but the partition ledgers remain, policy get/set for t used to pass the existence check and now returns 404 Topic ... not found.
This is the same behaviour master has, and that state is already broken for most other operations, so I think it is acceptable. It would be worth a line in the PR description, since it says the 404 behaviour is preserved.
codelipenghui
left a comment
There was a problem hiding this comment.
Code Review approval for commit 8e9bec2.
Summary:
No actionable findings identified within the reviewed scope.
The narrow backport removes namespace scans while preserving normal validation, authorization and ownership behavior, with correct TopicExistsInfo recycling. Recommend approval based on source review, noting the orphan-partition compatibility caveat. Local validation did not reach any selected tests.
…g in topic policy validation #27372 made the topic policy validation check the topic existence with NamespaceService#checkTopicExistsAsync, which on branch-4.0 doesn't treat the topics of the heartbeat namespace as existing like it does since #24225. PartitionedSystemTopicTest.testHeartbeatTopicNotAllowedToSendEvent then gets a 404 instead of the 409 with which the topic policies service refuses the policy updates of heartbeat namespace topics.
Motivation
On
branch-4.0, every persistent-topic policy operation runsPersistentTopicsBase.preValidation, which callscheckTopicExistsAsync. For persistent topics, that method lists every topic in the namespace and normalizes every topic name before answering a single-topic existence question.This makes each policy request O(number of topics in the namespace). The cost is amplified when a control-plane inventory reads policies for many topics concurrently.
We reproduced the issue with an inventory of 3,956 topics and policy concurrency 20. On Pulsar 4.0, one Broker received 4,929 policy requests across 451 topics in five minutes, and the repeated namespace scans drove all Broker web workers and Brokers to an 88-100% CPU plateau. With the same inventory on Pulsar 4.2, where the direct existence-check path from #24225 is present, the saturation pattern disappeared: the maximum sampled Broker CPU was 74.2%, and the inventory completed 17.3% faster.
The complete #24225 change also modifies partitioned-topic recreation semantics. This PR intentionally backports only the safe existence-check optimization needed by topic-policy validation.
Modifications
internalCheckTopicExists, which usesNamespaceService.checkTopicExistsAsyncfor a direct metadata/resource existence check and recycles the returnedTopicExistsInfo.branch-4.0.Verifying this change
This change added tests and can be verified as follows:
./mvnw -pl pulsar-broker -Dtest=TopicPoliciesTest#testTopicPolicyValidationDoesNotListNamespaceTopics test./mvnw -pl pulsar-broker -Dtest=TopicPoliciesTest#testNonPersistentTopicAppliesTopicPolicyOnLoad test./mvnw -pl pulsar-broker -DskipTests install(includes compilation and Checkstyle)Does this pull request potentially affect one of the following parts:
The implementation of topic-policy REST endpoint pre-validation changes, but its API and response semantics are preserved.