diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeJobV2.java b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeJobV2.java index a624dc3c733374..54bcc35262760c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeJobV2.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeJobV2.java @@ -663,21 +663,21 @@ protected void runRunningJob() throws AlterCancelException { commitShadowIndex(); // all partitions are good onFinished(tbl); - } finally { - tbl.writeUnlock(); - } - - pruneMeta(); - - LOG.info("schema change job finished: {}", jobId); + pruneMeta(); - changeTableState(dbId, tableId, OlapTableState.NORMAL); - LOG.info("set table's state to NORMAL, table id: {}, job id: {}", tableId, jobId); + LOG.info("schema change job finished: {}", jobId); - this.jobState = JobState.FINISHED; - this.finishedTimeMs = System.currentTimeMillis(); - Env.getCurrentEnv().getEditLog().logAlterJob(this); + changeTableState(dbId, tableId, OlapTableState.NORMAL); + LOG.info("set table's state to NORMAL, table id: {}, job id: {}", tableId, jobId); + this.jobState = JobState.FINISHED; + this.finishedTimeMs = System.currentTimeMillis(); + // Write edit log with table's write lock held, to avoid adding partitions before writing edit log, + // else it will try to transform index in newly added partition while replaying and result in failure. + Env.getCurrentEnv().getEditLog().logAlterJob(this); + } finally { + tbl.writeUnlock(); + } postProcessOriginIndex(); // Drop table column stats after schema change finished. Env.getCurrentEnv().getAnalysisManager().dropStats(tbl, null);