Skip to content

Commit

Permalink
[fix](schema-change) Fix job replay failure when partitions added to …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
TangSiyang2001 authored Jan 2, 2025
1 parent 902151f commit 04d7927
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 04d7927

Please sign in to comment.