Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,28 @@ public MTMVStatus alterStatus(MTMVStatus newStatus) {

public void addTaskResult(MTMVTask task, MTMVRelation relation,
Map<String, MTMVRefreshPartitionSnapshot> partitionSnapshots) {
MTMVCache mtmvCache = null;
boolean needUpdateCache = false;
if (task.getStatus() == TaskStatus.SUCCESS && !Env.isCheckpointThread()
&& !Config.enable_check_compatibility_mode) {
needUpdateCache = true;
try {
// shouldn't do this while holding mvWriteLock
mtmvCache = MTMVCache.from(this, MTMVPlanUtil.createMTMVContext(this), true);
} catch (Throwable e) {
mtmvCache = null;
LOG.warn("generate cache failed", e);
}
}
writeMvLock();
try {
if (task.getStatus() == TaskStatus.SUCCESS) {
this.status.setState(MTMVState.NORMAL);
this.status.setSchemaChangeDetail(null);
this.status.setRefreshState(MTMVRefreshState.SUCCESS);
this.relation = relation;
if (!Env.isCheckpointThread() && !Config.enable_check_compatibility_mode) {
try {
this.cache = MTMVCache.from(this, MTMVPlanUtil.createMTMVContext(this), true);
} catch (Throwable e) {
this.cache = null;
LOG.warn("generate cache failed", e);
}
if (needUpdateCache) {
this.cache = mtmvCache;
}
} else {
this.status.setRefreshState(MTMVRefreshState.FAIL);
Expand Down Expand Up @@ -268,17 +276,24 @@ public Set<String> getExcludedTriggerTables() {
* Called when in query, Should use one connection context in query
*/
public MTMVCache getOrGenerateCache(ConnectContext connectionContext) throws AnalysisException {
if (cache == null) {
writeMvLock();
try {
if (cache == null) {
this.cache = MTMVCache.from(this, connectionContext, true);
}
} finally {
writeMvUnlock();
readMvLock();
try {
if (cache != null) {
return cache;
}
} finally {
readMvUnlock();
}
// Concurrent situations may result in duplicate cache generation,
// but we tolerate this in order to prevent nested use of readLock and write MvLock for the table
MTMVCache mtmvCache = MTMVCache.from(this, connectionContext, true);
writeMvLock();
try {
this.cache = mtmvCache;
return cache;
} finally {
writeMvUnlock();
}
return cache;
}

public MTMVCache getCache() {
Expand Down