[enhance](mtmv) During cache generation, no longer hold the write loc… (#40489)

…k for mtmv (#40402)

pick: https://github.com/apache/doris/pull/40402
This commit is contained in:
zhangdong
2024-09-09 11:35:22 +08:00
committed by GitHub
parent facce8b4d5
commit 01a651e573

View File

@ -182,6 +182,18 @@ public class MTMV extends OlapTable {
public void addTaskResult(MTMVTask task, MTMVRelation relation,
Map<String, MTMVRefreshPartitionSnapshot> partitionSnapshots) {
MTMVCache mtmvCache = null;
boolean needUpdateCache = false;
if (task.getStatus() == TaskStatus.SUCCESS && !Env.isCheckpointThread()) {
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) {
@ -189,13 +201,8 @@ public class MTMV extends OlapTable {
this.status.setSchemaChangeDetail(null);
this.status.setRefreshState(MTMVRefreshState.SUCCESS);
this.relation = relation;
if (!Env.isCheckpointThread()) {
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);
@ -274,17 +281,24 @@ public class MTMV extends OlapTable {
* 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 Map<String, String> getMvProperties() {