voidBlockCache::put(int sst_id, int block_id, std::shared_ptr<Block> block){ std::lock_guard<std::mutex> lock(mutex_); auto key = std::make_pair(sst_id, block_id); auto it = cache_map_.find(key);
// 这里的 block_cache 就是我们实现的缓存池的指针 std::shared_ptr<Block> SST::read_block(size_t block_idx){ if (block_idx >= meta_entries.size()) { throw std::out_of_range("Block index out of range"); }
// 先从缓存中查找 if (block_cache != nullptr) { auto cache_ptr = block_cache->get(this->sst_id, block_idx); if (cache_ptr != nullptr) { return cache_ptr; } } else { throw std::runtime_error("Block cache not set"); }
$ time xmake run test_lsm [==========] Running 5 tests from 1 test suite. [----------] Global test environment set-up. [----------] 5 tests from LSMTest [ RUN ] LSMTest.BasicOperations [ OK ] LSMTest.BasicOperations (0 ms) [ RUN ] LSMTest.Persistence [ OK ] LSMTest.Persistence (533 ms) [ RUN ] LSMTest.LargeScaleOperations [ OK ] LSMTest.LargeScaleOperations (4 ms) [ RUN ] LSMTest.IteratorOperations [ OK ] LSMTest.IteratorOperations (0 ms) [ RUN ] LSMTest.MixedOperations [ OK ] LSMTest.MixedOperations (0 ms) [----------] 5 tests from LSMTest (539 ms total)
[----------] Global test environment tear-down [==========] 5 tests from 1 test suite ran. (539 ms total) [ PASSED ] 5 tests. xmake run test_lsm 0.61s user 0.01s system 98% cpu 0.629 total
$ time xmake run test_lsm [==========] Running 5 tests from 1 test suite. [----------] Global test environment set-up. [----------] 5 tests from LSMTest [ RUN ] LSMTest.BasicOperations [ OK ] LSMTest.BasicOperations (0 ms) [ RUN ] LSMTest.Persistence [ OK ] LSMTest.Persistence (1051 ms) [ RUN ] LSMTest.LargeScaleOperations [ OK ] LSMTest.LargeScaleOperations (4 ms) [ RUN ] LSMTest.IteratorOperations [ OK ] LSMTest.IteratorOperations (0 ms) [ RUN ] LSMTest.MixedOperations [ OK ] LSMTest.MixedOperations (0 ms) [----------] 5 tests from LSMTest (1057 ms total)
[----------] Global test environment tear-down [==========] 5 tests from 1 test suite ran. (1057 ms total) [ PASSED ] 5 tests. xmake run test_lsm 1.02s user 0.12s system 98% cpu 1.160 total