@@ -2374,6 +2374,7 @@ protected void updateLastSeqPushed(OpSendMsg op) {
2374
2374
* 3-1-1. If {@link #pauseSendingToPreservePublishOrderOnSchemaRegFailure} is true pause all following
2375
2375
* publishing to avoid out-of-order issue.
2376
2376
* 3-1-2. Otherwise, discard the failed message anc continuously publishing the following messages.
2377
+ * Additionally, the following messages may need schema registration also.
2377
2378
* 3-2. The new schema registration failed due to other error, retry registering.
2378
2379
* Note: Since the current method accesses & modifies {@link #pendingMessages}, you should acquire a lock on
2379
2380
* {@link ProducerImpl} before calling method.
@@ -2392,6 +2393,7 @@ private void recoverProcessOpSendMsgFrom(ClientCnx cnx, MessageImpl latestMsgAtt
2392
2393
Iterator <OpSendMsg > msgIterator = pendingMessages .iterator ();
2393
2394
MessageImpl loopStartAt = latestMsgAttemptedRegisteredSchema ;
2394
2395
OpSendMsg loopEndDueToSchemaRegisterNeeded = null ;
2396
+ boolean pausedSendingToPreservePublishOrderOnSchemaRegFailure = false ;
2395
2397
while (msgIterator .hasNext ()) {
2396
2398
OpSendMsg op = msgIterator .next ();
2397
2399
if (loopStartAt != null ) {
@@ -2436,6 +2438,7 @@ private void recoverProcessOpSendMsgFrom(ClientCnx cnx, MessageImpl latestMsgAtt
2436
2438
+ " 2) Unload topic on target cluster. Schema details: {}" ,
2437
2439
topic , producerName , SchemaUtils .jsonifySchemaInfo (msgSchemaInfo , false ));
2438
2440
loopEndDueToSchemaRegisterNeeded = op ;
2441
+ pausedSendingToPreservePublishOrderOnSchemaRegFailure = true ;
2439
2442
break ;
2440
2443
}
2441
2444
// Event 3-1-2.
@@ -2491,23 +2494,27 @@ private void recoverProcessOpSendMsgFrom(ClientCnx cnx, MessageImpl latestMsgAtt
2491
2494
}
2492
2495
cnx .ctx ().flush ();
2493
2496
2494
- // "Event 1-1" or "Event 3-1-1" or "Event 3-2".
2497
+ // "Event 1-1" or "Event 3-1-1" or "Event 3-1-2" or "Event 3- 2".
2495
2498
if (loopEndDueToSchemaRegisterNeeded != null ) {
2496
2499
if (compareAndSetState (State .Connecting , State .Ready )) {
2497
2500
// "Event 1-1" happens after "Event 3-1-1".
2498
2501
// After a topic unload, ask the producer retry to register schema, which avoids restart client
2499
2502
// after users changed the compatibility strategy to make the schema is compatible.
2500
2503
tryRegisterSchema (cnx , loopEndDueToSchemaRegisterNeeded .msg , loopEndDueToSchemaRegisterNeeded .callback ,
2501
2504
expectedEpoch );
2502
- } else if (!failedIncompatibleSchema && compareAndSetState (State .RegisteringSchema , State .Ready )) {
2503
- // "Event 2-1" or "Event 3-2".
2505
+ } else if (pausedSendingToPreservePublishOrderOnSchemaRegFailure ) {
2506
+ // Nothing to do if the event is "Event 3-1-1", just keep stuck.
2507
+ return ;
2508
+ } else if (compareAndSetState (State .RegisteringSchema , State .Ready )) {
2509
+ // "Event 2-1" or "Event 3-1-2" or "Event 3-2".
2504
2510
// "pendingMessages" has more messages to register new schema.
2505
2511
// This operation will not be conflict with another schema registration because both operations are
2506
2512
// attempt to acquire the same lock "ProducerImpl.this".
2507
2513
tryRegisterSchema (cnx , loopEndDueToSchemaRegisterNeeded .msg , loopEndDueToSchemaRegisterNeeded .callback ,
2508
2514
expectedEpoch );
2509
2515
}
2510
- // Nothing to do if the event is "Event 3-1-1", just keep stuck.
2516
+ // Schema registration will trigger a new "recoverProcessOpSendMsgFrom", so return here. If failed to switch
2517
+ // state, it means another task will trigger a new "recoverProcessOpSendMsgFrom".
2511
2518
return ;
2512
2519
} else if (latestMsgAttemptedRegisteredSchema != null ) {
2513
2520
// Event 2-2 or "Event 3-1-2".
0 commit comments