@@ -2447,6 +2447,7 @@ protected void updateLastSeqPushed(OpSendMsg op) {
2447
2447
* 3-1-1. If {@link #pauseSendingToPreservePublishOrderOnSchemaRegFailure} is true pause all following
2448
2448
* publishing to avoid out-of-order issue.
2449
2449
* 3-1-2. Otherwise, discard the failed message anc continuously publishing the following messages.
2450
+ * Additionally, the following messages may need schema registration also.
2450
2451
* 3-2. The new schema registration failed due to other error, retry registering.
2451
2452
* Note: Since the current method accesses & modifies {@link #pendingMessages}, you should acquire a lock on
2452
2453
* {@link ProducerImpl} before calling method.
@@ -2465,6 +2466,7 @@ private void recoverProcessOpSendMsgFrom(ClientCnx cnx, MessageImpl latestMsgAtt
2465
2466
Iterator <OpSendMsg > msgIterator = pendingMessages .iterator ();
2466
2467
MessageImpl loopStartAt = latestMsgAttemptedRegisteredSchema ;
2467
2468
OpSendMsg loopEndDueToSchemaRegisterNeeded = null ;
2469
+ boolean pausedSendingToPreservePublishOrderOnSchemaRegFailure = false ;
2468
2470
while (msgIterator .hasNext ()) {
2469
2471
OpSendMsg op = msgIterator .next ();
2470
2472
if (loopStartAt != null ) {
@@ -2509,6 +2511,7 @@ private void recoverProcessOpSendMsgFrom(ClientCnx cnx, MessageImpl latestMsgAtt
2509
2511
+ " 2) Unload topic on target cluster. Schema details: {}" ,
2510
2512
topic , producerName , SchemaUtils .jsonifySchemaInfo (msgSchemaInfo , false ));
2511
2513
loopEndDueToSchemaRegisterNeeded = op ;
2514
+ pausedSendingToPreservePublishOrderOnSchemaRegFailure = true ;
2512
2515
break ;
2513
2516
}
2514
2517
// Event 3-1-2.
@@ -2564,23 +2567,27 @@ private void recoverProcessOpSendMsgFrom(ClientCnx cnx, MessageImpl latestMsgAtt
2564
2567
}
2565
2568
cnx .ctx ().flush ();
2566
2569
2567
- // "Event 1-1" or "Event 3-1-1" or "Event 3-2".
2570
+ // "Event 1-1" or "Event 3-1-1" or "Event 3-1-2" or "Event 3- 2".
2568
2571
if (loopEndDueToSchemaRegisterNeeded != null ) {
2569
2572
if (compareAndSetState (State .Connecting , State .Ready )) {
2570
2573
// "Event 1-1" happens after "Event 3-1-1".
2571
2574
// After a topic unload, ask the producer retry to register schema, which avoids restart client
2572
2575
// after users changed the compatibility strategy to make the schema is compatible.
2573
2576
tryRegisterSchema (cnx , loopEndDueToSchemaRegisterNeeded .msg , loopEndDueToSchemaRegisterNeeded .callback ,
2574
2577
expectedEpoch );
2575
- } else if (!failedIncompatibleSchema && compareAndSetState (State .RegisteringSchema , State .Ready )) {
2576
- // "Event 2-1" or "Event 3-2".
2578
+ } else if (pausedSendingToPreservePublishOrderOnSchemaRegFailure ) {
2579
+ // Nothing to do if the event is "Event 3-1-1", just keep stuck.
2580
+ return ;
2581
+ } else if (compareAndSetState (State .RegisteringSchema , State .Ready )) {
2582
+ // "Event 2-1" or "Event 3-1-2" or "Event 3-2".
2577
2583
// "pendingMessages" has more messages to register new schema.
2578
2584
// This operation will not be conflict with another schema registration because both operations are
2579
2585
// attempt to acquire the same lock "ProducerImpl.this".
2580
2586
tryRegisterSchema (cnx , loopEndDueToSchemaRegisterNeeded .msg , loopEndDueToSchemaRegisterNeeded .callback ,
2581
2587
expectedEpoch );
2582
2588
}
2583
- // Nothing to do if the event is "Event 3-1-1", just keep stuck.
2589
+ // Schema registration will trigger a new "recoverProcessOpSendMsgFrom", so return here. If failed to switch
2590
+ // state, it means another task will trigger a new "recoverProcessOpSendMsgFrom".
2584
2591
return ;
2585
2592
} else if (latestMsgAttemptedRegisteredSchema != null ) {
2586
2593
// Event 2-2 or "Event 3-1-2".
0 commit comments