yujun777 opened a new pull request, #64958:
URL: https://github.com/apache/doris/pull/64958
## Problem
Fixes DORIS-26669.
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 job's writeLock, the new on-commit task can acquire the
new job's writeLock concurrently, causing two refresh tasks to operate on the
same MTMV simultaneously.
This race triggers "partition not found" when the on-commit task reads
partition metadata via
`UpdateMvByPartitionCommand.constructTableWithPredicates()`, while the
immediate build task is in the middle of replacing partitions.
## Root Cause
- `alterJob()` drops the old job and creates a new one
- The new job has a brand new `ReentrantReadWriteLock` instance
- `MTMVTask.runTask()` acquires the writeLock from `getJobOrJobException()`
- After drop+create, `getJobOrJobException()` returns the new job with a
different lock
- Two tasks can hold two different locks → no mutual exclusion
## Fix
In `alterJob()`, acquire the existing job's 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.
## Change
Single file:
`fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVJobManager.java`
```java
public void alterJob(MTMV mtmv, boolean isReplay) {
MTMVJob oldJob = getJobByMTMV(mtmv);
if (!isReplay && oldJob != null) {
oldJob.writeLock(); // block until running tasks complete
}
try {
dropJob(mtmv, isReplay);
createJob(mtmv, isReplay);
} finally {
if (!isReplay && oldJob != null) {
oldJob.writeUnlock();
}
}
}
```
- No deadlock risk: lock ordering is always PER-JOB → GLOBAL, no reverse path
- Replay path (`isReplay=true`) unchanged
- Null-safe on `oldJob`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]