@@ -115,7 +115,7 @@ public CompletableFuture<TransactionMetadataStore> init(TransactionRecoverTracke
115
115
+ tcID .toString () + " change state to Initializing error when init it" ));
116
116
} else {
117
117
recoverTime .setRecoverStartTime (System .currentTimeMillis ());
118
- internalPinnedExecutor . execute (() -> transactionLog .replayAsync (new TransactionLogReplayCallback () {
118
+ FutureUtil . safeRunAsync (() -> transactionLog .replayAsync (new TransactionLogReplayCallback () {
119
119
@ Override
120
120
public void replayComplete () {
121
121
recoverTracker .appendOpenTransactionToTimeoutTracker ();
@@ -203,7 +203,7 @@ public void handleMetadataEntry(Position position, TransactionMetadataEntry tran
203
203
log .error (e .getMessage (), e );
204
204
}
205
205
}
206
- }));
206
+ }), internalPinnedExecutor , completableFuture );
207
207
}
208
208
return completableFuture ;
209
209
}
@@ -227,60 +227,59 @@ public CompletableFuture<TxnMeta> getTxnMeta(TxnID txnID) {
227
227
228
228
@ Override
229
229
public CompletableFuture <TxnID > newTransaction (long timeOut ) {
230
- if (this .maxActiveTransactionsPerCoordinator == 0
231
- || this .maxActiveTransactionsPerCoordinator > txnMetaMap .size ()) {
232
- CompletableFuture <TxnID > completableFuture = new CompletableFuture <>();
233
- internalPinnedExecutor .execute (() -> {
234
- if (!checkIfReady ()) {
235
- completableFuture .completeExceptionally (new CoordinatorException
236
- .TransactionMetadataStoreStateException (tcID , State .Ready , getState (), "new Transaction" ));
237
- return ;
238
- }
239
-
240
- long mostSigBits = tcID .getId ();
241
- long leastSigBits = sequenceIdGenerator .generateSequenceId ();
242
- TxnID txnID = new TxnID (mostSigBits , leastSigBits );
243
- long currentTimeMillis = System .currentTimeMillis ();
244
- TransactionMetadataEntry transactionMetadataEntry = new TransactionMetadataEntry ()
245
- .setTxnidMostBits (mostSigBits )
246
- .setTxnidLeastBits (leastSigBits )
247
- .setStartTime (currentTimeMillis )
248
- .setTimeoutMs (timeOut )
249
- .setMetadataOp (TransactionMetadataEntry .TransactionMetadataOp .NEW )
250
- .setLastModificationTime (currentTimeMillis )
251
- .setMaxLocalTxnId (sequenceIdGenerator .getCurrentSequenceId ());
252
- transactionLog .append (transactionMetadataEntry )
253
- .whenComplete ((position , throwable ) -> {
254
- if (throwable != null ) {
255
- completableFuture .completeExceptionally (throwable );
256
- } else {
257
- appendLogCount .increment ();
258
- TxnMeta txn = new TxnMetaImpl (txnID , currentTimeMillis , timeOut );
259
- List <Position > positions = new ArrayList <>();
260
- positions .add (position );
261
- Pair <TxnMeta , List <Position >> pair = MutablePair .of (txn , positions );
262
- txnMetaMap .put (leastSigBits , pair );
263
- this .timeoutTracker .addTransaction (leastSigBits , timeOut );
264
- createdTransactionCount .increment ();
265
- completableFuture .complete (txnID );
266
- }
267
- });
268
- });
269
- return completableFuture ;
270
- } else {
230
+ if (this .maxActiveTransactionsPerCoordinator != 0
231
+ && this .maxActiveTransactionsPerCoordinator <= txnMetaMap .size ()) {
271
232
return FutureUtil .failedFuture (new CoordinatorException .ReachMaxActiveTxnException ("New txn op "
272
233
+ "reach max active txn! tcId : " + getTransactionCoordinatorID ().getId ()));
273
234
}
235
+ CompletableFuture <TxnID > completableFuture = new CompletableFuture <>();
236
+ FutureUtil .safeRunAsync (() -> {
237
+ if (!checkIfReady ()) {
238
+ completableFuture .completeExceptionally (new CoordinatorException
239
+ .TransactionMetadataStoreStateException (tcID , State .Ready , getState (), "new Transaction" ));
240
+ return ;
241
+ }
242
+
243
+ long mostSigBits = tcID .getId ();
244
+ long leastSigBits = sequenceIdGenerator .generateSequenceId ();
245
+ TxnID txnID = new TxnID (mostSigBits , leastSigBits );
246
+ long currentTimeMillis = System .currentTimeMillis ();
247
+ TransactionMetadataEntry transactionMetadataEntry = new TransactionMetadataEntry ()
248
+ .setTxnidMostBits (mostSigBits )
249
+ .setTxnidLeastBits (leastSigBits )
250
+ .setStartTime (currentTimeMillis )
251
+ .setTimeoutMs (timeOut )
252
+ .setMetadataOp (TransactionMetadataEntry .TransactionMetadataOp .NEW )
253
+ .setLastModificationTime (currentTimeMillis )
254
+ .setMaxLocalTxnId (sequenceIdGenerator .getCurrentSequenceId ());
255
+ transactionLog .append (transactionMetadataEntry )
256
+ .whenComplete ((position , throwable ) -> {
257
+ if (throwable != null ) {
258
+ completableFuture .completeExceptionally (throwable );
259
+ } else {
260
+ appendLogCount .increment ();
261
+ TxnMeta txn = new TxnMetaImpl (txnID , currentTimeMillis , timeOut );
262
+ List <Position > positions = new ArrayList <>();
263
+ positions .add (position );
264
+ Pair <TxnMeta , List <Position >> pair = MutablePair .of (txn , positions );
265
+ txnMetaMap .put (leastSigBits , pair );
266
+ this .timeoutTracker .addTransaction (leastSigBits , timeOut );
267
+ createdTransactionCount .increment ();
268
+ completableFuture .complete (txnID );
269
+ }
270
+ });
271
+ }, internalPinnedExecutor , completableFuture );
272
+ return completableFuture ;
274
273
}
275
274
276
275
@ Override
277
276
public CompletableFuture <Void > addProducedPartitionToTxn (TxnID txnID , List <String > partitions ) {
278
277
CompletableFuture <Void > promise = new CompletableFuture <>();
279
- internalPinnedExecutor . execute (() -> {
278
+ FutureUtil . safeRunAsync (() -> {
280
279
if (!checkIfReady ()) {
281
280
promise
282
281
.completeExceptionally (new CoordinatorException .TransactionMetadataStoreStateException (tcID ,
283
- State .Ready , getState (), "add produced partition" ));
282
+ State .Ready , getState (), "add produced partition" ));
284
283
return ;
285
284
}
286
285
getTxnPositionPair (txnID ).thenCompose (txnMetaListPair -> {
@@ -313,15 +312,15 @@ public CompletableFuture<Void> addProducedPartitionToTxn(TxnID txnID, List<Strin
313
312
promise .completeExceptionally (ex );
314
313
return null ;
315
314
});
316
- });
315
+ }, internalPinnedExecutor , promise );
317
316
return promise ;
318
317
}
319
318
320
319
@ Override
321
320
public CompletableFuture <Void > addAckedPartitionToTxn (TxnID txnID ,
322
321
List <TransactionSubscription > txnSubscriptions ) {
323
322
CompletableFuture <Void > promise = new CompletableFuture <>();
324
- internalPinnedExecutor . execute (() -> {
323
+ FutureUtil . safeRunAsync (() -> {
325
324
if (!checkIfReady ()) {
326
325
promise .completeExceptionally (new CoordinatorException
327
326
.TransactionMetadataStoreStateException (tcID , State .Ready , getState (), "add acked partition" ));
@@ -357,15 +356,15 @@ public CompletableFuture<Void> addAckedPartitionToTxn(TxnID txnID,
357
356
promise .completeExceptionally (ex );
358
357
return null ;
359
358
});
360
- });
359
+ }, internalPinnedExecutor , promise );
361
360
return promise ;
362
361
}
363
362
364
363
@ Override
365
364
public CompletableFuture <Void > updateTxnStatus (TxnID txnID , TxnStatus newStatus ,
366
365
TxnStatus expectedStatus , boolean isTimeout ) {
367
366
CompletableFuture <Void > promise = new CompletableFuture <>();
368
- internalPinnedExecutor . execute (() -> {
367
+ FutureUtil . safeRunAsync (() -> {
369
368
if (!checkIfReady ()) {
370
369
promise .completeExceptionally (new CoordinatorException
371
370
.TransactionMetadataStoreStateException (tcID ,
@@ -426,7 +425,7 @@ public CompletableFuture<Void> updateTxnStatus(TxnID txnID, TxnStatus newStatus,
426
425
promise .completeExceptionally (ex );
427
426
return null ;
428
427
});
429
- });
428
+ }, internalPinnedExecutor , promise );
430
429
return promise ;
431
430
}
432
431
0 commit comments