Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bring back function set_cache_capacity #17196

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/common/cache/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ pub trait Cache<K: Eq + Hash + MemSized, V: MemSized> {

fn items_capacity(&self) -> u64;

fn set_bytes_capacity(&mut self, capacity: usize);

fn set_items_capacity(&mut self, capacity: usize);

/// Returns the bytes size of all the key-value pairs in the cache.
fn bytes_size(&self) -> u64;

Expand Down
14 changes: 14 additions & 0 deletions src/common/cache/src/cache/lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,20 @@ impl<K: Eq + Hash + MemSized, V: MemSized> Cache<K, V> for LruCache<K, V> {
self.max_items as u64
}

fn set_bytes_capacity(&mut self, max_bytes: usize) {
while self.bytes > max_bytes || self.map.len() > self.max_items {
self.pop_by_policy();
}
self.max_bytes = max_bytes;
}

fn set_items_capacity(&mut self, max_items: usize) {
while self.bytes > self.max_bytes || self.map.len() > max_items {
self.pop_by_policy();
}
self.max_items = max_items;
}

/// Returns the bytes size of all the key-value pairs in the cache.
fn bytes_size(&self) -> u64 {
self.bytes as u64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ enum ObjectId {
}

// table functions that need `Super` privilege
const SYSTEM_TABLE_FUNCTIONS: [&str; 1] = ["fuse_amend"];
const SYSTEM_TABLE_FUNCTIONS: [&str; 2] = ["fuse_amend", "set_cache_capacity"];

impl PrivilegeAccess {
pub fn create(ctx: Arc<QueryContext>) -> Box<dyn AccessChecker> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use databend_common_storages_fuse::table_functions::FuseEncodingFunc;
use databend_common_storages_fuse::table_functions::FuseStatisticsFunc;
use databend_common_storages_fuse::table_functions::FuseTimeTravelSizeFunc;
use databend_common_storages_fuse::table_functions::FuseVacuumTemporaryTable;
use databend_common_storages_fuse::table_functions::SetCacheCapacity;
use databend_common_storages_fuse::table_functions::TableFunctionTemplate;
use databend_common_storages_stream::stream_status_table_func::StreamStatusTable;
use databend_storages_common_table_meta::table_id_ranges::SYS_TBL_FUC_ID_END;
Expand Down Expand Up @@ -138,6 +139,14 @@ impl TableFunctionFactory {
),
);

creators.insert(
"set_cache_capacity".to_string(),
(
next_id(),
Arc::new(TableFunctionTemplate::<SetCacheCapacity>::create),
),
);

creators.insert(
"fuse_segment".to_string(),
(
Expand Down
Loading
Loading