This is an automated email from the ASF dual-hosted git repository. morrysnow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new e23696cd000 [enhance](mtmv) During cache generation, no longer hold the write lock for mtmv (#40402) e23696cd000 is described below commit e23696cd000b4e8834ee805d3520fe6af5db96b6 Author: zhangdong <493738...@qq.com> AuthorDate: Fri Sep 6 11:34:23 2024 +0800 [enhance](mtmv) During cache generation, no longer hold the write lock for mtmv (#40402) During cache generation, no longer hold the write Lock for mv to avoid changes in the logic of cache generation in the future, internal calls to other locks, and deadlocks --- .../main/java/org/apache/doris/catalog/MTMV.java | 47 ++++++++++++++-------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java index c3d36ea3971..3e60a489c93 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java @@ -176,6 +176,19 @@ 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() + && !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) { @@ -183,13 +196,8 @@ public class MTMV extends OlapTable { 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); @@ -268,17 +276,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 MTMVCache getCache() { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org