From 8e024d852d991549438a9ac79ad765a7abaacf00 Mon Sep 17 00:00:00 2001 From: yujun Date: Mon, 29 Jun 2026 19:02:03 +0800 Subject: [PATCH] fix(mtmv): serialize alterJob with running tasks to prevent concurrent refresh ALTER MTMV REFRESH ON COMMIT calls alterJob() which does dropJob() + createJob(), creating a new MTMVJob instance with a new ReentrantReadWriteLock. If the CREATE MTMV immediate build task is still running under the old jobs writeLock, the new on-commit task can acquire the new jobs writeLock concurrently, causing two refresh tasks to operate on the same MTMV simultaneously and triggering "partition not found". Fix: In alterJob(), acquire the existing jobs writeLock before drop+create, ensuring all running tasks complete before the job is rebuilt. This serializes the alter with any in-flight tasks using the same lock instance. Co-Authored-By: Claude --- .../java/org/apache/doris/mtmv/MTMVJobManager.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java index 67a5bbe4db5294..971bbfa3501653 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java @@ -143,8 +143,18 @@ public void dropJob(MTMV mtmv, boolean isReplay) { } public void alterJob(MTMV mtmv, boolean isReplay) { - dropJob(mtmv, isReplay); - createJob(mtmv, isReplay); + MTMVJob oldJob = getJobByMTMV(mtmv); + if (!isReplay && oldJob != null) { + oldJob.writeLock(); + } + try { + dropJob(mtmv, isReplay); + createJob(mtmv, isReplay); + } finally { + if (!isReplay && oldJob != null) { + oldJob.writeUnlock(); + } + } } /**