-
Notifications
You must be signed in to change notification settings - Fork 165
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 f420771
Showing
2 changed files
with
62 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,35 @@ | ||
#pragma once | ||
#include "rocksdb/cache.h" | ||
|
||
namespace rocksdb { | ||
namespace titandb { | ||
|
||
class PrioritizedCache : 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: | ||
// real insert function, it will check the cache ptr first | ||
Status CheckCacheAndInsert(const Slice& key, void* value, size_t charge, | ||
void (*deleter)(const Slice& key, void* value), | ||
Cache::Handle** handle); | ||
|
||
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,27 @@ | ||
#include "titan/prioritized_cache.h" | ||
|
||
namespace rocksdb { | ||
namespace titandb { | ||
|
||
PrioritizedCache::PrioritizedCache(std::shared_ptr<Cache> cache, | ||
Cache::Priority priority) | ||
: cache_(cache), priority_(priority) {} | ||
|
||
std::shared_ptr<Cache> PrioritizedCache::GetCache() { return cache_; } | ||
|
||
Status PrioritizedCache::CheckCacheAndInsert( | ||
const Slice& key, void* value, size_t charge, | ||
void (*deleter)(const Slice& key, void* value), Cache::Handle** handle) { | ||
if (!cache_) return Status::NotFound(); | ||
return cache_->Insert(key, value, charge, deleter, handle, priority_); | ||
} | ||
|
||
Status PrioritizedCache::Insert(const Slice& key, void* value, size_t charge, | ||
void (*deleter)(const Slice& key, void* value), | ||
Cache::Handle** handle, | ||
Cache::Priority /*priority*/) { | ||
return CheckCacheAndInsert(key, value, charge, deleter, handle); | ||
} | ||
|
||
} // namespace titandb | ||
} // namespace rocksdb |