github-actions[bot] commented on code in PR #61176:
URL: https://github.com/apache/doris/pull/61176#discussion_r3085284886


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java:
##########
@@ -446,6 +439,27 @@ public long getSchemaChangeVersion() {
         }
     }
 
+    /**
+     * Best-effort cache invalidation after metadata changes such as ADD/DROP 
CONSTRAINT.
+     * Concurrent queries may rebuild the cache again around this window, 
which is acceptable.
+     */
+    public void invalidateRewriteCache() {
+        writeMvLock();

Review Comment:
   `invalidateRewriteCache()` clears the fields under `mvRwLock`, but 
`getOrGenerateCache()` still builds a candidate cache outside that lock and 
later publishes it if the slot is `null`. That creates a stale-cache race:
   
   1. Thread A enters `getOrGenerateCache()`, sees `cache == null`, and starts 
building a cache from the old constraint metadata.
   2. Thread B executes `ADD/DROP CONSTRAINT`, calls 
`invalidateRewriteCache()`, and clears both cache fields.
   3. Thread A finishes building, reacquires `mvRwLock`, still sees `cache == 
null`, and stores the stale pre-DDL cache back into the MTMV.
   
   After that, rewrites can keep using old PK/FK/UK metadata until some later 
refresh/invalidation happens, which defeats the purpose of this PR.
   
   This needs a generation/version check (or equivalent) so a cache built 
before invalidation cannot be published afterward.



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