This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new a6cfe20cdb0 [enhance](mtmv) During cache generation, no longer hold
the write lock for mtmv (#40402)
a6cfe20cdb0 is described below
commit a6cfe20cdb0e746a38f5b28a12b4e981cc6d73f1
Author: zhangdong <[email protected]>
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 0bd11c40df3..f17e501a72a 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
@@ -177,6 +177,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) {
@@ -184,13 +197,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);
@@ -271,17 +279,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: [email protected]
For additional commands, e-mail: [email protected]