mattisonchao commented on a change in pull request #14940:
URL: https://github.com/apache/pulsar/pull/14940#discussion_r838265065



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/TransactionMetadataStoreService.java
##########
@@ -163,86 +165,63 @@ public boolean test(NamespaceBundle namespaceBundle) {
     }
 
     public CompletableFuture<Void> 
handleTcClientConnect(TransactionCoordinatorID tcId) {
-        CompletableFuture<Void> completableFuture = new CompletableFuture<>();
-        internalPinnedExecutor.execute(() -> {
-            if (stores.get(tcId) != null) {
-                completableFuture.complete(null);
-            } else {
-                
pulsarService.getBrokerService().checkTopicNsOwnership(TopicName
-                        .TRANSACTION_COORDINATOR_ASSIGN.getPartition((int) 
tcId.getId()).toString())
-                        .thenRun(() -> internalPinnedExecutor.execute(() -> {
-                    final Semaphore tcLoadSemaphore = this.tcLoadSemaphores
-                            .computeIfAbsent(tcId.getId(), (id) -> new 
Semaphore(1));
-                    Deque<CompletableFuture<Void>> deque = 
pendingConnectRequests
-                            .computeIfAbsent(tcId.getId(), (id) -> new 
ConcurrentLinkedDeque<>());
-                    if (tcLoadSemaphore.tryAcquire()) {
-                        // when tcLoadSemaphore.release(), this command will 
acquire semaphore,
-                        // so we should jude the store exist again.
-                        if (stores.get(tcId) != null) {
-                            completableFuture.complete(null);
-                        }
-
-                        openTransactionMetadataStore(tcId).thenAccept((store) 
-> internalPinnedExecutor.execute(() -> {
-                            stores.put(tcId, store);
-                            LOG.info("Added new transaction meta store {}", 
tcId);
-                            long endTime = System.currentTimeMillis() + 
HANDLE_PENDING_CONNECT_TIME_OUT;
-                            while (true) {
-                                // prevent thread in a busy loop.
-                                if (System.currentTimeMillis() < endTime) {
-                                    CompletableFuture<Void> future = 
deque.poll();
-                                    if (future != null) {
-                                        // complete queue request future
-                                        future.complete(null);
-                                    } else {
-                                        break;
-                                    }
-                                } else {
-                                    deque.clear();
-                                    break;
+        if (stores.get(tcId) != null) {

Review comment:
       Well, The second ``stores.get(tcId) != null`` check will ensure 
thread-safe.
   but looks make the first check move to ``pinner executor`` will be better.




-- 
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]


Reply via email to