@@ -2464,6 +2464,7 @@ protected void updateLastSeqPushed(OpSendMsg op) {
2464
2464
* 3-1-1. If {@link #pauseSendingToPreservePublishOrderOnSchemaRegFailure} is true pause all following
2465
2465
* publishing to avoid out-of-order issue.
2466
2466
* 3-1-2. Otherwise, discard the failed message anc continuously publishing the following messages.
2467
+ * Additionally, the following messages may need schema registration also.
2467
2468
* 3-2. The new schema registration failed due to other error, retry registering.
2468
2469
* Note: Since the current method accesses & modifies {@link #pendingMessages}, you should acquire a lock on
2469
2470
* {@link ProducerImpl} before calling method.
@@ -2482,6 +2483,7 @@ private void recoverProcessOpSendMsgFrom(ClientCnx cnx, MessageImpl latestMsgAtt
2482
2483
Iterator <OpSendMsg > msgIterator = pendingMessages .iterator ();
2483
2484
MessageImpl loopStartAt = latestMsgAttemptedRegisteredSchema ;
2484
2485
OpSendMsg loopEndDueToSchemaRegisterNeeded = null ;
2486
+ boolean pausedSendingToPreservePublishOrderOnSchemaRegFailure = false ;
2485
2487
while (msgIterator .hasNext ()) {
2486
2488
OpSendMsg op = msgIterator .next ();
2487
2489
if (loopStartAt != null ) {
@@ -2526,6 +2528,7 @@ private void recoverProcessOpSendMsgFrom(ClientCnx cnx, MessageImpl latestMsgAtt
2526
2528
+ " 2) Unload topic on target cluster. Schema details: {}" ,
2527
2529
topic , producerName , SchemaUtils .jsonifySchemaInfo (msgSchemaInfo , false ));
2528
2530
loopEndDueToSchemaRegisterNeeded = op ;
2531
+ pausedSendingToPreservePublishOrderOnSchemaRegFailure = true ;
2529
2532
break ;
2530
2533
}
2531
2534
// Event 3-1-2.
@@ -2581,23 +2584,27 @@ private void recoverProcessOpSendMsgFrom(ClientCnx cnx, MessageImpl latestMsgAtt
2581
2584
}
2582
2585
cnx .ctx ().flush ();
2583
2586
2584
- // "Event 1-1" or "Event 3-1-1" or "Event 3-2".
2587
+ // "Event 1-1" or "Event 3-1-1" or "Event 3-1-2" or "Event 3- 2".
2585
2588
if (loopEndDueToSchemaRegisterNeeded != null ) {
2586
2589
if (compareAndSetState (State .Connecting , State .Ready )) {
2587
2590
// "Event 1-1" happens after "Event 3-1-1".
2588
2591
// After a topic unload, ask the producer retry to register schema, which avoids restart client
2589
2592
// after users changed the compatibility strategy to make the schema is compatible.
2590
2593
tryRegisterSchema (cnx , loopEndDueToSchemaRegisterNeeded .msg , loopEndDueToSchemaRegisterNeeded .callback ,
2591
2594
expectedEpoch );
2592
- } else if (!failedIncompatibleSchema && compareAndSetState (State .RegisteringSchema , State .Ready )) {
2593
- // "Event 2-1" or "Event 3-2".
2595
+ } else if (pausedSendingToPreservePublishOrderOnSchemaRegFailure ) {
2596
+ // Nothing to do if the event is "Event 3-1-1", just keep stuck.
2597
+ return ;
2598
+ } else if (compareAndSetState (State .RegisteringSchema , State .Ready )) {
2599
+ // "Event 2-1" or "Event 3-1-2" or "Event 3-2".
2594
2600
// "pendingMessages" has more messages to register new schema.
2595
2601
// This operation will not be conflict with another schema registration because both operations are
2596
2602
// attempt to acquire the same lock "ProducerImpl.this".
2597
2603
tryRegisterSchema (cnx , loopEndDueToSchemaRegisterNeeded .msg , loopEndDueToSchemaRegisterNeeded .callback ,
2598
2604
expectedEpoch );
2599
2605
}
2600
- // Nothing to do if the event is "Event 3-1-1", just keep stuck.
2606
+ // Schema registration will trigger a new "recoverProcessOpSendMsgFrom", so return here. If failed to switch
2607
+ // state, it means another task will trigger a new "recoverProcessOpSendMsgFrom".
2601
2608
return ;
2602
2609
} else if (latestMsgAttemptedRegisteredSchema != null ) {
2603
2610
// Event 2-2 or "Event 3-1-2".
0 commit comments