924060929 commented on code in PR #70397:
URL: https://github.com/apache/doris/pull/70397#discussion_r4549460794


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java:
##########
@@ -424,38 +433,62 @@ public MTMVCache getOrGenerateCache(ConnectContext 
connectionContext) throws
         boolean sessionVarsMatch = 
SessionVarGuardRewriter.checkSessionVariablesMatch(
                 currentSessionVars, this.sessionVariables);
 
-        // Select appropriate cache based on session variable match
-        readMvLock();
-        try {
-            if (sessionVarsMatch && cacheWithoutGuard != null) {
-                return cacheWithoutGuard;
+        while (true) {
+            long cacheGeneration;
+            readMvLock();
+            try {
+                MTMVCache cached = sessionVarsMatch ? cacheWithoutGuard : 
cacheWithGuard;
+                if (cached != null) {
+                    return cached;
+                }
+                cacheGeneration = rewriteCacheGeneration;
+            } finally {
+                readMvUnlock();
             }
-            if (!sessionVarsMatch && cacheWithGuard != null) {
-                return cacheWithGuard;
+
+            // Build outside the MV lock to avoid nesting it with table locks 
during analysis.
+            MTMVCache generated = createRewriteCache(connectionContext, false, 
!sessionVarsMatch);
+            writeMvLock();
+            try {
+                if (cacheGeneration != rewriteCacheGeneration) {
+                    continue;

Review Comment:
   Confirmed and fixed in 7f74ff6730bedbc7567e37ff947d589e4e317e2d. The same 
repair is applied to branch-4.2 in 4dd904ad0a7e74f9ed416cd0cda93e31de6fa3f2.
   
   Automatic database object eviction now uses a lifecycle-only retirement 
path: local objects and typed engine entries are still cleaned up, but the 
eviction does not report a semantic database change. Explicit invalidation 
keeps the derived-cache notifications and final row-count fence. The shared 
reset/routing implementation is retained.
   
   Rewrite-cache construction is additionally bounded to four attempts. If real 
metadata changes keep invalidating the build, it throws the existing analysis 
exception; all production callers already catch that failure and skip the 
optional MV rewrite/statistics/traits.
   
   The new reproduction uses a real size-limited database MetaCache and a fresh 
StatementContext resolving two databases. Capacity one failed before the fix; 
capacity two is a passing control. Tests also cover automatic versus explicit 
removal and both MV cache variants. Before the production fix, six of eleven 
targeted tests failed. Afterward, both branches passed 192 focused FE tests 
(zero failures/errors/skips), FE builds and integrated Checkstyle.



-- 
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]

Reply via email to