Denovo1998 opened a new pull request, #26111: URL: https://github.com/apache/pulsar/pull/26111
### Motivation PR #26075 fixed the non-persistent topic subscribe race by redirecting a migrated consumer before adding it to the subscription. However, that path still completes the subscribe future with the same consumer, and `ServerCnx.handleSubscribe` runs the generic post-subscribe migration check again. That second check can redirect and disconnect the same consumer a second time. For non-persistent topics this can double-decrement the topic usage count and emit duplicate `TopicMigrated` commands. ### Modifications - Make `Consumer.topicMigrated(...)` idempotent for each consumer with an atomic once guard. - Keep the first migration handling unchanged: send `TopicMigrated` and disconnect the consumer. - Ignore repeated migration handling for the same consumer so the `ServerCnx` post-subscribe check remains safe after an inline non-persistent redirect. - Add a regression test that simulates the post-subscribe migration check after `NonPersistentTopic.internalSubscribe` already redirected the consumer, verifying one redirect and balanced topic usage count. ### Verifying this change - [x] Make sure that the change passes the CI checks. - `./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopicTest.testPostSubscribeMigrationCheckDoesNotDoubleCloseRedirectedConsumer` - `./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopicTest.testSubscribeOnMigratedTopicSkipsAddingConsumer --tests org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopicTest.testPostSubscribeMigrationCheckDoesNotDoubleCloseRedirectedConsumer` - `./gradlew :pulsar-broker:checkstyleMain :pulsar-broker:checkstyleTest` ### 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 - [ ] The metrics - [ ] Anything that affects deployment -- 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]
