-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: haoxiang47 <[email protected]>
- Loading branch information
1 parent
4dc4ba8
commit 52ad7c3
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
#include "rocksdb/cache.h" | ||
|
||
namespace rocksdb { | ||
namespace titandb { | ||
|
||
class PrioritizedCache : public Cache { | ||
public: | ||
// Constructs a PrioritizedCache, which is a wrapper | ||
// of rocksdb Cache | ||
PrioritizedCache(std::shared_ptr<Cache> cache, Cache::Priority priority); | ||
~PrioritizedCache(); | ||
|
||
// Get the Cache ptr | ||
std::shared_ptr<Cache> GetCache(); | ||
|
||
// always insert into the cache with the priority when init, | ||
// regardless of user provided option | ||
Status Insert(const Slice& key, void* value, size_t charge, | ||
void (*deleter)(const Slice& key, void* value), | ||
Cache::Handle** handle, Cache::Priority /*priority*/) override; | ||
|
||
private: | ||
std::shared_ptr<Cache> cache_; | ||
Cache::Priority priority_; | ||
}; | ||
|
||
} // namespace titandb | ||
} // namespace rocksdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "titan/prioritized_cache.h" | ||
|
||
namespace rocksdb { | ||
namespace titandb { | ||
|
||
PrioritizedCache::PrioritizedCache(std::shared_ptr<Cache> cache, | ||
Cache::Priority priority) | ||
: cache_(cache), priority_(priority) {} | ||
|
||
PrioritizedCache::~PrioritizedCache() {} | ||
|
||
std::shared_ptr<Cache> PrioritizedCache::GetCache() { return cache_; } | ||
|
||
Status PrioritizedCache::Insert(const Slice& key, void* value, size_t charge, | ||
void (*deleter)(const Slice& key, void* value), | ||
Cache::Handle** handle, | ||
Cache::Priority /*priority*/) { | ||
assert(cache_); | ||
return cache_->Insert(key, value, charge, deleter, handle, priority_); | ||
} | ||
|
||
} // namespace titandb | ||
} // namespace rocksdb |