BewareMyPower opened a new pull request, #24785: URL: https://github.com/apache/pulsar/pull/24785
### Motivation The topic loading timeout starts at `loadOrCreatePersistentTopic`: https://github.com/apache/pulsar/blob/46a76e98d6a6f2a86839d93467c5337bb205f851/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java#L1661-L1663 However, there could be two asynchronous tasks before that: 1. Check if the topic exists https://github.com/apache/pulsar/blob/46a76e98d6a6f2a86839d93467c5337bb205f851/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java#L1165 2. Get the topic policies (`__change_events` topic will be replayed) https://github.com/apache/pulsar/blob/46a76e98d6a6f2a86839d93467c5337bb205f851/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java#L1171 The 1st task should be okay in most time, but the 2nd task could be time-consuming and risky. I have seen when replaying `__change_events` topic was stuck in production env. If this case happens, there is no metric or log and it can be only aware from client side. P.S. as the comment shows, it actually does not make sense to execute the 2nd task here but I want to improve the topic loading process in other PRs. The topic loading metric (`pulsar_topic_load_times`) starts even later at `createPersistent0`: https://github.com/apache/pulsar/blob/46a76e98d6a6f2a86839d93467c5337bb205f851/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java#L1769 It does not even include the time when the topic loading is in `BrokerService#pendingTopicLoadingQueue`, which happens when the number of pending topic loading tasks exceeds the `maxConcurrentTopicLoadRequest` config. ### Modifications - Refactor `TopicLoadingContext` to add latency info and create this context from the beginning before `checkNonPartitionedTopicExists`, so the latency could include the time before `createPersistent0` - Log latency when the topic is loaded successfully or fails to load, specially, if the topic has been added to the pending queue due to `maxConcurrentTopicLoadRequest` limitation, log the pending time as well ### Verifying this change - [x] Make sure that the change passes the CI checks. Here are example outputs from `BrokerServiceTest.testConcurrentLoadTopicExceedLimitShouldNotBeAutoCreated` ``` Created topic persistent://prop/concurrentLoad/my-topic_0 - dedup is disabled (latency: 156 ms) Created topic persistent://prop/concurrentLoad/my-topic_1 - dedup is disabled (latency: 20 ms) Created topic persistent://prop/concurrentLoad/my-topic_2 - dedup is disabled (latency: 20 ms) Created topic persistent://prop/concurrentLoad/my-topic_0 - dedup is disabled (latency: 4 ms) Created topic persistent://prop/concurrentLoad/my-topic_1 - dedup is disabled (latency: 7 ms (queued: 3)) Created topic persistent://prop/concurrentLoad/my-topic_2 - dedup is disabled (latency: 12 ms (queued: 7)) ``` `queued` means how long it stays in `pendingTopicLoadingQueue`. ### Does this pull request potentially affect one of the following parts: <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. --> *If the box was checked, please highlight the changes* - [ ] Dependencies (add or upgrade a dependency) - [ ] The public API - [ ] The schema - [ ] The default values of configurations - [ ] The threading model - [ ] The binary protocol - [ ] The REST endpoints - [ ] The admin CLI options - [x] The metrics - [ ] Anything that affects deployment ### Documentation <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. --> - [ ] `doc` <!-- Your PR contains doc changes. --> - [ ] `doc-required` <!-- Your PR changes impact docs and you will update later --> - [x] `doc-not-needed` <!-- Your PR changes do not impact docs --> - [ ] `doc-complete` <!-- Docs have been already added --> ### Matching PR in forked repository PR in forked repository: <!-- ENTER URL HERE --> <!-- After opening this PR, the build in apache/pulsar will fail and instructions will be provided for opening a PR in the PR author's forked repository. apache/pulsar pull requests should be first tested in your own fork since the apache/pulsar CI based on GitHub Actions has constrained resources and quota. GitHub Actions provides separate quota for pull requests that are executed in a forked repository. The tests will be run in the forked repository until all PR review comments have been handled, the tests pass and the PR is approved by a reviewer. --> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
