Skip to content

Commit

Permalink
rename vars/methods of cache mgr
Browse files Browse the repository at this point in the history
  • Loading branch information
dantengsky committed Jan 8, 2025
1 parent 7580cd9 commit 7f73bf9
Showing 1 changed file with 41 additions and 61 deletions.
102 changes: 41 additions & 61 deletions src/query/storages/common/cache/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl CacheManager {

// Cache of deserialized table data
let in_memory_table_data_cache =
Self::new_named_bytes_cache_slot(MEMORY_CACHE_TABLE_DATA, memory_cache_capacity);
Self::new_bytes_cache_slot(MEMORY_CACHE_TABLE_DATA, memory_cache_capacity);

// setup in-memory table meta cache
if !config.enable_table_meta_cache {
Expand All @@ -154,29 +154,29 @@ impl CacheManager {
block_meta_cache: CacheSlot::new(None),
}));
} else {
let table_snapshot_cache = Self::new_named_items_cache_slot(
config.table_meta_snapshot_count as usize,
let table_snapshot_cache = Self::new_items_cache_slot(
MEMORY_CACHE_TABLE_SNAPSHOT,
config.table_meta_snapshot_count as usize,
);
let table_statistic_cache = Self::new_named_items_cache_slot(
config.table_meta_statistic_count as usize,
let table_statistic_cache = Self::new_items_cache_slot(
MEMORY_CACHE_TABLE_STATISTICS,
config.table_meta_statistic_count as usize,
);
let compact_segment_info_cache = Self::new_named_bytes_cache_slot(
let compact_segment_info_cache = Self::new_bytes_cache_slot(
MEMORY_CACHE_COMPACT_SEGMENT_INFO,
config.table_meta_segment_bytes as usize,
);
let bloom_index_filter_cache = Self::new_named_bytes_cache_slot(
let bloom_index_filter_cache = Self::new_bytes_cache_slot(
MEMORY_CACHE_BLOOM_INDEX_FILTER,
config.table_bloom_index_filter_size as usize,
);
let bloom_index_meta_cache = Self::new_named_items_cache_slot(
config.table_bloom_index_meta_count as usize,
let bloom_index_meta_cache = Self::new_items_cache_slot(
MEMORY_CACHE_BLOOM_INDEX_FILE_META_DATA,
config.table_bloom_index_meta_count as usize,
);
let inverted_index_meta_cache = Self::new_named_items_cache_slot(
config.inverted_index_meta_count as usize,
let inverted_index_meta_cache = Self::new_items_cache_slot(
MEMORY_CACHE_INVERTED_INDEX_FILE_META_DATA,
config.inverted_index_meta_count as usize,
);

// setup in-memory inverted index filter cache
Expand All @@ -187,23 +187,23 @@ impl CacheManager {
} else {
config.inverted_index_filter_size as usize
};
let inverted_index_file_cache = Self::new_named_bytes_cache_slot(
let inverted_index_file_cache = Self::new_bytes_cache_slot(
MEMORY_CACHE_INVERTED_INDEX_FILE,
inverted_index_file_size,
);
let prune_partitions_cache = Self::new_named_items_cache_slot(
config.table_prune_partitions_count as usize,
let prune_partitions_cache = Self::new_items_cache_slot(
MEMORY_CACHE_PRUNE_PARTITIONS,
config.table_prune_partitions_count as usize,
);

let parquet_meta_data_cache = Self::new_named_items_cache_slot(
DEFAULT_PARQUET_META_DATA_CACHE_ITEMS,
let parquet_meta_data_cache = Self::new_items_cache_slot(
MEMORY_CACHE_PARQUET_META_DATA,
DEFAULT_PARQUET_META_DATA_CACHE_ITEMS,
);

let block_meta_cache = Self::new_named_items_cache_slot(
config.block_meta_count as usize,
let block_meta_cache = Self::new_items_cache_slot(
MEMORY_CACHE_BLOCK_META,
config.block_meta_count as usize,
);

GlobalInstance::set(Arc::new(Self {
Expand Down Expand Up @@ -237,61 +237,41 @@ impl CacheManager {
match name {
MEMORY_CACHE_TABLE_DATA => {
let cache = &self.in_memory_table_data_cache;
Self::set_named_cache_bytes_capacity(cache, new_capacity, name);
Self::set_bytes_capacity(cache, new_capacity, name);
}
MEMORY_CACHE_PARQUET_META_DATA => {
let cache = &self.parquet_meta_data_cache;
Self::set_named_cache_items_capacity(cache, new_capacity, name)
Self::set_items_capacity(cache, new_capacity, name)
}
MEMORY_CACHE_PRUNE_PARTITIONS => {
let cache = &self.prune_partitions_cache;
Self::set_named_cache_items_capacity(cache, new_capacity, name)
Self::set_items_capacity(cache, new_capacity, name)
}
MEMORY_CACHE_INVERTED_INDEX_FILE => {
let cache = &self.inverted_index_file_cache;
Self::set_named_cache_bytes_capacity(cache, new_capacity, name);
Self::set_bytes_capacity(cache, new_capacity, name);
}
MEMORY_CACHE_INVERTED_INDEX_FILE_META_DATA => {
let cache = &self.inverted_index_meta_cache;
Self::set_named_cache_items_capacity(cache, new_capacity, name);
Self::set_items_capacity(cache, new_capacity, name);
}
MEMORY_CACHE_BLOOM_INDEX_FILE_META_DATA => {
Self::set_named_cache_items_capacity(
&self.bloom_index_meta_cache,
new_capacity,
name,
);
Self::set_items_capacity(&self.bloom_index_meta_cache, new_capacity, name);
}
MEMORY_CACHE_BLOOM_INDEX_FILTER => {
Self::set_named_cache_bytes_capacity(
&self.bloom_index_filter_cache,
new_capacity,
name,
);
Self::set_bytes_capacity(&self.bloom_index_filter_cache, new_capacity, name);
}
MEMORY_CACHE_COMPACT_SEGMENT_INFO => {
Self::set_named_cache_bytes_capacity(
&self.compact_segment_info_cache,
new_capacity,
name,
);
Self::set_bytes_capacity(&self.compact_segment_info_cache, new_capacity, name);
}
MEMORY_CACHE_TABLE_STATISTICS => {
Self::set_named_cache_items_capacity(
&self.table_statistic_cache,
new_capacity,
name,
);
Self::set_items_capacity(&self.table_statistic_cache, new_capacity, name);
}
MEMORY_CACHE_TABLE_SNAPSHOT => {
Self::set_named_cache_items_capacity(
&self.table_snapshot_cache,
new_capacity,
name,
);
Self::set_items_capacity(&self.table_snapshot_cache, new_capacity, name);
}
MEMORY_CACHE_BLOCK_META => {
Self::set_named_cache_items_capacity(&self.block_meta_cache, new_capacity, name);
Self::set_items_capacity(&self.block_meta_cache, new_capacity, name);
}

crate::DISK_TABLE_DATA_CACHE_NAME => {
Expand All @@ -305,28 +285,28 @@ impl CacheManager {
Ok(())
}

fn set_named_cache_bytes_capacity<T: Into<CacheValue<T>>>(
fn set_bytes_capacity<T: Into<CacheValue<T>>>(
cache: &CacheSlot<InMemoryLruCache<T>>,
new_capacity: u64,
name: impl Into<String>,
) {
if let Some(v) = cache.get() {
v.set_bytes_capacity(new_capacity as usize);
} else {
let new_cache = Self::new_named_bytes_cache(name, new_capacity as usize);
let new_cache = Self::new_bytes_cache(name, new_capacity as usize);
cache.set(new_cache)
}
}

fn set_named_cache_items_capacity<T: Into<CacheValue<T>>>(
fn set_items_capacity<T: Into<CacheValue<T>>>(
cache: &CacheSlot<InMemoryLruCache<T>>,
new_capacity: u64,
name: impl Into<String>,
) {
if let Some(v) = cache.get() {
v.set_items_capacity(new_capacity as usize);
} else {
let new_cache = Self::new_named_items_cache(new_capacity as usize, name);
let new_cache = Self::new_items_cache(name, new_capacity as usize);
cache.set(new_cache)
}
}
Expand Down Expand Up @@ -375,31 +355,31 @@ impl CacheManager {
self.in_memory_table_data_cache.get()
}

fn new_named_items_cache_slot<V: Into<CacheValue<V>>>(
capacity: usize,
fn new_items_cache_slot<V: Into<CacheValue<V>>>(
name: impl Into<String>,
capacity: usize,
) -> CacheSlot<InMemoryLruCache<V>> {
CacheSlot::new(Self::new_named_items_cache(capacity, name))
CacheSlot::new(Self::new_items_cache(name, capacity))
}

fn new_named_items_cache<V: Into<CacheValue<V>>>(
capacity: usize,
fn new_items_cache<V: Into<CacheValue<V>>>(
name: impl Into<String>,
capacity: usize,
) -> Option<InMemoryLruCache<V>> {
match capacity {
0 => None,
_ => Some(InMemoryLruCache::with_items_capacity(name.into(), capacity)),
}
}

fn new_named_bytes_cache_slot<V: Into<CacheValue<V>>>(
fn new_bytes_cache_slot<V: Into<CacheValue<V>>>(
name: impl Into<String>,
bytes_capacity: usize,
) -> CacheSlot<InMemoryLruCache<V>> {
CacheSlot::new(Self::new_named_bytes_cache(name, bytes_capacity))
CacheSlot::new(Self::new_bytes_cache(name, bytes_capacity))
}

fn new_named_bytes_cache<V: Into<CacheValue<V>>>(
fn new_bytes_cache<V: Into<CacheValue<V>>>(
name: impl Into<String>,
bytes_capacity: usize,
) -> Option<InMemoryLruCache<V>> {
Expand Down

0 comments on commit 7f73bf9

Please sign in to comment.