From 560fe70233fda3c86495e4b9509cac5c65ea7651 Mon Sep 17 00:00:00 2001 From: Hui Xiao Date: Mon, 1 Nov 2021 14:42:11 -0700 Subject: [PATCH] Add new API CacheReservationManager::GetDummyEntrySize() (#9072) Summary: Note: it might conflict with another CRM related PR https://github.com/facebook/rocksdb/pull/9071 and so will merge after that's merged. Context: As `CacheReservationManager` being used by more memory users, it is convenient to retrieve the dummy entry size for `CacheReservationManager` instead of hard-coding `256 * 1024` in writing tests. Plus it allows more flexibility to change our implementation on dummy entry size. A follow-up PR is needed to replace those hard-coded dummy entry size value in `db_test2.cc`, `db_write_buffer_manager_test.cc`, `write_buffer_manager_test.cc`, `table_test.cc` and the ones introduced in https://github.com/facebook/rocksdb/pull/9072#issue-1034326069. - Exposed the private static constexpr `kDummyEntrySize` through public static `CacheReservationManager::GetDummyEntrySize()` Pull Request resolved: https://github.com/facebook/rocksdb/pull/9072 Test Plan: - Passing new tests - Passing existing tests Reviewed By: ajkr Differential Revision: D32043684 Pulled By: hx235 fbshipit-source-id: ddefc6921c052adab6a2cda2394eb26da3076a50 --- cache/cache_reservation_manager.h | 4 +++- cache/cache_reservation_manager_test.cc | 14 +++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cache/cache_reservation_manager.h b/cache/cache_reservation_manager.h index 9511a4bfa..cc69de8d8 100644 --- a/cache/cache_reservation_manager.h +++ b/cache/cache_reservation_manager.h @@ -75,6 +75,8 @@ class CacheReservationManager { Status UpdateCacheReservation(std::size_t new_memory_used); std::size_t GetTotalReservedCacheSize(); + static constexpr std::size_t GetDummyEntrySize() { return kSizeDummyEntry; } + private: static constexpr std::size_t kSizeDummyEntry = 256 * 1024; // The key will be longer than keys for blocks in SST files so they won't @@ -95,4 +97,4 @@ class CacheReservationManager { // The non-prefix part will be updated according to the ID to use. char cache_key_[kCacheKeyPrefixSize + kMaxVarint64Length]; }; -} // namespace ROCKSDB_NAMESPACE \ No newline at end of file +} // namespace ROCKSDB_NAMESPACE diff --git a/cache/cache_reservation_manager_test.cc b/cache/cache_reservation_manager_test.cc index be548d3af..06a50edc8 100644 --- a/cache/cache_reservation_manager_test.cc +++ b/cache/cache_reservation_manager_test.cc @@ -25,7 +25,8 @@ class CacheReservationManagerTest : public ::testing::Test { static constexpr std::size_t kOneGigabyte = 1024 * 1024 * 1024; static constexpr int kNumShardBits = 0; // 2^0 shard - static constexpr std::size_t kSizeDummyEntry = 256 * 1024; + static constexpr std::size_t kSizeDummyEntry = + CacheReservationManager::GetDummyEntrySize(); static const std::size_t kCacheKeyPrefixSize = BlockBasedTable::kMaxCacheKeyPrefixSize + kMaxVarint64Length; static constexpr std::size_t kMetaDataChargeOverhead = 10000; @@ -143,7 +144,8 @@ TEST(CacheReservationManagerIncreaseReservcationOnFullCacheTest, IncreaseCacheReservationOnFullCache) { constexpr std::size_t kOneMegabyte = 1024 * 1024; constexpr std::size_t kOneGigabyte = 1024 * 1024 * 1024; - constexpr std::size_t kSizeDummyEntry = 256 * 1024; + constexpr std::size_t kSizeDummyEntry = + CacheReservationManager::GetDummyEntrySize(); constexpr std::size_t kMetaDataChargeOverhead = 10000; LRUCacheOptions lo; @@ -307,7 +309,8 @@ TEST_F(CacheReservationManagerTest, TEST(CacheReservationManagerWithDelayedDecreaseTest, DecreaseCacheReservationWithDelayedDecrease) { constexpr std::size_t kOneGigabyte = 1024 * 1024 * 1024; - constexpr std::size_t kSizeDummyEntry = 256 * 1024; + constexpr std::size_t kSizeDummyEntry = + CacheReservationManager::GetDummyEntrySize(); constexpr std::size_t kMetaDataChargeOverhead = 10000; LRUCacheOptions lo; @@ -379,7 +382,8 @@ TEST(CacheReservationManagerWithDelayedDecreaseTest, TEST(CacheReservationManagerDestructorTest, ReleaseRemainingDummyEntriesOnDestruction) { constexpr std::size_t kOneGigabyte = 1024 * 1024 * 1024; - constexpr std::size_t kSizeDummyEntry = 256 * 1024; + constexpr std::size_t kSizeDummyEntry = + CacheReservationManager::GetDummyEntrySize(); constexpr std::size_t kMetaDataChargeOverhead = 10000; LRUCacheOptions lo; @@ -408,4 +412,4 @@ TEST(CacheReservationManagerDestructorTest, int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); -} \ No newline at end of file +}