From 6b0f3f7067f98fe1f289d7b9d82f69912d9a8df7 Mon Sep 17 00:00:00 2001 From: Yixin Luo <18810541851@163.com> Date: Thu, 18 May 2023 15:18:29 +0800 Subject: [PATCH] [BugFix] fix schema change hang when data loading concurrent with schema change (#23456) Fixes #23452 1. Assume there is a partition, current visible version is 13378, and all loading task is finished. 2. Trigger schema change, it will create new replica, and at the same time, one loading task is trigger and finished, and it's version is 13379. 3. Before send alter replica request, FE check that all loading task is finished, but loading task on new create replica haven't finish yet and V=1, LFV=13379. 4. Alter replica finish on BE, and BE send finish alter replica request back to FE. When call `handleFinishAlterTask`, `checkState` fail because LFV != -1. (cherry picked from commit 084a19c63e5387afcc183b5e17f7dab47c034871) --- .../com/starrocks/task/AlterReplicaTask.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/task/AlterReplicaTask.java b/fe/fe-core/src/main/java/com/starrocks/task/AlterReplicaTask.java index 4134b30e03109..88454db67aecf 100644 --- a/fe/fe-core/src/main/java/com/starrocks/task/AlterReplicaTask.java +++ b/fe/fe-core/src/main/java/com/starrocks/task/AlterReplicaTask.java @@ -188,6 +188,9 @@ public TAlterTabletReqV2 toThrift() { * There are new load jobs after alter task, and at least one of them is succeed on this replica. * So the replica's version should be larger than X. So we don't need to modify the replica version * because its already looks like normal. + * Case 3: + * There are new load jobs after alter task, and their version and LFV is smaller or equal to X. + * And because alter request report success, it means that we can increase replica's version to X. */ public void handleFinishAlterTask() throws Exception { Database db = GlobalStateMgr.getCurrentState().getDb(getDbId()); @@ -221,18 +224,10 @@ public void handleFinishAlterTask() throws Exception { getVersion()); boolean versionChanged = false; if (replica.getVersion() <= getVersion()) { - if (replica.getLastFailedVersion() > getVersion()) { - // Case 2.1 - replica.updateRowCount(getVersion(), replica.getDataSize(), - replica.getRowCount()); - versionChanged = true; - } else { - // Case 1 - Preconditions.checkState(replica.getLastFailedVersion() == -1, replica.getLastFailedVersion()); - replica.updateRowCount(getVersion(), replica.getDataSize(), - replica.getRowCount()); - versionChanged = true; - } + // Case 1, Case 2.1 or Case 3 + replica.updateRowCount(getVersion(), replica.getDataSize(), + replica.getRowCount()); + versionChanged = true; } if (versionChanged) {