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,