This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new 89ba95d6b48 branch-4.0: [fix](cache) invalidate sorted partition cache 
after replacing temp partition in cloud mode #60888 (#61093)
89ba95d6b48 is described below

commit 89ba95d6b4823096650e2c5309125d14de64f51e
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Mar 6 13:17:15 2026 +0800

    branch-4.0: [fix](cache) invalidate sorted partition cache after replacing 
temp partition in cloud mode #60888 (#61093)
    
    Cherry-picked from #60888
    
    Co-authored-by: hui lai <[email protected]>
---
 .../main/java/org/apache/doris/catalog/Env.java    | 14 ++++++
 .../cache/NereidsSortedPartitionsCacheManager.java |  5 ++
 .../cache/clear_sorted_partition_cache.groovy      | 55 ++++++++++++++++++++++
 3 files changed, 74 insertions(+)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index 7cfc38c0523..4a8ab20c1ff 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -6730,6 +6730,13 @@ public class Env {
         if (Config.isNotCloudMode()) {
             version = olapTable.getNextVersion();
             olapTable.updateVisibleVersionAndTime(version, versionTime);
+        } else {
+            // Invalidate sorted partition cache for this table to avoid stale 
cache after partition replacement.
+            // In non-cloud mode, the version update above would also trigger 
cache invalidation on next query,
+            // but in cloud mode, getVisibleVersion() fetches version from 
meta service via RPC,
+            // so the local version update may not be reflected. Explicit 
invalidation is needed.
+            Env.getCurrentEnv().getSortedPartitionsCacheManager()
+                    .invalidateTable(db.getCatalog().getName(), 
db.getFullName(), olapTable.getName());
         }
         // Here, we only wait for the EventProcessor to finish processing the 
event,
         // but regardless of the success or failure of the result,
@@ -6771,6 +6778,13 @@ public class Env {
             if (Config.isNotCloudMode()) {
                 
olapTable.updateVisibleVersionAndTime(replaceTempPartitionLog.getVersion(),
                         replaceTempPartitionLog.getVersionTime());
+            } else {
+                // Invalidate sorted partition cache for this table to avoid 
stale cache after partition replacement.
+                // In non-cloud mode, the version update above would also 
trigger cache invalidation on next query,
+                // but in cloud mode, getVisibleVersion() fetches version from 
meta service via RPC,
+                // so the local version update may not be reflected. Explicit 
invalidation is needed.
+                Env.getCurrentEnv().getSortedPartitionsCacheManager()
+                        .invalidateTable(db.getCatalog().getName(), 
db.getFullName(), olapTable.getName());
             }
         } catch (DdlException e) {
             throw new MetaNotFoundException(e);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/common/cache/NereidsSortedPartitionsCacheManager.java
 
b/fe/fe-core/src/main/java/org/apache/doris/common/cache/NereidsSortedPartitionsCacheManager.java
index 43a14834f55..2d670aa011e 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/common/cache/NereidsSortedPartitionsCacheManager.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/common/cache/NereidsSortedPartitionsCacheManager.java
@@ -66,6 +66,11 @@ public class NereidsSortedPartitionsCacheManager {
         this.partitionCaches.invalidateAll();
     }
 
+    public void invalidateTable(String catalog, String db, String table) {
+        TableIdentifier key = new TableIdentifier(catalog, db, table);
+        partitionCaches.invalidate(key);
+    }
+
     public Optional<SortedPartitionRanges<?>> get(
             SupportBinarySearchFilteringPartitions table, CatalogRelation 
scan) {
         ConnectContext connectContext = ConnectContext.get();
diff --git 
a/regression-test/suites/query_p0/cache/clear_sorted_partition_cache.groovy 
b/regression-test/suites/query_p0/cache/clear_sorted_partition_cache.groovy
new file mode 100644
index 00000000000..0881b71ab87
--- /dev/null
+++ b/regression-test/suites/query_p0/cache/clear_sorted_partition_cache.groovy
@@ -0,0 +1,55 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("clear_sorted_partition_cache") {
+    multi_sql """
+        set enable_sql_cache=false;
+        set enable_binary_search_filtering_partitions=true;
+        drop table if exists t_part_cache;
+        create table t_part_cache(
+            id int,
+            dt int
+        )
+        partition by range(dt) (
+            partition p20250101 values [(20250101), (20250102))
+        )
+        distributed by hash(id)
+        properties("replication_num" = "1");
+        alter table t_part_cache add temporary partition tp20250101 values 
[(20250101), (20250102));
+        insert into t_part_cache temporary partition (tp20250101) select 1, 
20250101;
+        """
+    // wait cache valid
+    sleep(10000)
+    // query the original empty partition to populate the sorted partition 
cache
+    test {
+        sql """
+        select *
+        from t_part_cache
+        where dt = '20250101'
+        """
+        rowNum 0
+    }
+    sql "alter table t_part_cache replace partition p20250101 WITH TEMPORARY 
PARTITION tp20250101;"
+    test {
+        sql """
+        select *
+        from t_part_cache
+        where dt = '20250101'
+        """
+        rowNum 1
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to