mattisonchao commented on a change in pull request #14940:
URL: https://github.com/apache/pulsar/pull/14940#discussion_r838300448
##########
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:
Hi @eolivelli
I changed the method to run in a single thread. Could you review it again?
After deep thinking, I think creating an executor that chooses thread by TC
id is better than running in a single thread. but I think I need to do it at
another PR to avoid making this PR more complex.
Let me know what you think! thanks~
--
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]