Skip to content
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
12 changes: 8 additions & 4 deletions be/src/io/cache/block_file_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ void BlockFileCache::use_cell(const FileBlockCell& cell, FileBlocks* result, boo
/// Move to the end of the queue. The iterator remains valid.
if (cell.queue_iterator && move_iter_flag) {
queue.move_to_end(*cell.queue_iterator, cache_lock);
_lru_recorder->record_queue_event(cell.file_block->cache_type(),
CacheLRULogType::MOVETOBACK, cell.file_block->_key.hash,
cell.file_block->_key.offset, cell.size());
}
_lru_recorder->record_queue_event(cell.file_block->cache_type(), CacheLRULogType::MOVETOBACK,
cell.file_block->_key.hash, cell.file_block->_key.offset,
cell.size());

cell.update_atime();
}
Expand Down Expand Up @@ -1546,7 +1546,11 @@ bool LRUQueue::contains(const UInt128Wrapper& hash, size_t offset,

LRUQueue::Iterator LRUQueue::get(const UInt128Wrapper& hash, size_t offset,
std::lock_guard<std::mutex>& /* cache_lock */) const {
return map.find(std::make_pair(hash, offset))->second;
auto itr = map.find(std::make_pair(hash, offset));
if (itr != map.end()) {
return itr->second;
}
return std::list<FileKeyAndOffset>::iterator();
}

std::string LRUQueue::to_string(std::lock_guard<std::mutex>& /* cache_lock */) const {
Expand Down
12 changes: 6 additions & 6 deletions be/src/io/cache/lru_queue_recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void LRUQueueRecorder::record_queue_event(FileCacheType type, CacheLRULogType lo
const UInt128Wrapper hash, const size_t offset,
const size_t size) {
CacheLRULogQueue& log_queue = get_lru_log_queue(type);
log_queue.push_back(std::make_unique<CacheLRULog>(log_type, hash, offset, size));
log_queue.enqueue(std::make_unique<CacheLRULog>(log_type, hash, offset, size));
++(_lru_queue_update_cnt_from_last_dump[type]);
}

Expand All @@ -36,9 +36,8 @@ void LRUQueueRecorder::replay_queue_event(FileCacheType type) {
LRUQueue& shadow_queue = get_shadow_queue(type);

std::lock_guard<std::mutex> lru_log_lock(_mutex_lru_log);
while (!log_queue.empty()) {
auto log = std::move(log_queue.front());
log_queue.pop_front();
std::unique_ptr<CacheLRULog> log;
while (log_queue.try_dequeue(log)) {
try {
switch (log->type) {
case CacheLRULogType::ADD: {
Expand All @@ -47,16 +46,17 @@ void LRUQueueRecorder::replay_queue_event(FileCacheType type) {
}
case CacheLRULogType::REMOVE: {
auto it = shadow_queue.get(log->hash, log->offset, lru_log_lock);
if (it != shadow_queue.end()) {
if (it != std::list<LRUQueue::FileKeyAndOffset>::iterator()) {
shadow_queue.remove(it, lru_log_lock);
} else {
LOG(WARNING) << "REMOVE failed, doesn't exist in shadow queue";
}
break;
}
case CacheLRULogType::MOVETOBACK: {
LOG(INFO) << "MOVETOBACK" << log->hash.to_string() << " " << log->offset;
auto it = shadow_queue.get(log->hash, log->offset, lru_log_lock);
if (it != shadow_queue.end()) {
if (it != std::list<LRUQueue::FileKeyAndOffset>::iterator()) {
shadow_queue.move_to_end(it, lru_log_lock);
} else {
LOG(WARNING) << "MOVETOBACK failed, doesn't exist in shadow queue";
Expand Down
6 changes: 5 additions & 1 deletion be/src/io/cache/lru_queue_recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

#pragma once

#include <concurrentqueue.h>

#include <boost/lockfree/spsc_queue.hpp>

#include "io/cache/file_cache_common.h"

namespace doris::io {
Expand All @@ -40,7 +44,7 @@ struct CacheLRULog {
: type(t), hash(h), offset(o), size(s) {}
};

using CacheLRULogQueue = std::list<std::unique_ptr<CacheLRULog>>;
using CacheLRULogQueue = moodycamel::ConcurrentQueue<std::unique_ptr<CacheLRULog>>;

class LRUQueueRecorder {
public:
Expand Down
2 changes: 2 additions & 0 deletions be/test/io/cache/block_file_cache_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3909,6 +3909,7 @@ TEST_F(BlockFileCacheTest, cached_remote_file_reader_error_handle) {
}
EXPECT_TRUE(reader.close().ok());
EXPECT_TRUE(reader.closed());
std::this_thread::sleep_for(std::chrono::seconds(1));
if (fs::exists(cache_base_path)) {
fs::remove_all(cache_base_path);
}
Expand Down Expand Up @@ -3969,6 +3970,7 @@ TEST_F(BlockFileCacheTest, cached_remote_file_reader_init) {
CachedRemoteFileReader reader(local_reader, opts);
EXPECT_EQ(reader._cache->get_base_path(), cache_base_path);
}
std::this_thread::sleep_for(std::chrono::seconds(1));
if (fs::exists(cache_base_path)) {
fs::remove_all(cache_base_path);
}
Expand Down
16 changes: 8 additions & 8 deletions be/test/io/cache/block_file_cache_test_lru_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ TEST_F(BlockFileCacheTest, test_lru_log_record_replay_dump_restore) {
ASSERT_EQ(cache.get_stats_unsafe()["normal_queue_curr_size"], 500000);

// all queue are filled, let's check the lru log records
ASSERT_EQ(cache._lru_recorder->_ttl_lru_log_queue.size(), 5);
ASSERT_EQ(cache._lru_recorder->_index_lru_log_queue.size(), 5);
ASSERT_EQ(cache._lru_recorder->_normal_lru_log_queue.size(), 5);
ASSERT_EQ(cache._lru_recorder->_disposable_lru_log_queue.size(), 5);
ASSERT_EQ(cache._lru_recorder->_ttl_lru_log_queue.size_approx(), 5);
ASSERT_EQ(cache._lru_recorder->_index_lru_log_queue.size_approx(), 5);
ASSERT_EQ(cache._lru_recorder->_normal_lru_log_queue.size_approx(), 5);
ASSERT_EQ(cache._lru_recorder->_disposable_lru_log_queue.size_approx(), 5);

// then check the log replay
std::this_thread::sleep_for(std::chrono::milliseconds(
Expand All @@ -175,10 +175,10 @@ TEST_F(BlockFileCacheTest, test_lru_log_record_replay_dump_restore) {
context2); // move index queue 3rd element to the end
cache.remove_if_cached(key3); // remove all element from ttl queue
}
ASSERT_EQ(cache._lru_recorder->_ttl_lru_log_queue.size(), 5);
ASSERT_EQ(cache._lru_recorder->_index_lru_log_queue.size(), 1);
ASSERT_EQ(cache._lru_recorder->_normal_lru_log_queue.size(), 0);
ASSERT_EQ(cache._lru_recorder->_disposable_lru_log_queue.size(), 0);
ASSERT_EQ(cache._lru_recorder->_ttl_lru_log_queue.size_approx(), 5);
ASSERT_EQ(cache._lru_recorder->_index_lru_log_queue.size_approx(), 1);
ASSERT_EQ(cache._lru_recorder->_normal_lru_log_queue.size_approx(), 0);
ASSERT_EQ(cache._lru_recorder->_disposable_lru_log_queue.size_approx(), 0);

std::this_thread::sleep_for(std::chrono::milliseconds(
2 * config::file_cache_background_lru_log_replay_interval_ms));
Expand Down
Loading