You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by eo...@apache.org on 2022/06/21 09:22:34 UTC
[pulsar] branch branch-2.10 updated: Transactions: fix race in TransactionMetaStoreHandler (#16147)
This is an automated email from the ASF dual-hosted git repository.
eolivelli pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.10 by this push:
new d3492ca36a1 Transactions: fix race in TransactionMetaStoreHandler (#16147)
d3492ca36a1 is described below
commit d3492ca36a18f1dc578011050c803280fe8ee006
Author: Enrico Olivelli <eo...@apache.org>
AuthorDate: Tue Jun 21 03:23:51 2022 +0200
Transactions: fix race in TransactionMetaStoreHandler (#16147)
### Motivation
Fixes #15375
the NPE happens because internalPinnedExecutor has not been assigned yet.
### Modifications
Refactor the constructor, in a way that "this" is not accessed from another thread while the constructor is not done yet.
(cherry picked from commit ec276da53231bc01eb44e9cdc106b5174915691f)
---
.../org/apache/pulsar/client/impl/TransactionMetaStoreHandler.java | 7 +++++--
.../client/impl/transaction/TransactionCoordinatorClientImpl.java | 2 ++
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/TransactionMetaStoreHandler.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/TransactionMetaStoreHandler.java
index 2b65b38f51f..db252e64791 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/TransactionMetaStoreHandler.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/TransactionMetaStoreHandler.java
@@ -105,9 +105,12 @@ public class TransactionMetaStoreHandler extends HandlerState
.create(),
this);
this.connectFuture = connectFuture;
- this.connectionHandler.grabCnx();
+ this.internalPinnedExecutor = pulsarClient.getInternalExecutorService();
this.timer = pulsarClient.timer();
- internalPinnedExecutor = pulsarClient.getInternalExecutorService();
+ }
+
+ public void start() {
+ this.connectionHandler.grabCnx();
}
@Override
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionCoordinatorClientImpl.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionCoordinatorClientImpl.java
index 432fc671071..0bd01ff8b35 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionCoordinatorClientImpl.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionCoordinatorClientImpl.java
@@ -93,6 +93,7 @@ public class TransactionCoordinatorClientImpl implements TransactionCoordinatorC
i, pulsarClient, getTCAssignTopicName(i), connectFuture);
handlers[i] = handler;
handlerMap.put(i, handler);
+ handler.start();
}
} else {
handlers = new TransactionMetaStoreHandler[1];
@@ -102,6 +103,7 @@ public class TransactionCoordinatorClientImpl implements TransactionCoordinatorC
getTCAssignTopicName(-1), connectFuture);
handlers[0] = handler;
handlerMap.put(0, handler);
+ handler.start();
}
STATE_UPDATER.set(TransactionCoordinatorClientImpl.this, State.READY);