@@ -663,21 +663,21 @@ protected void runRunningJob() throws AlterCancelException {
663
663
commitShadowIndex ();
664
664
// all partitions are good
665
665
onFinished (tbl );
666
- } finally {
667
- tbl .writeUnlock ();
668
- }
669
-
670
- pruneMeta ();
671
-
672
- LOG .info ("schema change job finished: {}" , jobId );
666
+ pruneMeta ();
673
667
674
- changeTableState (dbId , tableId , OlapTableState .NORMAL );
675
- LOG .info ("set table's state to NORMAL, table id: {}, job id: {}" , tableId , jobId );
668
+ LOG .info ("schema change job finished: {}" , jobId );
676
669
677
- this .jobState = JobState .FINISHED ;
678
- this .finishedTimeMs = System .currentTimeMillis ();
679
- Env .getCurrentEnv ().getEditLog ().logAlterJob (this );
670
+ changeTableState (dbId , tableId , OlapTableState .NORMAL );
671
+ LOG .info ("set table's state to NORMAL, table id: {}, job id: {}" , tableId , jobId );
680
672
673
+ this .jobState = JobState .FINISHED ;
674
+ this .finishedTimeMs = System .currentTimeMillis ();
675
+ // Write edit log with table's write lock held, to avoid adding partitions before writing edit log,
676
+ // else it will try to transform index in newly added partition while replaying and result in failure.
677
+ Env .getCurrentEnv ().getEditLog ().logAlterJob (this );
678
+ } finally {
679
+ tbl .writeUnlock ();
680
+ }
681
681
postProcessOriginIndex ();
682
682
// Drop table column stats after schema change finished.
683
683
Env .getCurrentEnv ().getAnalysisManager ().dropStats (tbl , null );
0 commit comments