Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for secondary cache in LRUCache #8271

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix rebase
  • Loading branch information
anand76 committed May 13, 2021
commit 9e69439adebc41f6b9cf3b884574256bce866a67
15 changes: 8 additions & 7 deletions cache/lru_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ void LRUCacheShard::ApplyToSomeEntries(

table_.ApplyToEntriesRange(
[callback](LRUHandle* h) {
callback(h->key(), h->value, h->charge, h->deleter);
DeleterFn deleter = h->IsSecondaryCacheCompatible()
? h->info_.helper->del_cb
: h->info_.deleter;
callback(h->key(), h->value, h->charge, deleter);
},
index_begin, index_end);
}
Expand Down Expand Up @@ -589,12 +592,10 @@ LRUCache::LRUCache(size_t capacity, int num_shard_bits,
port::cacheline_aligned_alloc(sizeof(LRUCacheShard) * num_shards_));
size_t per_shard = (capacity + (num_shards_ - 1)) / num_shards_;
for (int i = 0; i < num_shards_; i++) {
new (&shards_[i])
LRUCacheShard(per_shard, strict_capacity_limit, high_pri_pool_ratio,
use_adaptive_mutex, metadata_charge_policy,
/* max_upper_hash_bits */ 32 - num_shard_bits);
use_adaptive_mutex, metadata_charge_policy,
secondary_cache);
new (&shards_[i]) LRUCacheShard(
per_shard, strict_capacity_limit, high_pri_pool_ratio,
use_adaptive_mutex, metadata_charge_policy,
/* max_upper_hash_bits */ 32 - num_shard_bits, secondary_cache);
}
}

Expand Down
8 changes: 4 additions & 4 deletions cache/lru_cache_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class LRUCacheTest : public testing::Test {
DeleteCache();
cache_ = reinterpret_cast<LRUCacheShard*>(
port::cacheline_aligned_alloc(sizeof(LRUCacheShard)));
new (cache_)
LRUCacheShard(capacity, false /*strict_capcity_limit*/,
high_pri_pool_ratio, use_adaptive_mutex,
kDontChargeCacheMetadata, nullptr /*secondary_cache*/);
new (cache_) LRUCacheShard(
capacity, false /*strict_capcity_limit*/, high_pri_pool_ratio,
use_adaptive_mutex, kDontChargeCacheMetadata,
24 /*max_upper_hash_bits*/, nullptr /*secondary_cache*/);
}

void Insert(const std::string& key,
Expand Down
14 changes: 5 additions & 9 deletions include/rocksdb/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,18 @@ class Cache {
using SaveToCallback = Status (*)(void* obj, size_t offset, size_t size,
void* out);

// DeletionCallback is a function pointer that deletes the cached
// object. The signature matches the old deleter function.
using DeletionCallback = void (*)(const Slice&, void*);
// A function pointer type for custom destruction of an entry's
// value. The Cache is responsible for copying and reclaiming space
// for the key, but values are managed by the caller.
using DeleterFn = void (*)(const Slice& key, void* value);

// A struct with pointers to helper functions for spilling items from the
// cache into the secondary cache. May be extended in the future. An
// instance of this struct is expected to outlive the cache.
struct CacheItemHelper {
SizeCallback size_cb;
anand1976 marked this conversation as resolved.
Show resolved Hide resolved
SaveToCallback saveto_cb;
DeletionCallback del_cb;
DeleterFn del_cb;
};

// The CreateCallback is passed by the block cache user to Lookup(). It
Expand Down Expand Up @@ -232,11 +233,6 @@ class Cache {
// Opaque handle to an entry stored in the cache.
struct Handle {};

// A function pointer type for custom destruction of an entry's
// value. The Cache is responsible for copying and reclaiming space
// for the key, but values are managed by the caller.
using DeleterFn = void (*)(const Slice& key, void* value);

// The type of the Cache
virtual const char* Name() const = 0;

Expand Down