@@ -413,26 +413,38 @@ public interface ThrowableFunction<T, R> {
413413 R apply (T t ) throws Exception ;
414414 }
415415
416- public void inactivePeer (Peer peer , boolean forDeletionPurpose )
416+ public void inactivatePeer (Peer peer , boolean forDeletionPurpose )
417417 throws ConsensusGroupModifyPeerException {
418- try (SyncIoTConsensusServiceClient client =
419- syncClientManager .borrowClient (peer .getEndpoint ())) {
420- try {
421- TInactivatePeerRes res =
422- client .inactivatePeer (
423- new TInactivatePeerReq (peer .getGroupId ().convertToTConsensusGroupId ())
424- .setForDeletionPurpose (forDeletionPurpose ));
425- if (!isSuccess (res .status )) {
426- throw new ConsensusGroupModifyPeerException (
427- String .format ("error when inactivating %s. %s" , peer , res .getStatus ()));
418+ ConsensusGroupModifyPeerException lastException = null ;
419+ // In region migration, if the target node restarts before the “addRegionPeer” phase within 1
420+ // minutes,
421+ // the client in the ClientManager will become invalid.
422+ // This PR adds 1 retry at this point to ensure that region migration can still proceed
423+ // correctly in such cases.
424+ for (int i = 0 ; i < 2 ; i ++) {
425+ try (SyncIoTConsensusServiceClient client =
426+ syncClientManager .borrowClient (peer .getEndpoint ())) {
427+ try {
428+ TInactivatePeerRes res =
429+ client .inactivatePeer (
430+ new TInactivatePeerReq (peer .getGroupId ().convertToTConsensusGroupId ())
431+ .setForDeletionPurpose (forDeletionPurpose ));
432+ if (isSuccess (res .status )) {
433+ return ;
434+ }
435+ lastException =
436+ new ConsensusGroupModifyPeerException (
437+ String .format ("error when inactivating %s. %s" , peer , res .getStatus ()));
438+ } catch (Exception e ) {
439+ lastException =
440+ new ConsensusGroupModifyPeerException (
441+ String .format ("error when inactivating %s" , peer ), e );
428442 }
429- } catch (Exception e ) {
430- throw new ConsensusGroupModifyPeerException (
431- String .format ("error when inactivating %s" , peer ), e );
443+ } catch (ClientManagerException e ) {
444+ lastException = new ConsensusGroupModifyPeerException (e );
432445 }
433- } catch (ClientManagerException e ) {
434- throw new ConsensusGroupModifyPeerException (e );
435446 }
447+ throw lastException ;
436448 }
437449
438450 public void triggerSnapshotLoad (Peer peer ) throws ConsensusGroupModifyPeerException {
0 commit comments