Skip to content

Commit

Permalink
[fix](schema-change) Fix potential data race when a schema change job…
Browse files Browse the repository at this point in the history
…s 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.
  • Loading branch information
TangSiyang2001 authored Aug 15, 2024
1 parent aebc70d commit 642beb0
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ private void onFinished(OlapTable tbl) {
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);
Expand Down Expand Up @@ -704,12 +704,11 @@ protected synchronized boolean cancelImpl(String errMsg) {
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;
}

Expand Down Expand Up @@ -745,8 +744,6 @@ private void cancelInternal() {
}
}
}

jobState = JobState.CANCELLED;
}

// Check whether transactions of the given database which txnId is less than 'watershedTxnId' are finished.
Expand Down

0 comments on commit 642beb0

Please sign in to comment.