Make HashCuckooRep::ApproximateMemoryUsage() return reasonable estimation.
Summary: HashCuckooRep::ApproximateMemoryUsage() previously return std::numeric_limits<size_t>::max() when it cannot accept more entries. This patch makes it return a more reasonable estimation. This change is necessary in order to make GetIntProperty("rocksdb.cur-size-all-mem-tables") handles HashCuckooRep properly in diff https://reviews.facebook.net/D44229. Test Plan: db_test Reviewers: sdong, anthony, IslamAbdelRahman, igor Reviewed By: igor Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D44241
This commit is contained in:
parent
601b1aaca0
commit
b2df20a890
@ -61,11 +61,13 @@ class HashCuckooRep : public MemTableRep {
|
||||
explicit HashCuckooRep(const MemTableRep::KeyComparator& compare,
|
||||
MemTableAllocator* allocator,
|
||||
const size_t bucket_count,
|
||||
const unsigned int hash_func_count)
|
||||
const unsigned int hash_func_count,
|
||||
const size_t approximate_entry_size)
|
||||
: MemTableRep(allocator),
|
||||
compare_(compare),
|
||||
allocator_(allocator),
|
||||
bucket_count_(bucket_count),
|
||||
approximate_entry_size_(approximate_entry_size),
|
||||
cuckoo_path_max_depth_(kDefaultCuckooPathMaxDepth),
|
||||
occupied_count_(0),
|
||||
hash_function_count_(hash_func_count),
|
||||
@ -98,15 +100,15 @@ class HashCuckooRep : public MemTableRep {
|
||||
// the current mem-table already contains the specified key.
|
||||
virtual void Insert(KeyHandle handle) override;
|
||||
|
||||
// This function returns std::numeric_limits<size_t>::max() in the following
|
||||
// three cases to disallow further write operations:
|
||||
// This function returns bucket_count_ * approximate_entry_size_ when any
|
||||
// of the followings happen to disallow further write operations:
|
||||
// 1. when the fullness reaches kMaxFullnes.
|
||||
// 2. when the backup_table_ is used.
|
||||
//
|
||||
// otherwise, this function will always return 0.
|
||||
virtual size_t ApproximateMemoryUsage() override {
|
||||
if (is_nearly_full_) {
|
||||
return std::numeric_limits<size_t>::max();
|
||||
return bucket_count_ * approximate_entry_size_;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -193,6 +195,8 @@ class HashCuckooRep : public MemTableRep {
|
||||
MemTableAllocator* const allocator_;
|
||||
// the number of hash bucket in the hash table.
|
||||
const size_t bucket_count_;
|
||||
// approximate size of each entry
|
||||
const size_t approximate_entry_size_;
|
||||
// the maxinum depth of the cuckoo path.
|
||||
const unsigned int cuckoo_path_max_depth_;
|
||||
// the current number of entries in cuckoo_array_ which has been occupied.
|
||||
@ -629,7 +633,8 @@ MemTableRep* HashCuckooRepFactory::CreateMemTableRep(
|
||||
hash_function_count = kMaxHashCount;
|
||||
}
|
||||
return new HashCuckooRep(compare, allocator, bucket_count,
|
||||
hash_function_count);
|
||||
hash_function_count,
|
||||
(average_data_size_ + pointer_size) / kFullness);
|
||||
}
|
||||
|
||||
MemTableRepFactory* NewHashCuckooRepFactory(size_t write_buffer_size,
|
||||
|
Loading…
x
Reference in New Issue
Block a user