2017-06-02 21:13:59 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2017-06-02 21:13:59 +00:00
|
|
|
//
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
|
|
|
#include "rocksdb/write_buffer_manager.h"
|
2022-10-28 20:16:50 +00:00
|
|
|
|
2019-05-30 18:21:38 +00:00
|
|
|
#include "test_util/testharness.h"
|
2017-06-02 21:13:59 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2017-06-02 21:13:59 +00:00
|
|
|
class WriteBufferManagerTest : public testing::Test {};
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
2021-01-26 06:07:26 +00:00
|
|
|
const size_t kSizeDummyEntry = 256 * 1024;
|
|
|
|
|
2017-06-02 21:13:59 +00:00
|
|
|
TEST_F(WriteBufferManagerTest, ShouldFlush) {
|
2017-06-21 17:28:54 +00:00
|
|
|
// A write buffer manager of size 10MB
|
2017-06-02 21:13:59 +00:00
|
|
|
std::unique_ptr<WriteBufferManager> wbf(
|
|
|
|
new WriteBufferManager(10 * 1024 * 1024));
|
|
|
|
|
|
|
|
wbf->ReserveMem(8 * 1024 * 1024);
|
|
|
|
ASSERT_FALSE(wbf->ShouldFlush());
|
|
|
|
// 90% of the hard limit will hit the condition
|
|
|
|
wbf->ReserveMem(1 * 1024 * 1024);
|
|
|
|
ASSERT_TRUE(wbf->ShouldFlush());
|
2017-06-21 17:28:54 +00:00
|
|
|
// Scheduling for freeing will release the condition
|
2017-06-02 21:13:59 +00:00
|
|
|
wbf->ScheduleFreeMem(1 * 1024 * 1024);
|
|
|
|
ASSERT_FALSE(wbf->ShouldFlush());
|
|
|
|
|
|
|
|
wbf->ReserveMem(2 * 1024 * 1024);
|
|
|
|
ASSERT_TRUE(wbf->ShouldFlush());
|
2017-06-21 17:28:54 +00:00
|
|
|
|
|
|
|
wbf->ScheduleFreeMem(4 * 1024 * 1024);
|
|
|
|
// 11MB total, 6MB mutable. hard limit still hit
|
2017-06-02 21:13:59 +00:00
|
|
|
ASSERT_TRUE(wbf->ShouldFlush());
|
2017-06-21 17:28:54 +00:00
|
|
|
|
|
|
|
wbf->ScheduleFreeMem(2 * 1024 * 1024);
|
|
|
|
// 11MB total, 4MB mutable. hard limit stills but won't flush because more
|
|
|
|
// than half data is already being flushed.
|
|
|
|
ASSERT_FALSE(wbf->ShouldFlush());
|
|
|
|
|
|
|
|
wbf->ReserveMem(4 * 1024 * 1024);
|
|
|
|
// 15 MB total, 8MB mutable.
|
|
|
|
ASSERT_TRUE(wbf->ShouldFlush());
|
|
|
|
|
|
|
|
wbf->FreeMem(7 * 1024 * 1024);
|
2021-03-03 22:19:21 +00:00
|
|
|
// 8MB total, 8MB mutable.
|
|
|
|
ASSERT_FALSE(wbf->ShouldFlush());
|
|
|
|
|
|
|
|
// change size: 8M limit, 7M mutable limit
|
|
|
|
wbf->SetBufferSize(8 * 1024 * 1024);
|
|
|
|
// 8MB total, 8MB mutable.
|
|
|
|
ASSERT_TRUE(wbf->ShouldFlush());
|
|
|
|
|
|
|
|
wbf->ScheduleFreeMem(2 * 1024 * 1024);
|
|
|
|
// 8MB total, 6MB mutable.
|
|
|
|
ASSERT_TRUE(wbf->ShouldFlush());
|
|
|
|
|
|
|
|
wbf->FreeMem(2 * 1024 * 1024);
|
|
|
|
// 6MB total, 6MB mutable.
|
|
|
|
ASSERT_FALSE(wbf->ShouldFlush());
|
|
|
|
|
|
|
|
wbf->ReserveMem(1 * 1024 * 1024);
|
|
|
|
// 7MB total, 7MB mutable.
|
|
|
|
ASSERT_FALSE(wbf->ShouldFlush());
|
|
|
|
|
|
|
|
wbf->ReserveMem(1 * 1024 * 1024);
|
|
|
|
// 8MB total, 8MB mutable.
|
|
|
|
ASSERT_TRUE(wbf->ShouldFlush());
|
|
|
|
|
|
|
|
wbf->ScheduleFreeMem(1 * 1024 * 1024);
|
|
|
|
wbf->FreeMem(1 * 1024 * 1024);
|
|
|
|
// 7MB total, 7MB mutable.
|
2017-06-02 21:13:59 +00:00
|
|
|
ASSERT_FALSE(wbf->ShouldFlush());
|
|
|
|
}
|
|
|
|
|
2022-05-17 22:01:51 +00:00
|
|
|
class ChargeWriteBufferTest : public testing::Test {};
|
|
|
|
|
|
|
|
TEST_F(ChargeWriteBufferTest, Basic) {
|
2021-08-24 19:42:31 +00:00
|
|
|
constexpr std::size_t kMetaDataChargeOverhead = 10000;
|
|
|
|
|
2019-09-16 22:14:51 +00:00
|
|
|
LRUCacheOptions co;
|
2017-06-02 21:13:59 +00:00
|
|
|
// 1GB cache
|
2019-09-16 22:14:51 +00:00
|
|
|
co.capacity = 1024 * 1024 * 1024;
|
|
|
|
co.num_shard_bits = 4;
|
|
|
|
co.metadata_charge_policy = kDontChargeCacheMetadata;
|
|
|
|
std::shared_ptr<Cache> cache = NewLRUCache(co);
|
2017-06-02 21:13:59 +00:00
|
|
|
// A write buffer manager of size 50MB
|
|
|
|
std::unique_ptr<WriteBufferManager> wbf(
|
|
|
|
new WriteBufferManager(50 * 1024 * 1024, cache));
|
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Allocate 333KB will allocate 512KB, memory_used_ = 333KB
|
2019-04-16 18:59:35 +00:00
|
|
|
wbf->ReserveMem(333 * 1024);
|
2021-08-24 19:42:31 +00:00
|
|
|
// 2 dummy entries are added for size 333 KB
|
2021-01-08 21:24:11 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 2 * kSizeDummyEntry);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 2 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(), 2 * 256 * 1024 + kMetaDataChargeOverhead);
|
2017-06-02 21:13:59 +00:00
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Allocate another 512KB, memory_used_ = 845KB
|
2019-04-16 18:59:35 +00:00
|
|
|
wbf->ReserveMem(512 * 1024);
|
2021-08-24 19:42:31 +00:00
|
|
|
// 2 more dummy entries are added for size 512 KB
|
|
|
|
// since ceil((memory_used_ - dummy_entries_in_cache_usage) % kSizeDummyEntry)
|
|
|
|
// = 2
|
2021-01-08 21:24:11 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 4 * kSizeDummyEntry);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 4 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(), 4 * 256 * 1024 + kMetaDataChargeOverhead);
|
2017-06-02 21:13:59 +00:00
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Allocate another 10MB, memory_used_ = 11085KB
|
2019-04-16 18:59:35 +00:00
|
|
|
wbf->ReserveMem(10 * 1024 * 1024);
|
2021-08-24 19:42:31 +00:00
|
|
|
// 40 more entries are added for size 10 * 1024 * 1024 KB
|
2021-01-08 21:24:11 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 44 * kSizeDummyEntry);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 44 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(), 44 * 256 * 1024 + kMetaDataChargeOverhead);
|
2017-06-02 21:13:59 +00:00
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Free 1MB, memory_used_ = 10061KB
|
|
|
|
// It will not cause any change in cache cost
|
|
|
|
// since memory_used_ > dummy_entries_in_cache_usage * (3/4)
|
|
|
|
wbf->FreeMem(1 * 1024 * 1024);
|
2021-01-08 21:24:11 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 44 * kSizeDummyEntry);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 44 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(), 44 * 256 * 1024 + kMetaDataChargeOverhead);
|
2017-06-02 21:13:59 +00:00
|
|
|
ASSERT_FALSE(wbf->ShouldFlush());
|
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Allocate another 41MB, memory_used_ = 52045KB
|
2019-04-16 18:59:35 +00:00
|
|
|
wbf->ReserveMem(41 * 1024 * 1024);
|
2021-01-08 21:24:11 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 204 * kSizeDummyEntry);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 204 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(),
|
|
|
|
204 * 256 * 1024 + kMetaDataChargeOverhead);
|
2017-06-02 21:13:59 +00:00
|
|
|
ASSERT_TRUE(wbf->ShouldFlush());
|
|
|
|
|
|
|
|
ASSERT_TRUE(wbf->ShouldFlush());
|
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Schedule free 20MB, memory_used_ = 52045KB
|
|
|
|
// It will not cause any change in memory_used and cache cost
|
2017-06-02 21:13:59 +00:00
|
|
|
wbf->ScheduleFreeMem(20 * 1024 * 1024);
|
2021-01-08 21:24:11 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 204 * kSizeDummyEntry);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 204 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(),
|
|
|
|
204 * 256 * 1024 + kMetaDataChargeOverhead);
|
2017-06-02 21:13:59 +00:00
|
|
|
// Still need flush as the hard limit hits
|
|
|
|
ASSERT_TRUE(wbf->ShouldFlush());
|
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Free 20MB, memory_used_ = 31565KB
|
|
|
|
// It will releae 80 dummy entries from cache since
|
|
|
|
// since memory_used_ < dummy_entries_in_cache_usage * (3/4)
|
|
|
|
// and floor((dummy_entries_in_cache_usage - memory_used_) % kSizeDummyEntry)
|
|
|
|
// = 80
|
2017-06-02 21:13:59 +00:00
|
|
|
wbf->FreeMem(20 * 1024 * 1024);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 124 * kSizeDummyEntry);
|
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 124 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(),
|
|
|
|
124 * 256 * 1024 + kMetaDataChargeOverhead);
|
2017-06-02 21:13:59 +00:00
|
|
|
|
|
|
|
ASSERT_FALSE(wbf->ShouldFlush());
|
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Free 16KB, memory_used_ = 31549KB
|
|
|
|
// It will not release any dummy entry since memory_used_ >=
|
|
|
|
// dummy_entries_in_cache_usage * (3/4)
|
2017-06-02 21:13:59 +00:00
|
|
|
wbf->FreeMem(16 * 1024);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 124 * kSizeDummyEntry);
|
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 124 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(),
|
|
|
|
124 * 256 * 1024 + kMetaDataChargeOverhead);
|
|
|
|
|
|
|
|
// Free 20MB, memory_used_ = 11069KB
|
|
|
|
// It will releae 80 dummy entries from cache
|
|
|
|
// since memory_used_ < dummy_entries_in_cache_usage * (3/4)
|
|
|
|
// and floor((dummy_entries_in_cache_usage - memory_used_) % kSizeDummyEntry)
|
|
|
|
// = 80
|
|
|
|
wbf->FreeMem(20 * 1024 * 1024);
|
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 44 * kSizeDummyEntry);
|
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 44 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(), 44 * 256 * 1024 + kMetaDataChargeOverhead);
|
2017-06-02 21:13:59 +00:00
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Free 1MB, memory_used_ = 10045KB
|
|
|
|
// It will not cause any change in cache cost
|
|
|
|
// since memory_used_ > dummy_entries_in_cache_usage * (3/4)
|
|
|
|
wbf->FreeMem(1 * 1024 * 1024);
|
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 44 * kSizeDummyEntry);
|
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 44 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(), 44 * 256 * 1024 + kMetaDataChargeOverhead);
|
|
|
|
|
|
|
|
// Reserve 512KB, memory_used_ = 10557KB
|
|
|
|
// It will not casue any change in cache cost
|
|
|
|
// since memory_used_ > dummy_entries_in_cache_usage * (3/4)
|
|
|
|
// which reflects the benefit of saving dummy entry insertion on memory
|
|
|
|
// reservation after delay decrease
|
2019-04-16 18:59:35 +00:00
|
|
|
wbf->ReserveMem(512 * 1024);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 44 * kSizeDummyEntry);
|
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 44 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(), 44 * 256 * 1024 + kMetaDataChargeOverhead);
|
2017-06-02 21:13:59 +00:00
|
|
|
|
2022-08-11 00:34:38 +00:00
|
|
|
// Destroy write buffer manger should free everything
|
2017-06-02 21:13:59 +00:00
|
|
|
wbf.reset();
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_EQ(cache->GetPinnedUsage(), 0);
|
2017-06-02 21:13:59 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 22:01:51 +00:00
|
|
|
TEST_F(ChargeWriteBufferTest, BasicWithNoBufferSizeLimit) {
|
2021-08-24 19:42:31 +00:00
|
|
|
constexpr std::size_t kMetaDataChargeOverhead = 10000;
|
2017-06-02 21:13:59 +00:00
|
|
|
// 1GB cache
|
|
|
|
std::shared_ptr<Cache> cache = NewLRUCache(1024 * 1024 * 1024, 4);
|
|
|
|
// A write buffer manager of size 256MB
|
|
|
|
std::unique_ptr<WriteBufferManager> wbf(new WriteBufferManager(0, cache));
|
2021-08-24 19:42:31 +00:00
|
|
|
|
|
|
|
// Allocate 10MB, memory_used_ = 10240KB
|
|
|
|
// It will allocate 40 dummy entries
|
2017-06-02 21:13:59 +00:00
|
|
|
wbf->ReserveMem(10 * 1024 * 1024);
|
2021-01-08 21:24:11 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 40 * kSizeDummyEntry);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 40 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(), 40 * 256 * 1024 + kMetaDataChargeOverhead);
|
|
|
|
|
2017-06-02 21:13:59 +00:00
|
|
|
ASSERT_FALSE(wbf->ShouldFlush());
|
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Free 9MB, memory_used_ = 1024KB
|
|
|
|
// It will free 36 dummy entries
|
2017-06-02 21:13:59 +00:00
|
|
|
wbf->FreeMem(9 * 1024 * 1024);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 4 * kSizeDummyEntry);
|
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 4 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(), 4 * 256 * 1024 + kMetaDataChargeOverhead);
|
|
|
|
|
|
|
|
// Free 160KB gradually, memory_used_ = 864KB
|
|
|
|
// It will not cause any change
|
|
|
|
// since memory_used_ > dummy_entries_in_cache_usage * 3/4
|
2019-04-16 18:59:35 +00:00
|
|
|
for (int i = 0; i < 40; i++) {
|
|
|
|
wbf->FreeMem(4 * 1024);
|
2017-06-02 21:13:59 +00:00
|
|
|
}
|
2021-01-08 21:24:11 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 4 * kSizeDummyEntry);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 4 * 256 * 1024);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(), 4 * 256 * 1024 + kMetaDataChargeOverhead);
|
2017-06-02 21:13:59 +00:00
|
|
|
}
|
2020-04-01 18:24:58 +00:00
|
|
|
|
2022-05-17 22:01:51 +00:00
|
|
|
TEST_F(ChargeWriteBufferTest, BasicWithCacheFull) {
|
2021-08-24 19:42:31 +00:00
|
|
|
constexpr std::size_t kMetaDataChargeOverhead = 20000;
|
|
|
|
|
|
|
|
// 12MB cache size with strict capacity
|
2020-04-01 18:24:58 +00:00
|
|
|
LRUCacheOptions lo;
|
|
|
|
lo.capacity = 12 * 1024 * 1024;
|
|
|
|
lo.num_shard_bits = 0;
|
|
|
|
lo.strict_capacity_limit = true;
|
|
|
|
std::shared_ptr<Cache> cache = NewLRUCache(lo);
|
|
|
|
std::unique_ptr<WriteBufferManager> wbf(new WriteBufferManager(0, cache));
|
2021-08-24 19:42:31 +00:00
|
|
|
|
|
|
|
// Allocate 10MB, memory_used_ = 10240KB
|
2020-04-01 18:24:58 +00:00
|
|
|
wbf->ReserveMem(10 * 1024 * 1024);
|
2021-01-08 21:24:11 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 40 * kSizeDummyEntry);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 40 * kSizeDummyEntry);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(),
|
|
|
|
40 * kSizeDummyEntry + kMetaDataChargeOverhead);
|
2021-01-08 21:24:11 +00:00
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Allocate 10MB, memory_used_ = 20480KB
|
|
|
|
// Some dummy entry insertion will fail due to full cache
|
2020-04-01 18:24:58 +00:00
|
|
|
wbf->ReserveMem(10 * 1024 * 1024);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 40 * kSizeDummyEntry);
|
2020-04-01 18:24:58 +00:00
|
|
|
ASSERT_LE(cache->GetPinnedUsage(), 12 * 1024 * 1024);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_LT(wbf->dummy_entries_in_cache_usage(), 80 * kSizeDummyEntry);
|
2020-04-01 18:24:58 +00:00
|
|
|
|
2021-08-24 19:42:31 +00:00
|
|
|
// Free 15MB after encoutering cache full, memory_used_ = 5120KB
|
|
|
|
wbf->FreeMem(15 * 1024 * 1024);
|
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 20 * kSizeDummyEntry);
|
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 20 * kSizeDummyEntry);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(),
|
|
|
|
20 * kSizeDummyEntry + kMetaDataChargeOverhead);
|
|
|
|
|
|
|
|
// Reserve 15MB, creating cache full again, memory_used_ = 20480KB
|
|
|
|
wbf->ReserveMem(15 * 1024 * 1024);
|
|
|
|
ASSERT_LE(cache->GetPinnedUsage(), 12 * 1024 * 1024);
|
|
|
|
ASSERT_LT(wbf->dummy_entries_in_cache_usage(), 80 * kSizeDummyEntry);
|
|
|
|
|
|
|
|
// Increase capacity so next insert will fully succeed
|
|
|
|
cache->SetCapacity(40 * 1024 * 1024);
|
|
|
|
|
|
|
|
// Allocate 10MB, memory_used_ = 30720KB
|
2020-04-01 18:24:58 +00:00
|
|
|
wbf->ReserveMem(10 * 1024 * 1024);
|
2021-01-08 21:24:11 +00:00
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 120 * kSizeDummyEntry);
|
2021-08-24 19:42:31 +00:00
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 120 * kSizeDummyEntry);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(),
|
|
|
|
120 * kSizeDummyEntry + kMetaDataChargeOverhead);
|
2020-04-01 18:24:58 +00:00
|
|
|
|
|
|
|
// Gradually release 20 MB
|
2021-08-24 19:42:31 +00:00
|
|
|
// It ended up sequentially releasing 32, 24, 18 dummy entries when
|
|
|
|
// memory_used_ decreases to 22528KB, 16384KB, 11776KB.
|
|
|
|
// In total, it releases 74 dummy entries
|
2020-04-01 18:24:58 +00:00
|
|
|
for (int i = 0; i < 40; i++) {
|
|
|
|
wbf->FreeMem(512 * 1024);
|
|
|
|
}
|
2021-08-24 19:42:31 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(wbf->dummy_entries_in_cache_usage(), 46 * kSizeDummyEntry);
|
|
|
|
ASSERT_GE(cache->GetPinnedUsage(), 46 * kSizeDummyEntry);
|
|
|
|
ASSERT_LT(cache->GetPinnedUsage(),
|
|
|
|
46 * kSizeDummyEntry + kMetaDataChargeOverhead);
|
2020-04-01 18:24:58 +00:00
|
|
|
}
|
|
|
|
|
2017-06-02 21:13:59 +00:00
|
|
|
#endif // ROCKSDB_LITE
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2017-06-02 21:13:59 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2022-10-18 07:35:35 +00:00
|
|
|
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
|
2017-06-02 21:13:59 +00:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|