@@ -445,18 +445,19 @@ private void schedulePendingTablets() {
445445 stat .counterTabletScheduledFailed .incrementAndGet ();
446446 addBackToPendingTablets (tabletCtx );
447447 }
448- } else if (e .getStatus () == Status .FINISHED ) {
449- // schedule redundant tablet or scheduler disabled will throw this exception
450- stat .counterTabletScheduledSucceeded .incrementAndGet ();
451- finalizeTabletCtx (tabletCtx , TabletSchedCtx .State .FINISHED , e .getStatus (), e .getMessage ());
448+ continue ;
449+ } else if (e .getStatus () == Status .SUBMITTED ) {
450+ // The SUBMITTED status will only occur when scheduling tablets that are of
451+ // the REDUNDANT or FORCE_REDUNDANT.
452+ continue ;
452453 } else {
453454 Preconditions .checkState (e .getStatus () == Status .UNRECOVERABLE , e .getStatus ());
454455 // discard
455456 stat .counterTabletScheduledDiscard .incrementAndGet ();
456457 tabletCtx .setSchedFailedCode (e .getSubCode ());
457458 finalizeTabletCtx (tabletCtx , TabletSchedCtx .State .CANCELLED , e .getStatus (), e .getMessage ());
459+ continue ;
458460 }
459- continue ;
460461 } catch (Exception e ) {
461462 LOG .warn ("got unexpected exception, discard this schedule. tablet: {}" ,
462463 tabletCtx .getTabletId (), e );
@@ -524,7 +525,7 @@ private void scheduleTablet(TabletSchedCtx tabletCtx, AgentBatchTask batchTask)
524525 OlapTable tbl = (OlapTable ) db .getTableOrException (tabletCtx .getTblId (),
525526 s -> new SchedException (Status .UNRECOVERABLE , SubCode .DIAGNOSE_IGNORE ,
526527 "tbl " + tabletCtx .getTblId () + " does not exist" ));
527- tbl .writeLockOrException (new SchedException (Status .UNRECOVERABLE ,
528+ tbl .readLockOrException (new SchedException (Status .UNRECOVERABLE ,
528529 "table " + tbl .getName () + " does not exist" ));
529530 try {
530531 long tabletId = tabletCtx .getTabletId ();
@@ -649,7 +650,7 @@ private void scheduleTablet(TabletSchedCtx tabletCtx, AgentBatchTask batchTask)
649650
650651 handleTabletByTypeAndStatus (tabletHealth .status , tabletCtx , batchTask );
651652 } finally {
652- tbl .writeUnlock ();
653+ tbl .readUnlock ();
653654 }
654655 }
655656
@@ -896,9 +897,9 @@ private void handleRedundantReplica(TabletSchedCtx tabletCtx, boolean force) thr
896897 || deleteReplicaOnUrgentHighDisk (tabletCtx , force )
897898 || deleteFromScaleInDropReplicas (tabletCtx , force )
898899 || deleteReplicaOnHighLoadBackend (tabletCtx , force )) {
899- // if we delete at least one redundant replica, we still throw a SchedException with status FINISHED
900- // to remove this tablet from the pendingTablets(consider it as finished)
901- throw new SchedException (Status .FINISHED , "redundant replica is deleted " );
900+ // if we will delete at least one redundant replica, an async task will be created to handle it.
901+ // we need to throw a SchedException with status SUBMITTED to indicate the task has been submitted.
902+ throw new SchedException (Status .SUBMITTED , "redundant replica task is submitted " );
902903 }
903904 throw new SchedException (Status .UNRECOVERABLE , "unable to delete any redundant replicas" );
904905 }
@@ -1284,10 +1285,18 @@ private void deleteReplicaInternal(TabletSchedCtx tabletCtx,
12841285 tabletCtx .getTabletId (),
12851286 beId );
12861287
1287- Env .getCurrentEnv ().getEditLog ().logDeleteReplica (info );
1288-
1289- LOG .info ("delete replica. tablet id: {}, backend id: {}. reason: {}, force: {}" ,
1290- tabletCtx .getTabletId (), beId , reason , force );
1288+ EditLogExecutor .submit (() -> {
1289+ Env .getCurrentEnv ().getEditLog ().logDeleteReplica (info );
1290+ LOG .info ("delete replica. tablet id: {}, backend id: {}. reason: {}, force: {}" ,
1291+ tabletCtx .getTabletId (), beId , reason , force );
1292+ stat .counterTabletScheduledSucceeded .incrementAndGet ();
1293+ gatherStatistics (tabletCtx );
1294+ finalizeTabletCtx (tabletCtx , TabletSchedCtx .State .FINISHED , Status .FINISHED , "write edit log finished" );
1295+ }, () -> {
1296+ stat .counterTabletScheduledFailed .incrementAndGet ();
1297+ finalizeTabletCtx (tabletCtx , TabletSchedCtx .State .CANCELLED , Status .SCHEDULE_FAILED ,
1298+ "failed to write edit log" );
1299+ });
12911300 }
12921301
12931302 private void sendDeleteReplicaTask (long backendId , long tabletId , long replicaId , int schemaHash ) {
@@ -1638,7 +1647,7 @@ private void addBackToPendingTablets(TabletSchedCtx tabletCtx) {
16381647 addTablet (tabletCtx , true /* force */ );
16391648 }
16401649
1641- private void finalizeTabletCtx (TabletSchedCtx tabletCtx , TabletSchedCtx .State state , Status status , String reason ) {
1650+ void finalizeTabletCtx (TabletSchedCtx tabletCtx , TabletSchedCtx .State state , Status status , String reason ) {
16421651 if (state == TabletSchedCtx .State .CANCELLED || state == TabletSchedCtx .State .UNEXPECTED ) {
16431652 if (tabletCtx .getType () == TabletSchedCtx .Type .BALANCE
16441653 && tabletCtx .getBalanceType () == TabletSchedCtx .BalanceType .BE_BALANCE ) {
@@ -1866,7 +1875,7 @@ public boolean finishCloneTask(CloneTask cloneTask, TFinishTaskRequest request)
18661875
18671876 Preconditions .checkState (tabletCtx .getState () == TabletSchedCtx .State .RUNNING , tabletCtx .getState ());
18681877 try {
1869- tabletCtx .finishCloneTask (cloneTask , request );
1878+ tabletCtx .finishCloneTask (this , cloneTask , request );
18701879 } catch (SchedException e ) {
18711880 tabletCtx .setErrMsg (e .getMessage ());
18721881 if (e .getStatus () == Status .RUNNING_FAILED ) {
@@ -1890,6 +1899,9 @@ public boolean finishCloneTask(CloneTask cloneTask, TFinishTaskRequest request)
18901899 stat .counterTabletScheduledDiscard .incrementAndGet ();
18911900 finalizeTabletCtx (tabletCtx , TabletSchedCtx .State .CANCELLED , e .getStatus (), e .getMessage ());
18921901 return true ;
1902+ } else if (e .getStatus () == Status .SUBMITTED ) {
1903+ // no finalizeTabletCtx
1904+ return true ;
18931905 } else if (e .getStatus () == Status .FINISHED ) {
18941906 // tablet is already healthy, just remove
18951907 finalizeTabletCtx (tabletCtx , TabletSchedCtx .State .CANCELLED , e .getStatus (), e .getMessage ());
@@ -1915,7 +1927,7 @@ public boolean finishCloneTask(CloneTask cloneTask, TFinishTaskRequest request)
19151927 * It will be evaluated for future strategy.
19161928 * This should only be called when the tablet is down with state FINISHED.
19171929 */
1918- private void gatherStatistics (TabletSchedCtx tabletCtx ) {
1930+ void gatherStatistics (TabletSchedCtx tabletCtx ) {
19191931 if (tabletCtx .getCopySize () > 0 && tabletCtx .getCopyTimeMs () > 0 ) {
19201932 if (tabletCtx .getSrcBackendId () != -1 && tabletCtx .getSrcPathHash () != -1 ) {
19211933 PathSlot pathSlot = backendsWorkingSlots .get (tabletCtx .getSrcBackendId ());
0 commit comments