From 642beb069b9d78f7142202b3fb33f2cadf276021 Mon Sep 17 00:00:00 2001 From: Siyang Tang <82279870+TangSiyang2001@users.noreply.github.com> Date: Thu, 15 Aug 2024 14:18:11 +0800 Subject: [PATCH] [fix](schema-change) Fix potential data race when a schema change jobs is set to cancelled but the table state is still SCHEMA_CHANGE (#39164) (#39327) ## Proposed changes Set job cancel state after table state changed to normal. --- .../org/apache/doris/alter/SchemaChangeJobV2.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 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 86f0e24a62..e74754de75 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 @@ -657,7 +657,7 @@ public class SchemaChangeJobV2 extends AlterJobV2 { tbl.getIndexMetaByIndexId(shadowIdxId).setMaxColUniqueId(maxColUniqueId); if (LOG.isDebugEnabled()) { LOG.debug("originIdxId:{}, shadowIdxId:{}, maxColUniqueId:{}, indexSchema:{}", - originIdxId, shadowIdxId, maxColUniqueId, indexSchemaMap.get(shadowIdxId)); + originIdxId, shadowIdxId, maxColUniqueId, indexSchemaMap.get(shadowIdxId)); } tbl.deleteIndexInfo(originIdxName); @@ -704,12 +704,11 @@ public class SchemaChangeJobV2 extends AlterJobV2 { pruneMeta(); this.errMsg = errMsg; this.finishedTimeMs = System.currentTimeMillis(); - LOG.info("cancel {} job {}, err: {}", this.type, jobId, errMsg); - Env.getCurrentEnv().getEditLog().logAlterJob(this); - changeTableState(dbId, tableId, OlapTableState.NORMAL); LOG.info("set table's state to NORMAL when cancel, table id: {}, job id: {}", tableId, jobId); - + jobState = JobState.CANCELLED; + Env.getCurrentEnv().getEditLog().logAlterJob(this); + LOG.info("cancel {} job {}, err: {}", this.type, jobId, errMsg); return true; } @@ -745,8 +744,6 @@ public class SchemaChangeJobV2 extends AlterJobV2 { } } } - - jobState = JobState.CANCELLED; } // Check whether transactions of the given database which txnId is less than 'watershedTxnId' are finished.