lhotari commented on code in PR #17524:
URL: https://github.com/apache/pulsar/pull/17524#discussion_r1448536989
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java:
##########
@@ -272,6 +273,46 @@ protected TopicStatsHelper initialValue() {
private CompletableFuture<Void> closeWithoutWaitingClientFuture;
+ private volatile CloseFutures closeFutures;
+
+ /***
+ * We use 3 futures to prevent a new closing if there is an in-progress
deletion or closing. We make Pulsar return
+ * the in-progress one when it is called the second time.
+ *
+ * The topic closing will be called the below scenarios:
+ * 1. Calling "pulsar-admin topics unload". Relate to {@link
CloseFutures#waitDisconnectClients}.
+ * 2. Namespace bundle transfer or unloading.
+ * a. The unloading topic triggered by unloading namespace bundles will
not wait for clients disconnect. Relate
+ * to {@link CloseFutures#notWaitDisconnectClients}.
+ * b. The unloading topic triggered by unloading namespace bundles was
seperated to two steps when using
+ * {@link ExtensibleLoadManagerImpl}.
+ * b-1. step-1: fence the topic on the original Broker, and do not
trigger reconnections of clients. Relate
+ * to {@link CloseFutures#notDisconnectClients}. This step is a half
closing.
+ * b-2. step-2: send the owner broker information to clients and
disconnect clients. Relate
+ * to {@link CloseFutures#notWaitDisconnectClients}.
+ *
+ * The three futures will be setting as the below rule:
+ * Event: Topic close.
+ * - If the first one closing is called by "close and not disconnect
clients":
+ * - {@link CloseFutures#notDisconnectClients} will be initialized as
"close and not disconnect clients".
+ * - {@link CloseFutures#waitDisconnectClients} ang {@link
CloseFutures#notWaitDisconnectClients} will be empty,
+ * the second closing will do a new close after {@link
CloseFutures#notDisconnectClients} is completed.
+ * - If the first one closing is called by "close and not wait for clients
disconnect":
+ * - {@link CloseFutures#waitDisconnectClients} will be initialized as
"waiting for clients disconnect".
+ * - {@link CloseFutures#notWaitDisconnectClients} ang {@link
CloseFutures#notDisconnectClients} will be
+ * initialized as "not waiting for clients disconnect" .
+ * - If the first one closing is called by "close and wait for clients
disconnect", the three futures will be
+ * initialized as "waiting for clients disconnect".
+ * Event: Topic delete.
+ * the three futures will be initialized as "waiting for clients
disconnect".
+ */
+ @AllArgsConstructor
+ private class CloseFutures {
Review Comment:
please also add `@Value` to make the fields `final`. That will help ensure
thread safety.
--
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]