Limit LRU cache size

This commit is contained in:
Marcus Holland-Moritz 2020-12-17 21:36:54 +01:00
parent ed24a60062
commit 629f3a4177

View File

@ -268,7 +268,11 @@ class block_cache_ : public block_cache::impl {
void set_block_size(size_t size) override { void set_block_size(size_t size) override {
// XXX: This currently inevitably clears the cache // XXX: This currently inevitably clears the cache
auto max_blocks = std::max<size_t>(options_.max_bytes / size, 1); auto max_blocks = std::max<size_t>(options_.max_bytes / size, 1);
{
if (!block_.empty() && max_blocks > block_.size()) {
max_blocks = block_.size();
}
std::lock_guard<std::mutex> lock(mx_); std::lock_guard<std::mutex> lock(mx_);
cache_.~lru_type(); cache_.~lru_type();
new (&cache_) lru_type(max_blocks); new (&cache_) lru_type(max_blocks);
@ -282,7 +286,6 @@ class block_cache_ : public block_cache::impl {
update_block_stats(*block); update_block_stats(*block);
}); });
} }
}
std::future<block_range> std::future<block_range>
get(size_t block_no, size_t offset, size_t size) const override { get(size_t block_no, size_t offset, size_t size) const override {