From 04d792771e11bc662ed8435446fceb97ecf3c7b0 Mon Sep 17 00:00:00 2001 From: Siyang Tang Date: Thu, 2 Jan 2025 10:19:24 +0800 Subject: [PATCH] [fix](schema-change) Fix job replay failure when partitions added to table after job finish (#46166) If all partitions in table are engaged in schema change job replay, replay may fail if there is any partition created after alter job commitment and before job replay. Therefore, write edit log within table write lock. --- .../apache/doris/alter/SchemaChangeJobV2.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) 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);