Skip to content

Commit 63cf08b

Browse files
authored
chore: backport set cache capacity to rel/v1.2.636-rc8.2 (#17343)
* chore: bring back function `set_cache_capacity` (#17196) * chore:bring back func `set_cache_capacity` * test cases * revert config file * tweak test case * fix: use usize as bytes capacity * tweak lock scope * rename vars/methods of cache mgr * resovle pick conflicts * cargo fmt * tweak audit.toml, bypass RUSTSEC-2025-0001 * pin patched opendal to tag, instead of commit hash * taplo fmt * tweak golden file of ut test_caches_table
1 parent fdf4332 commit 63cf08b

File tree

15 files changed

+372
-76
lines changed

15 files changed

+372
-76
lines changed

.cargo/audit.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ ignore = [
5353
"RUSTSEC-2024-0399",
5454
# `idna` accepts Punycode labels that do not produce any non-ASCII when decoded
5555
"RUSTSEC-2024-0421",
56+
# gix-worktree-state nonexclusive checkout sets executable files world-writable
57+
"RUSTSEC-2025-0001",
5658
]

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ deltalake = { git = "https://github.com/delta-io/delta-rs", rev = "57795da" }
417417
ethnum = { git = "https://github.com/ariesdevil/ethnum-rs", rev = "4cb05f1" }
418418
openai_api_rust = { git = "https://github.com/datafuse-extras/openai-api", rev = "819a0ed" }
419419
# patched opendal which categories the XML dersierialization errors as recoverable
420-
opendal = { git = "https://github.com/datafuse-extras/opendal-for-release-v1.2.636", rev = "6c490a0" }
420+
opendal = { git = "https://github.com/datafuse-extras/opendal-for-release-v1.2.636", tag = "v0.49.0-xml-deser-retry" }
421421

422422
# till new version(> 0.7) of opensrv released, locked on commit hash
423423
opensrv-mysql = { git = "https://github.com/databendlabs/opensrv", rev = "6cbb806" }

src/common/cache/src/cache.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ pub trait Cache<K: Eq + Hash + MemSized, V: MemSized> {
7272

7373
fn items_capacity(&self) -> u64;
7474

75+
fn set_bytes_capacity(&mut self, capacity: usize);
76+
77+
fn set_items_capacity(&mut self, capacity: usize);
78+
7579
/// Returns the bytes size of all the key-value pairs in the cache.
7680
fn bytes_size(&self) -> u64;
7781

src/common/cache/src/cache/lru.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,20 @@ impl<K: Eq + Hash + MemSized, V: MemSized> Cache<K, V> for LruCache<K, V> {
301301
self.max_items as u64
302302
}
303303

304+
fn set_bytes_capacity(&mut self, max_bytes: usize) {
305+
while self.bytes > max_bytes || self.map.len() > self.max_items {
306+
self.pop_by_policy();
307+
}
308+
self.max_bytes = max_bytes;
309+
}
310+
311+
fn set_items_capacity(&mut self, max_items: usize) {
312+
while self.bytes > self.max_bytes || self.map.len() > max_items {
313+
self.pop_by_policy();
314+
}
315+
self.max_items = max_items;
316+
}
317+
304318
/// Returns the bytes size of all the key-value pairs in the cache.
305319
fn bytes_size(&self) -> u64 {
306320
self.bytes as u64

src/query/service/src/interpreters/access/privilege_access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const SYSTEM_TABLES_ALLOW_LIST: [&str; 19] = [
8484
];
8585

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

8989
impl PrivilegeAccess {
9090
pub fn create(ctx: Arc<QueryContext>) -> Box<dyn AccessChecker> {

src/query/service/src/table_functions/table_function_factory.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use databend_common_storages_fuse::table_functions::FuseColumnFunc;
2626
use databend_common_storages_fuse::table_functions::FuseEncodingFunc;
2727
use databend_common_storages_fuse::table_functions::FuseStatisticsFunc;
2828
use databend_common_storages_fuse::table_functions::FuseVacuumTemporaryTable;
29+
use databend_common_storages_fuse::table_functions::SetCacheCapacity;
2930
use databend_common_storages_fuse::table_functions::TableFunctionTemplate;
3031
use databend_common_storages_stream::stream_status_table_func::StreamStatusTable;
3132
use databend_storages_common_table_meta::table_id_ranges::SYS_TBL_FUC_ID_END;
@@ -136,6 +137,14 @@ impl TableFunctionFactory {
136137
),
137138
);
138139

140+
creators.insert(
141+
"set_cache_capacity".to_string(),
142+
(
143+
next_id(),
144+
Arc::new(TableFunctionTemplate::<SetCacheCapacity>::create),
145+
),
146+
);
147+
139148
creators.insert(
140149
"fuse_segment".to_string(),
141150
(

src/query/service/tests/it/storages/testdata/caches_table.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ DB.Table: 'system'.'caches', Table: caches-table_id:1, ver:0, Engine: SystemCach
99
| 'test-node' | 'memory_cache_compact_segment_info' | 0 | 0 | 1073741824 | 'bytes' | 0 | 0 | 0 |
1010
| 'test-node' | 'memory_cache_inverted_index_file' | 0 | 0 | 2147483648 | 'bytes' | 0 | 0 | 0 |
1111
| 'test-node' | 'memory_cache_inverted_index_file_meta_data' | 0 | 0 | 3000 | 'count' | 0 | 0 | 0 |
12-
| 'test-node' | 'memory_cache_parquet_file_meta' | 0 | 0 | 3000 | 'count' | 0 | 0 | 0 |
12+
| 'test-node' | 'memory_cache_parquet_meta_data' | 0 | 0 | 3000 | 'count' | 0 | 0 | 0 |
1313
| 'test-node' | 'memory_cache_prune_partitions' | 0 | 0 | 256 | 'count' | 0 | 0 | 0 |
1414
| 'test-node' | 'memory_cache_table_snapshot' | 0 | 0 | 256 | 'count' | 0 | 0 | 0 |
1515
| 'test-node' | 'memory_cache_table_statistics' | 0 | 0 | 256 | 'count' | 0 | 0 | 0 |

0 commit comments

Comments
 (0)