From b2df20a890f552740c4c0a3c043669489c8d7b75 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Tue, 18 Aug 2015 13:19:55 -0700 Subject: [PATCH] Make HashCuckooRep::ApproximateMemoryUsage() return reasonable estimation. Summary: HashCuckooRep::ApproximateMemoryUsage() previously return std::numeric_limits::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 --- util/hash_cuckoo_rep.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/util/hash_cuckoo_rep.cc b/util/hash_cuckoo_rep.cc index e632b2fa3..5f664847e 100644 --- a/util/hash_cuckoo_rep.cc +++ b/util/hash_cuckoo_rep.cc @@ -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::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::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,