From 42eeeaa514684c9e370170449f36bd332efc0af5 Mon Sep 17 00:00:00 2001 From: Weny Xu Date: Thu, 4 Jun 2026 20:05:17 +0800 Subject: [PATCH] fix: avoid stale metadata cache after invalidation (#8235) Signed-off-by: WenyXu --- src/common/meta/src/cache/table/table_info.rs | 11 +++++++++-- src/partition/src/cache.rs | 7 +++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/common/meta/src/cache/table/table_info.rs b/src/common/meta/src/cache/table/table_info.rs index 97af5bcdb7..2d2dec347e 100644 --- a/src/common/meta/src/cache/table/table_info.rs +++ b/src/common/meta/src/cache/table/table_info.rs @@ -20,7 +20,7 @@ use snafu::OptionExt; use store_api::storage::TableId; use table::metadata::TableInfo; -use crate::cache::{CacheContainer, Initializer}; +use crate::cache::{CacheContainer, InitStrategy, Initializer}; use crate::error; use crate::error::Result; use crate::instruction::CacheIdent; @@ -41,7 +41,14 @@ pub fn new_table_info_cache( let table_info_manager = Arc::new(TableInfoManager::new(kv_backend)); let init = init_factory(table_info_manager); - CacheContainer::new(name, cache, Box::new(invalidator), init, filter) + CacheContainer::with_strategy( + name, + cache, + Box::new(invalidator), + init, + filter, + InitStrategy::VersionChecked, + ) } fn init_factory(table_info_manager: TableInfoManagerRef) -> Initializer> { diff --git a/src/partition/src/cache.rs b/src/partition/src/cache.rs index 4066b69aa3..0823e6ddf6 100644 --- a/src/partition/src/cache.rs +++ b/src/partition/src/cache.rs @@ -16,7 +16,9 @@ use std::sync::Arc; use common_base::hash::partition_expr_version; use common_error::ext::BoxedError; -use common_meta::cache::{CacheContainer, Initializer, TableRoute, TableRouteCacheRef}; +use common_meta::cache::{ + CacheContainer, InitStrategy, Initializer, TableRoute, TableRouteCacheRef, +}; use common_meta::instruction::CacheIdent; use common_meta::rpc::router::RegionRoute; use moka::future::Cache; @@ -118,7 +120,7 @@ pub fn new_partition_info_cache( cache: Cache, table_route_cache: TableRouteCacheRef, ) -> PartitionInfoCache { - CacheContainer::new( + CacheContainer::with_strategy( name, cache, Box::new(|cache, idents| { @@ -133,6 +135,7 @@ pub fn new_partition_info_cache( }), init_factory(table_route_cache), |ident| matches!(ident, CacheIdent::TableId(_)), + InitStrategy::VersionChecked, ) }