codelipenghui commented on code in PR #19201:
URL: https://github.com/apache/pulsar/pull/19201#discussion_r1090342351
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/TransactionMetadataStoreService.java:
##########
@@ -133,54 +133,66 @@ public CompletableFuture<Void>
handleTcClientConnect(TransactionCoordinatorID tc
return;
}
- 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;
- }
- }
-
- completableFuture.complete(null);
- tcLoadSemaphore.release();
- })).exceptionally(e -> {
- internalPinnedExecutor.execute(() -> {
-
completableFuture.completeExceptionally(e.getCause());
- // release before handle request queue,
- //in order to client reconnect
infinite loop
- tcLoadSemaphore.release();
- 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) {
- // this means that this tc
client connection connect fail
-
future.completeExceptionally(e);
- } else {
- break;
- }
+ TransactionTimeoutTracker timeoutTracker =
timeoutTrackerFactory.newTracker(tcId);
+ TransactionRecoverTracker recoverTracker =
+ new
TransactionRecoverTrackerImpl(TransactionMetadataStoreService.this,
+ timeoutTracker, tcId.getId());
+ openTransactionMetadataStore(tcId, timeoutTracker,
recoverTracker).thenAccept(
+ (store) -> internalPinnedExecutor.execute(()
-> {
+ // TransactionMetadataStore initialization
+ // need to use TransactionMetadataStore
itself.
+ // we need to put store into stores map
before
+ // handle committing and aborting
transaction.
+ stores.put(tcId, store);
+ LOG.info("Added new transaction meta store
{}", tcId);
+
recoverTracker.handleCommittingAndAbortingTransaction();
+
store.setRecoverEndTime(System.currentTimeMillis());
+
+ 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 {
- deque.clear();
break;
}
+ } else {
+ deque.clear();
+ break;
}
- LOG.error("Add transaction metadata
store with id {} error", tcId.getId(), e);
- });
- return null;
- });
+ }
+
+ completableFuture.complete(null);
+ tcLoadSemaphore.release();
+ })).exceptionally(e -> {
+ internalPinnedExecutor.execute(() -> {
+
completableFuture.completeExceptionally(e.getCause());
Review Comment:
nit: It looks like a code format issue?
##########
pulsar-transaction/coordinator/src/main/java/org/apache/pulsar/transaction/coordinator/TransactionMetadataStore.java:
##########
@@ -138,4 +138,10 @@ default long getLowWaterMark() {
* @return {@link TxnMeta} the txnMetas of slow transactions
*/
List<TxnMeta> getSlowTransactions(long timeout);
+
+ /**
+ * set recover end time.
+ * @param time
+ */
+ void setRecoverEndTime(long time);
Review Comment:
Sorry, forgot this one.
I think we don't need to add this one to the interface for now? Only the
MLTransactionMetadataStore has the recovery stage. We can just check if it's an
MLTransactionMetadataStore, then set the recover end time. Maybe it's not good
enough for now, we can try to refactor it in the future.
--
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]