@@ -194,13 +194,11 @@ public class TransactionManager {
194
194
private volatile boolean transactionStarted = false ;
195
195
private volatile boolean clientSideEpochBumpRequired = false ;
196
196
private volatile long latestFinalizedFeaturesEpoch = -1 ;
197
- private volatile boolean isUpgradingToV2 = false ;
198
197
private volatile boolean isTransactionV2Enabled = false ;
199
198
200
199
private enum State {
201
200
UNINITIALIZED ,
202
201
INITIALIZING ,
203
- UPGRADING ,
204
202
READY ,
205
203
IN_TRANSACTION ,
206
204
COMMITTING_TRANSACTION ,
@@ -213,11 +211,9 @@ private boolean isTransitionValid(State source, State target) {
213
211
case UNINITIALIZED :
214
212
return source == READY || source == ABORTABLE_ERROR ;
215
213
case INITIALIZING :
216
- return source == UNINITIALIZED || source == ABORTING_TRANSACTION ;
217
- case UPGRADING :
218
- return source == ABORTING_TRANSACTION || source == COMMITTING_TRANSACTION ;
214
+ return source == UNINITIALIZED || source == ABORTING_TRANSACTION || source == COMMITTING_TRANSACTION ;
219
215
case READY :
220
- return source == INITIALIZING || source == COMMITTING_TRANSACTION || source == ABORTING_TRANSACTION || source == UPGRADING ;
216
+ return source == INITIALIZING || source == COMMITTING_TRANSACTION || source == ABORTING_TRANSACTION ;
221
217
case IN_TRANSACTION :
222
218
return source == READY ;
223
219
case COMMITTING_TRANSACTION :
@@ -351,13 +347,16 @@ private TransactionalRequestResult beginCompletingTransaction(TransactionResult
351
347
isTransactionV2Enabled
352
348
);
353
349
350
+ // Maybe update the transaction version here before we enqueue the EndTxn request so there are no races with
351
+ // completion of the EndTxn request.
352
+ maybeUpdateTransactionV2Enabled (false );
353
+
354
354
EndTxnHandler handler = new EndTxnHandler (builder );
355
355
enqueueRequest (handler );
356
356
357
357
// If an epoch bump is required for recovery, initialize the transaction after completing the EndTxn request.
358
358
// If we are upgrading to TV2 transactions on the next transaction, also bump the epoch.
359
- maybeUpdateTransactionV2Enabled (false );
360
- if (clientSideEpochBumpRequired || isUpgradingToV2 ) {
359
+ if (clientSideEpochBumpRequired ) {
361
360
return initializeTransactions (this .producerIdAndEpoch );
362
361
}
363
362
@@ -456,7 +455,7 @@ public synchronized void maybeUpdateTransactionV2Enabled(boolean onInitiatializa
456
455
Short transactionVersion = info .finalizedFeatures .get ("transaction.version" );
457
456
boolean wasTransactionV2Enabled = isTransactionV2Enabled ;
458
457
isTransactionV2Enabled = transactionVersion != null && transactionVersion >= 2 ;
459
- isUpgradingToV2 = !onInitiatialization && !wasTransactionV2Enabled && isTransactionV2Enabled ;
458
+ clientSideEpochBumpRequired = !onInitiatialization && !wasTransactionV2Enabled && isTransactionV2Enabled ;
460
459
}
461
460
462
461
public boolean isTransactionV2Enabled () {
@@ -1254,14 +1253,11 @@ boolean canHandleAbortableError() {
1254
1253
private void completeTransaction () {
1255
1254
if (clientSideEpochBumpRequired ) {
1256
1255
transitionTo (State .INITIALIZING );
1257
- } else if (isUpgradingToV2 ) {
1258
- transitionTo (State .UPGRADING );
1259
1256
} else {
1260
1257
transitionTo (State .READY );
1261
1258
}
1262
1259
lastError = null ;
1263
1260
clientSideEpochBumpRequired = false ;
1264
- isUpgradingToV2 = false ;
1265
1261
transactionStarted = false ;
1266
1262
newPartitionsInTransaction .clear ();
1267
1263
pendingPartitionsInTransaction .clear ();
0 commit comments