@@ -261,7 +261,7 @@ FileBlocks BlockFileCache::get_impl(const UInt128Wrapper& hash, const CacheConte
261
261
// / find list [block1, ..., blockN] of blocks which intersect with given range.
262
262
auto it = _files.find (hash);
263
263
if (it == _files.end ()) {
264
- if (_lazy_open_done ) {
264
+ if (_async_open_done ) {
265
265
return {};
266
266
}
267
267
FileCacheKey key;
@@ -285,11 +285,10 @@ FileBlocks BlockFileCache::get_impl(const UInt128Wrapper& hash, const CacheConte
285
285
if (!st.ok ()) {
286
286
LOG_WARNING (" Failed to change key meta" ).error (st);
287
287
}
288
- }
289
- for (auto & [_, cell] : file_blocks) {
288
+
290
289
FileCacheType origin_type = cell.file_block ->cache_type ();
291
290
if (origin_type == FileCacheType::TTL) continue ;
292
- Status st = cell.file_block ->change_cache_type_by_mgr (FileCacheType::TTL);
291
+ st = cell.file_block ->change_cache_type_between_ttl_and_others (FileCacheType::TTL);
293
292
if (st.ok ()) {
294
293
auto & queue = get_queue (origin_type);
295
294
queue.remove (cell.queue_iterator .value (), cache_lock);
@@ -309,6 +308,7 @@ FileBlocks BlockFileCache::get_impl(const UInt128Wrapper& hash, const CacheConte
309
308
_time_to_key.insert (std::make_pair (context.expiration_time , hash));
310
309
}
311
310
if (auto iter = _key_to_time.find (hash);
311
+ // TODO(zhengyu): Why the hell the type is NORMAL while context set expiration_time?
312
312
(context.cache_type == FileCacheType::NORMAL || context.cache_type == FileCacheType::TTL) &&
313
313
iter != _key_to_time.end () && iter->second != context.expiration_time ) {
314
314
// remove from _time_to_key
@@ -330,7 +330,8 @@ FileBlocks BlockFileCache::get_impl(const UInt128Wrapper& hash, const CacheConte
330
330
for (auto & [_, cell] : file_blocks) {
331
331
auto cache_type = cell.file_block ->cache_type ();
332
332
if (cache_type != FileCacheType::TTL) continue ;
333
- auto st = cell.file_block ->change_cache_type_by_mgr (FileCacheType::NORMAL);
333
+ auto st = cell.file_block ->change_cache_type_between_ttl_and_others (
334
+ FileCacheType::NORMAL);
334
335
if (st.ok ()) {
335
336
if (config::enable_ttl_cache_evict_using_lru) {
336
337
auto & ttl_queue = get_queue (FileCacheType::TTL);
@@ -699,9 +700,9 @@ BlockFileCache::FileBlockCell* BlockFileCache::add_cell(const UInt128Wrapper& ha
699
700
FileBlockCell cell (std::make_shared<FileBlock>(key, size, this , state), cache_lock);
700
701
Status st;
701
702
if (context.expiration_time == 0 && context.cache_type == FileCacheType::TTL) {
702
- st = cell.file_block ->change_cache_type_by_mgr (FileCacheType::NORMAL);
703
+ st = cell.file_block ->change_cache_type_between_ttl_and_others (FileCacheType::NORMAL);
703
704
} else if (context.cache_type != FileCacheType::TTL && context.expiration_time != 0 ) {
704
- st = cell.file_block ->change_cache_type_by_mgr (FileCacheType::TTL);
705
+ st = cell.file_block ->change_cache_type_between_ttl_and_others (FileCacheType::TTL);
705
706
}
706
707
if (!st.ok ()) {
707
708
LOG (WARNING) << " Cannot change cache type. expiration_time=" << context.expiration_time
@@ -912,8 +913,8 @@ bool BlockFileCache::try_reserve_for_ttl(size_t size, std::lock_guard<std::mutex
912
913
bool BlockFileCache::try_reserve (const UInt128Wrapper& hash, const CacheContext& context,
913
914
size_t offset, size_t size,
914
915
std::lock_guard<std::mutex>& cache_lock) {
915
- if (!_lazy_open_done ) {
916
- return try_reserve_for_lazy_load (size, cache_lock);
916
+ if (!_async_open_done ) {
917
+ return try_reserve_during_async_load (size, cache_lock);
917
918
}
918
919
919
920
// use this strategy in scenarios where there is insufficient disk capacity or insufficient number of inodes remaining
@@ -1022,10 +1023,10 @@ bool BlockFileCache::remove_if_ttl_file_unlock(const UInt128Wrapper& file_key, b
1022
1023
LOG_WARNING (" Failed to update expiration time to 0" ).error (st);
1023
1024
}
1024
1025
}
1025
- }
1026
- for (auto & [_, cell] : _files[file_key]) {
1026
+
1027
1027
if (cell.file_block ->cache_type () == FileCacheType::NORMAL) continue ;
1028
- auto st = cell.file_block ->change_cache_type_by_mgr (FileCacheType::NORMAL);
1028
+ auto st = cell.file_block ->change_cache_type_between_ttl_and_others (
1029
+ FileCacheType::NORMAL);
1029
1030
if (st.ok ()) {
1030
1031
if (config::enable_ttl_cache_evict_using_lru) {
1031
1032
ttl_queue.remove (cell.queue_iterator .value (), cache_lock);
@@ -1396,6 +1397,21 @@ std::string BlockFileCache::dump_structure_unlocked(const UInt128Wrapper& hash,
1396
1397
return result.str ();
1397
1398
}
1398
1399
1400
+ std::string BlockFileCache::dump_single_cache_type (const UInt128Wrapper& hash, size_t offset) {
1401
+ std::lock_guard cache_lock (_mutex);
1402
+ return dump_single_cache_type_unlocked (hash, offset, cache_lock);
1403
+ }
1404
+
1405
+ std::string BlockFileCache::dump_single_cache_type_unlocked (const UInt128Wrapper& hash,
1406
+ size_t offset,
1407
+ std::lock_guard<std::mutex>&) {
1408
+ std::stringstream result;
1409
+ const auto & cells_by_offset = _files[hash];
1410
+ const auto & cell = cells_by_offset.find (offset);
1411
+
1412
+ return cache_type_to_string (cell->second .file_block ->cache_type ());
1413
+ }
1414
+
1399
1415
void BlockFileCache::change_cache_type (const UInt128Wrapper& hash, size_t offset,
1400
1416
FileCacheType new_type,
1401
1417
std::lock_guard<std::mutex>& cache_lock) {
@@ -1621,11 +1637,10 @@ void BlockFileCache::modify_expiration_time(const UInt128Wrapper& hash,
1621
1637
if (!st.ok ()) {
1622
1638
LOG_WARNING (" " ).error (st);
1623
1639
}
1624
- }
1625
- for (auto & [_, cell] : iter->second ) {
1640
+
1626
1641
FileCacheType origin_type = cell.file_block ->cache_type ();
1627
1642
if (origin_type == FileCacheType::TTL) continue ;
1628
- auto st = cell.file_block ->change_cache_type_by_mgr (FileCacheType::TTL);
1643
+ st = cell.file_block ->change_cache_type_between_ttl_and_others (FileCacheType::TTL);
1629
1644
if (st.ok ()) {
1630
1645
auto & queue = get_queue (origin_type);
1631
1646
queue.remove (cell.queue_iterator .value (), cache_lock);
@@ -1672,8 +1687,8 @@ BlockFileCache::get_hot_blocks_meta(const UInt128Wrapper& hash) const {
1672
1687
return blocks_meta;
1673
1688
}
1674
1689
1675
- bool BlockFileCache::try_reserve_for_lazy_load (size_t size,
1676
- std::lock_guard<std::mutex>& cache_lock) {
1690
+ bool BlockFileCache::try_reserve_during_async_load (size_t size,
1691
+ std::lock_guard<std::mutex>& cache_lock) {
1677
1692
size_t removed_size = 0 ;
1678
1693
size_t normal_queue_size = _normal_queue.get_capacity (cache_lock);
1679
1694
size_t disposable_queue_size = _disposable_queue.get_capacity (cache_lock);
0 commit comments