github-actions[bot] commented on code in PR #70397:
URL: https://github.com/apache/doris/pull/70397#discussion_r4548622049
##########
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:
[P2] Bound retries when cache construction invalidates its generation
With `materialized_view_rewrite_enable_contain_external_table=true`,
`max_meta_object_cache_num=1`, and an eligible MV joining tables in two
databases of the same external catalog, each `createRewriteCache()` creates a
fresh `StatementContext` and resolves both DBs. The resulting DB-object
eviction synchronously calls `handleDatabaseMetaCacheRemoval ->
resetMetaToUninitialized -> invalidateDb(ExternalDatabase)`, whose new
`onDatabaseChanged` callback invalidates this MV and advances
`rewriteCacheGeneration`. The successful build therefore takes this `continue`,
and the next attempt repeats the eviction even without DDL. A query considering
the MV can remain in planning indefinitely because this loop has no cumulative
retry/deadline check. Bound retries and let the caller skip the optional MV
rewrite when they cannot stabilize, or avoid invalidating rewrite plans for
ordinary capacity eviction. Cover a cross-database MV with the DB-object cache
smaller than its dependency count.
--
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]