[fix][broker] Prevent repeated consumer close on topic migration#26111
[fix][broker] Prevent repeated consumer close on topic migration#26111Denovo1998 wants to merge 2 commits into
Conversation
lhotari
left a comment
There was a problem hiding this comment.
It seems like the original logic before #26075 is incorrect. Consumer.topicMigrated should only get called by this code:
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
Lines 2017 to 2027 in 808133d
One possibility would be to add this method to Consumer so that it could be used in NonPersistentTopic.internalSubscribe instead of using checkAndApplyTopicMigrationAsync
public CompletableFuture<Boolean> checkTopicMigrationAsync() {
if (!subscription.isSubscriptionMigrated()) {
return CompletableFuture.completedFuture(false);
}
return AbstractTopic.getMigratedClusterUrlAsync(cnx.getBrokerService().getPulsar(), topicName)
.thenApply(clusterUrl -> {
return clusterUrl.isPresent();
});
}
@lhotari
|
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.handleSubscriberuns 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
TopicMigratedcommands.Modifications
Consumer.topicMigrated(...)idempotent for each consumer with an atomic once guard.TopicMigratedand disconnect the consumer.ServerCnxpost-subscribe check remains safe after an inline non-persistent redirect.NonPersistentTopic.internalSubscribealready redirected the consumer, verifying one redirect and balanced topic usage count.Verifying this change
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:checkstyleTestDoes this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes