Skip to content

Commit

Permalink
refactor: use TableRouteCache instead
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed May 13, 2024
1 parent f212ef1 commit b15ad13
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 396 deletions.
21 changes: 2 additions & 19 deletions src/cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ use std::time::Duration;

use catalog::kvbackend::new_table_cache;
use common_meta::cache::{
new_composite_table_route_cache, new_table_flownode_set_cache, new_table_info_cache,
new_table_name_cache, new_table_route_cache, CacheRegistry, CacheRegistryBuilder,
LayeredCacheRegistryBuilder,
new_table_flownode_set_cache, new_table_info_cache, new_table_name_cache,
new_table_route_cache, CacheRegistry, CacheRegistryBuilder, LayeredCacheRegistryBuilder,
};
use common_meta::kv_backend::KvBackendRef;
use moka::future::CacheBuilder;
Expand All @@ -38,7 +37,6 @@ pub const TABLE_NAME_CACHE_NAME: &str = "table_name_cache";
pub const TABLE_CACHE_NAME: &str = "table_cache";
pub const TABLE_FLOWNODE_SET_CACHE_NAME: &str = "table_flownode_set_cache";
pub const TABLE_ROUTE_CACHE_NAME: &str = "table_route_cache";
pub const COMPOSITE_TABLE_ROUTE_CACHE: &str = "composite_table_route_cache";

pub fn build_fundamental_cache_registry(kv_backend: KvBackendRef) -> CacheRegistry {
// Builds table info cache
Expand Down Expand Up @@ -103,9 +101,6 @@ pub fn with_default_composite_cache_registry(
let table_name_cache = builder.get().context(error::CacheRequiredSnafu {
name: TABLE_NAME_CACHE_NAME,
})?;
let table_route_cache = builder.get().context(error::CacheRequiredSnafu {
name: TABLE_ROUTE_CACHE_NAME,
})?;

// Builds table cache
let cache = CacheBuilder::new(DEFAULT_CACHE_MAX_CAPACITY)
Expand All @@ -119,20 +114,8 @@ pub fn with_default_composite_cache_registry(
table_name_cache,
));

// Builds composite table route cache
let cache = CacheBuilder::new(DEFAULT_CACHE_MAX_CAPACITY)
.time_to_live(DEFAULT_CACHE_TTL)
.time_to_idle(DEFAULT_CACHE_TTI)
.build();
let composite_table_route_cache = Arc::new(new_composite_table_route_cache(
COMPOSITE_TABLE_ROUTE_CACHE.to_string(),
cache,
table_route_cache,
));

let registry = CacheRegistryBuilder::default()
.add_cache(table_cache)
.add_cache(composite_table_route_cache)
.build();

Ok(builder.add_cache_registry(registry))
Expand Down
6 changes: 3 additions & 3 deletions src/catalog/src/kvbackend/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use common_catalog::consts::{
};
use common_config::Mode;
use common_error::ext::BoxedError;
use common_meta::cache::CompositeTableRouteCacheRef;
use common_meta::cache::TableRouteCacheRef;
use common_meta::key::catalog_name::CatalogNameKey;
use common_meta::key::schema_name::SchemaNameKey;
use common_meta::key::table_info::TableInfoValue;
Expand Down Expand Up @@ -72,14 +72,14 @@ impl KvBackendCatalogManager {
meta_client: Option<Arc<MetaClient>>,
backend: KvBackendRef,
table_cache: TableCacheRef,
composite_table_route_cache: CompositeTableRouteCacheRef,
table_route_cache: TableRouteCacheRef,
) -> Arc<Self> {
Arc::new_cyclic(|me| Self {
mode,
meta_client,
partition_manager: Arc::new(PartitionRuleManager::new(
backend.clone(),
composite_table_route_cache,
table_route_cache,
)),
table_metadata_manager: Arc::new(TableMetadataManager::new(backend)),
system_catalog: SystemCatalog {
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use std::time::Duration;

use async_trait::async_trait;
use cache::{
build_fundamental_cache_registry, with_default_composite_cache_registry,
COMPOSITE_TABLE_ROUTE_CACHE, TABLE_CACHE_NAME,
build_fundamental_cache_registry, with_default_composite_cache_registry, TABLE_CACHE_NAME,
TABLE_ROUTE_CACHE_NAME,
};
use catalog::kvbackend::{CachedMetaKvBackendBuilder, KvBackendCatalogManager, MetaKvBackend};
use clap::Parser;
Expand Down Expand Up @@ -268,18 +268,18 @@ impl StartCommand {
.context(error::CacheRequiredSnafu {
name: TABLE_CACHE_NAME,
})?;
let composite_table_route_cache =
let table_route_cache =
layered_cache_registry
.get()
.context(error::CacheRequiredSnafu {
name: COMPOSITE_TABLE_ROUTE_CACHE,
name: TABLE_ROUTE_CACHE_NAME,
})?;
let catalog_manager = KvBackendCatalogManager::new(
opts.mode,
Some(meta_client.clone()),
cached_meta_backend.clone(),
table_cache,
composite_table_route_cache,
table_route_cache,
)
.await;

Expand Down
13 changes: 6 additions & 7 deletions src/cmd/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use std::{fs, path};

use async_trait::async_trait;
use cache::{
build_fundamental_cache_registry, with_default_composite_cache_registry,
COMPOSITE_TABLE_ROUTE_CACHE, TABLE_CACHE_NAME,
build_fundamental_cache_registry, with_default_composite_cache_registry, TABLE_CACHE_NAME,
TABLE_ROUTE_CACHE_NAME,
};
use catalog::kvbackend::KvBackendCatalogManager;
use clap::Parser;
Expand Down Expand Up @@ -399,16 +399,15 @@ impl StartCommand {
let table_cache = layered_cache_registry.get().context(CacheRequiredSnafu {
name: TABLE_CACHE_NAME,
})?;
let composite_table_route_cache =
layered_cache_registry.get().context(CacheRequiredSnafu {
name: COMPOSITE_TABLE_ROUTE_CACHE,
})?;
let table_route_cache = layered_cache_registry.get().context(CacheRequiredSnafu {
name: TABLE_ROUTE_CACHE_NAME,
})?;
let catalog_manager = KvBackendCatalogManager::new(
dn_opts.mode,
None,
kv_backend.clone(),
table_cache,
composite_table_route_cache,
table_route_cache,
)
.await;

Expand Down
7 changes: 3 additions & 4 deletions src/common/meta/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ pub use registry::{
LayeredCacheRegistryBuilder, LayeredCacheRegistryRef,
};
pub use table::{
new_composite_table_route_cache, new_table_info_cache, new_table_name_cache,
new_table_route_cache, CompositeTableRoute, CompositeTableRouteCache,
CompositeTableRouteCacheRef, TableInfoCache, TableInfoCacheRef, TableNameCache,
TableNameCacheRef, TableRouteCache, TableRouteCacheRef,
new_table_info_cache, new_table_name_cache, new_table_route_cache, TableInfoCache,
TableInfoCacheRef, TableNameCache, TableNameCacheRef, TableRoute, TableRouteCache,
TableRouteCacheRef,
};
5 changes: 0 additions & 5 deletions src/common/meta/src/cache/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod composite_table_route;
mod table_info;
mod table_name;
mod table_route;
pub use composite_table_route::{
new_composite_table_route_cache, CompositeTableRoute, CompositeTableRouteCache,
CompositeTableRouteCacheRef,
};
pub use table_info::{new_table_info_cache, TableInfoCache, TableInfoCacheRef};
pub use table_name::{new_table_name_cache, TableNameCache, TableNameCacheRef};
pub use table_route::{new_table_route_cache, TableRoute, TableRouteCache, TableRouteCacheRef};
Loading

0 comments on commit b15ad13

Please sign in to comment.