From 00c775a365970cd8f61404fc86e9cca21c81ce6f Mon Sep 17 00:00:00 2001 From: mrambacher Date: Sun, 13 Nov 2022 13:24:05 -0500 Subject: [PATCH 01/11] First pass at adding Cachelib as Pluggable Secondary Cache --- .../rocks_secondary_cache/CMakeLists.txt | 12 +++ .../rocks_secondary_cache/CachelibWrapper.cpp | 74 +++++++++++++------ .../rocks_secondary_cache/CachelibWrapper.h | 61 +++++++-------- 3 files changed, 96 insertions(+), 51 deletions(-) create mode 100644 cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt diff --git a/cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt b/cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt new file mode 100644 index 0000000000..29198d5c98 --- /dev/null +++ b/cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.4) + +find_package(cachelib REQUIRED) +add_library(rocksdb_cachelib STATIC CachelibWrapper.cpp) +target_link_libraries(rocksdb_cachelib PRIVATE cachelib) +target_include_directories(rocksdb_cachelib PRIVATE ${CACHELIB_INCLUDE_DIR}) + +# Suppresses errors from folly exceptions +target_compile_options(rocksdb_cachelib PRIVATE -Wno-error=class-memaccess) +set(cachelib_LIBS rocksdb_cachelib PARENT_SCOPE) +set(cachelib_TARGETS rocksdb_cachelib PARENT_SCOPE) +set(cachelib_FUNC register_CachelibObjects PARENT_SCOPE) diff --git a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp index eee8435f6e..b13ec6ab63 100644 --- a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp @@ -14,18 +14,17 @@ * limitations under the License. */ -#include "cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h" +#include "CachelibWrapper.h" -#include "cachelib/facebook/utils/FbInternalRuntimeUpdateWrapper.h" #include "folly/init/Init.h" #include "folly/synchronization/Rcu.h" #include "rocksdb/version.h" +#include "rocksdb/utilities/object_registry.h" namespace facebook { namespace rocks_secondary_cache { #define FB_CACHE_MAX_ITEM_SIZE 4 << 20 -using ApiWrapper = cachelib::FbInternalRuntimeUpdateWrapper; namespace { // We use a separate RCU domain since read side critical sections can block @@ -131,6 +130,41 @@ class RocksCachelibWrapperHandle : public rocksdb::SecondaryCacheResultHandle { }; } // namespace +RockeCachelibWrapper::PrepareOptions(const ROCKSDB_NAMESPACE::ConfigOptions& opts) { + if (!cache_) { + std::unique_ptr cache; + cachelib::PoolId defaultPool; + FbCacheConfig config; + NvmCacheConfig nvmConfig; + + nvmConfig.navyConfig.setBlockSize(options_.blockSize); + nvmConfig.navyConfig.setSimpleFile(options_.fileName, + options_.size, + /*truncateFile=*/true); + nvmConfig.navyConfig.blockCache().setRegionSize(options_.regionSize); + if (options_.admPolicy == "random") { + nvmConfig.navyConfig.enableRandomAdmPolicy().setAdmProbability( + options_.admProbability); + } else { + nvmConfig.navyConfig.enableDynamicRandomAdmPolicy() + .setMaxWriteRate(options_.maxWriteRate) + .setAdmWriteRate(options_.admissionWriteRate); + } + nvmConfig.enableFastNegativeLookups = true; + + config.setCacheSize(options_.volatileSize) + .setCacheName(options_.cacheName) + .setAccessConfig( + {options_.bktPower /* bucket power */, options_.lockPower /* lock power */}) + .enableNvmCache(nvmConfig) + .validate(); // will throw if bad config + cache_ = std::make_unique(config); + pool_ = + cache->addPool("default", cache_->getCacheMemoryStats().cacheSize); + } + return SecondaryCache::PreareOptions(opts); +} + RocksCachelibWrapper::~RocksCachelibWrapper() { Close(); } rocksdb::Status RocksCachelibWrapper::Insert( @@ -225,26 +259,14 @@ void RocksCachelibWrapper::Close() { // sections already started to finish, and then delete the cache cache_.store(nullptr); GetRcuDomain().synchronize(); - admin_.reset(); delete cache; } } -bool RocksCachelibWrapper::UpdateMaxWriteRateForDynamicRandom( - uint64_t maxRate) { - FbCache* cache = cache_.load(); - bool ret = false; - if (cache) { - ret = ApiWrapper::updateMaxRateForDynamicRandomAP(*cache, maxRate); - } - return ret; -} - // Global cache object and a default cache pool std::unique_ptr NewRocksCachelibWrapper( const RocksCachelibOptions& opts) { std::unique_ptr cache; - std::unique_ptr admin; cachelib::PoolId defaultPool; FbCacheConfig config; NvmCacheConfig nvmConfig; @@ -274,15 +296,23 @@ std::unique_ptr NewRocksCachelibWrapper( defaultPool = cache->addPool("default", cache->getCacheMemoryStats().cacheSize); - if (opts.fb303Stats) { - cachelib::CacheAdmin::Config adminConfig; - adminConfig.oncall = opts.oncallName; - admin = std::make_unique(*cache, adminConfig); - } - return std::unique_ptr(new RocksCachelibWrapper( - std::move(cache), std::move(admin), std::move(defaultPool))); + std::move(cache), std::move(defaultPool))); } +#ifndef ROCKSDB_LITE +int register_CachelibObjects(ROCKSDB_NAMESPACE::ObjectLibrary& library, const std::string&) { + library.AddFactory(CachelibWrapper::kClassName(), + [](const std::string& uri, std::unique_ptr* guard, + std::string* /*errmsg*/) { + RocksCachelibOptions options; + guard->reset(new CacheLibWrapper(options)); + return guard->get(); + }); + return 1; +} +#endif // ROCKSDB_LITE } // namespace rocks_secondary_cache } // namespace facebook + + diff --git a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h index 9b1565034d..43d7780fae 100644 --- a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h +++ b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h @@ -16,11 +16,14 @@ #pragma once #include "cachelib/allocator/CacheAllocator.h" -#include "cachelib/facebook/admin/CacheAdmin.h" #include "rocksdb/secondary_cache.h" #include "rocksdb/types.h" #include "rocksdb/version.h" +namespace ROCKSDB_NAMESPACE { +class ObjectLibrary; +} // namespace ROCKSDB_NAMESPACE + namespace facebook { namespace rocks_secondary_cache { // Options structure for configuring a Cachelib SecondaryCache instance @@ -82,37 +85,34 @@ using FbCacheReadHandle = typename FbCache::ReadHandle; using FbCacheItem = typename FbCache::Item; // The RocksCachelibWrapper is a concrete implementation of -// rocksdb::SecondaryCache. It can be allocated using +// ROCKSDB_NAMESPACE::SecondaryCache. It can be allocated using // NewRocksCachelibWrapper() and the resulting pointer -// can be passed in rocksdb::LRUCacheOptions to -// rocksdb::NewLRUCache(). +// can be passed in ROCKSDB_NAMESPACE::LRUCacheOptions to +// ROCKSDB_NAMESPACE::NewLRUCache(). // // Users can also cast a pointer to it and call methods on // it directly, especially custom methods that may be added // in the future. For example - -// std::unique_ptr cache = +// std::unique_ptr cache = // NewRocksCachelibWrapper(opts); // static_cast(cache.get())->Erase(key); -class RocksCachelibWrapper : public rocksdb::SecondaryCache { +class RocksCachelibWrapper : public ROCKSDB_NAMESPACE::SecondaryCache { public: - RocksCachelibWrapper(std::unique_ptr&& cache, - std::unique_ptr&& admin, - cachelib::PoolId pool) - : cache_(std::move(cache).release()), - admin_(std::move(admin)), - pool_(pool) {} + RocksCachelibWrapper(const RocksCachelibOptions& options) : + options_(options) { } ~RocksCachelibWrapper() override; - const char* Name() const override { return "RocksCachelibWrapper"; } + static const char* kClassName() const { return "RocksCachelibWrapper"; } + const char* Name() const override { return kClassName(); } - rocksdb::Status Insert( - const rocksdb::Slice& key, + ROCKSDB_NAMESPACE::Status Insert( + const ROCKSDB_NAMESPACE::Slice& key, void* value, - const rocksdb::Cache::CacheItemHelper* helper) override; + const ROCKSDB_NAMESPACE::Cache::CacheItemHelper* helper) override; - std::unique_ptr Lookup( - const rocksdb::Slice& key, - const rocksdb::Cache::CreateCallback& create_cb, + std::unique_ptr Lookup( + const ROCKSDB_NAMESPACE::Slice& key, + const ROCKSDB_NAMESPACE::Cache::CreateCallback& create_cb, bool wait #if ROCKSDB_MAJOR > 7 || (ROCKSDB_MAJOR == 7 && ROCKSDB_MINOR >= 7) , @@ -125,10 +125,10 @@ class RocksCachelibWrapper : public rocksdb::SecondaryCache { bool SupportForceErase() const override { return false; } #endif - void Erase(const rocksdb::Slice& key) override; + void Erase(const ROCKSDB_NAMESPACE::Slice& key) override; void WaitAll( - std::vector handles) override; + std::vector handles) override; // TODO std::string GetPrintableOptions() const override { return ""; } @@ -140,19 +140,22 @@ class RocksCachelibWrapper : public rocksdb::SecondaryCache { // ongoing lookups and inserts by other threads to be quiesced. void Close(); - // If the admPolicy in RocksCachelibOptions was set to "dynamic_random", - // then this function can be called to update the max write rate for that - // policy. - bool UpdateMaxWriteRateForDynamicRandom(uint64_t maxRate); - + ROCKSDB_NAMESPACE::Status PrepareOptions(const ConfigOptions& /*options*/) override; + private: + RocksCachelibOptions options_; std::atomic cache_; - std::unique_ptr admin_; cachelib::PoolId pool_; }; -// Allocate a new Cache instance with a rocksdb::TieredCache wrapper around it -extern std::unique_ptr NewRocksCachelibWrapper( +// Allocate a new Cache instance with a ROCKSDB_NAMESPACE::TieredCache wrapper around it +extern std::unique_ptr NewRocksCachelibWrapper( const RocksCachelibOptions& opts); +#ifndef ROCKSDB_LITE +extern "C" { +int register_CachelibObjects(ROCKSDB_NAMESPACE::ObjectLibrary& library, const std::string&); +} // extern "C" + +#endif // ROCKSDB_LITE } // namespace rocks_secondary_cache } // namespace facebook From fea3f81775b34522bad894fcb062cf139d4bb30b Mon Sep 17 00:00:00 2001 From: mrambacher Date: Tue, 29 Nov 2022 14:28:18 -0500 Subject: [PATCH 02/11] Next pass at Cachelib/Rocks integration --- .../rocks_secondary_cache/CMakeLists.txt | 12 +-- .../rocks_secondary_cache/CachelibWrapper.cpp | 89 ++++++++++--------- .../rocks_secondary_cache/CachelibWrapper.h | 10 +-- 3 files changed, 59 insertions(+), 52 deletions(-) diff --git a/cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt b/cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt index 29198d5c98..806dfa2db4 100644 --- a/cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt +++ b/cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required(VERSION 3.4) find_package(cachelib REQUIRED) -add_library(rocksdb_cachelib STATIC CachelibWrapper.cpp) -target_link_libraries(rocksdb_cachelib PRIVATE cachelib) -target_include_directories(rocksdb_cachelib PRIVATE ${CACHELIB_INCLUDE_DIR}) # Suppresses errors from folly exceptions -target_compile_options(rocksdb_cachelib PRIVATE -Wno-error=class-memaccess) -set(cachelib_LIBS rocksdb_cachelib PARENT_SCOPE) -set(cachelib_TARGETS rocksdb_cachelib PARENT_SCOPE) +set(cachelib_SOURCES CachelibWrapper.cpp PARENT_SCOPE) +set(cachelib_INCLUDE_PATHS ${CACHELIB_INCLUDE_DIR}/.. PARENT_SCOPE) +set(cachelib_COMPILE_FLAGS -Wno-error=class-memaccess -Wno-error=sign-compare -Wno-error=deprecated-declarationsPARENT_SCOPE) +set(cachelib_LIBS "cachelib_allocator" "cachelib_shm" "cachelib_navy" "cachelib_common" "thriftcpp2" "thriftfrozen2" "thriftmetadata" "thriftanyrep" "thrifttype" "thrifttyperep" "thriftannotation" "thriftprotocol" "async" "wangle" "fizz" "sodium" "rt" PARENT_SCOPE) set(cachelib_FUNC register_CachelibObjects PARENT_SCOPE) +set(cachelib_LINK_PATHS ${CMAKE_PREFIX_PATH}/lib PARENT_SCOPE) +set(cachelib_TESTS tests/CachelibWrapperTest.cpp PARENT_SCOPE) diff --git a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp index b13ec6ab63..f2dd00b399 100644 --- a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp @@ -18,8 +18,10 @@ #include "folly/init/Init.h" #include "folly/synchronization/Rcu.h" +#include "rocksdb/convenience.h" #include "rocksdb/version.h" #include "rocksdb/utilities/object_registry.h" +#include "rocksdb/utilities/options_type.h" namespace facebook { namespace rocks_secondary_cache { @@ -128,11 +130,46 @@ class RocksCachelibWrapperHandle : public rocksdb::SecondaryCacheResultHandle { } } }; + +static std::unordered_map +rocks_cachelib_type_info = { +#ifndef ROCKSDB_LITE + {"cachename", + {offsetof(struct RocksCachelibOptions, cacheName), OptionType::kString}}, + {"filename", + {offsetof(struct RocksCachelibOptions, fileName), OptionType::kString}}, + {"size", + {offsetof(struct RocksCachelibOptions, size), OptionType::kSizeT}}, + {"block_size", + {offsetof(struct RocksCachelibOptions, blockSize), OptionType::kSizeT}}, + {"region_size", + {offsetof(struct RocksCachelibOptions, regionSize), OptionType::kSizeT}}, + {"policy", + {offsetof(struct RocksCachelibOptions, admPolicy), OptionType::kString}}, + {"probability", + {offsetof(struct RocksCachelibOptions, admProbability), OptionType::kDouble}}, + {"max_write_rate", + {offsetof(struct RocksCachelibOptions, maxWriteRate), OptionType::kUInt64T}}, + {"admission_write_rate", + {offsetof(struct RocksCachelibOptions, admissionWriteRate), OptionType::kUInt64T}}, + {"volatile_size", + {offsetof(struct RocksCachelibOptions, volatileSize), OptionType::kSizeT}}, + {"bucket_power", + {offsetof(struct RocksCachelibOptions, bktPower), OptionType::kUInt32T}}, + {"lock_power", + {offsetof(struct RocksCachelibOptions, lockPower), OptionType::kUInt32T}}, +#endif // ROCKSDB_LITE +}; } // namespace -RockeCachelibWrapper::PrepareOptions(const ROCKSDB_NAMESPACE::ConfigOptions& opts) { - if (!cache_) { - std::unique_ptr cache; +RocksCachelibWrapper::RocksCachelibWrapper(const RocksCachelibOptions& options) + : options_(options) { +} + +ROCKSDB_NAMESPACE::Status RocksCachelibWrapper::PrepareOptions(const ROCKSDB_NAMESPACE::ConfigOptions& opts) { + FbCache* cache = cache_.load(); + + if (!cache) { cachelib::PoolId defaultPool; FbCacheConfig config; NvmCacheConfig nvmConfig; @@ -158,11 +195,12 @@ RockeCachelibWrapper::PrepareOptions(const ROCKSDB_NAMESPACE::ConfigOptions& opt {options_.bktPower /* bucket power */, options_.lockPower /* lock power */}) .enableNvmCache(nvmConfig) .validate(); // will throw if bad config - cache_ = std::make_unique(config); + auto new_cache = std::make_unique(config); pool_ = - cache->addPool("default", cache_->getCacheMemoryStats().cacheSize); + new_cache->addPool("default", new_cache->getCacheMemoryStats().cacheSize); + cache_.store(new_cache.release()); } - return SecondaryCache::PreareOptions(opts); + return SecondaryCache::PrepareOptions(opts); } RocksCachelibWrapper::~RocksCachelibWrapper() { Close(); } @@ -266,47 +304,18 @@ void RocksCachelibWrapper::Close() { // Global cache object and a default cache pool std::unique_ptr NewRocksCachelibWrapper( const RocksCachelibOptions& opts) { - std::unique_ptr cache; - cachelib::PoolId defaultPool; - FbCacheConfig config; - NvmCacheConfig nvmConfig; - - nvmConfig.navyConfig.setBlockSize(opts.blockSize); - nvmConfig.navyConfig.setSimpleFile(opts.fileName, - opts.size, - /*truncateFile=*/true); - nvmConfig.navyConfig.blockCache().setRegionSize(opts.regionSize); - if (opts.admPolicy == "random") { - nvmConfig.navyConfig.enableRandomAdmPolicy().setAdmProbability( - opts.admProbability); - } else { - nvmConfig.navyConfig.enableDynamicRandomAdmPolicy() - .setMaxWriteRate(opts.maxWriteRate) - .setAdmWriteRate(opts.admissionWriteRate); - } - nvmConfig.enableFastNegativeLookups = true; - - config.setCacheSize(opts.volatileSize) - .setCacheName(opts.cacheName) - .setAccessConfig( - {opts.bktPower /* bucket power */, opts.lockPower /* lock power */}) - .enableNvmCache(nvmConfig) - .validate(); // will throw if bad config - cache = std::make_unique(config); - defaultPool = - cache->addPool("default", cache->getCacheMemoryStats().cacheSize); - - return std::unique_ptr(new RocksCachelibWrapper( - std::move(cache), std::move(defaultPool))); + std::unique_ptr secondary = std::make_unique(opts); + assert(secondary->PrepareOptions(ROCKSDB_NAMESPACE::ConfigOptions()).ok()); + return secondary; } #ifndef ROCKSDB_LITE int register_CachelibObjects(ROCKSDB_NAMESPACE::ObjectLibrary& library, const std::string&) { - library.AddFactory(CachelibWrapper::kClassName(), + library.AddFactory(RocksCachelibWrapper::kClassName(), [](const std::string& uri, std::unique_ptr* guard, std::string* /*errmsg*/) { RocksCachelibOptions options; - guard->reset(new CacheLibWrapper(options)); + guard->reset(new RocksCachelibWrapper(options)); return guard->get(); }); return 1; diff --git a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h index 43d7780fae..cd867c4cef 100644 --- a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h +++ b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h @@ -98,11 +98,10 @@ using FbCacheItem = typename FbCache::Item; // static_cast(cache.get())->Erase(key); class RocksCachelibWrapper : public ROCKSDB_NAMESPACE::SecondaryCache { public: - RocksCachelibWrapper(const RocksCachelibOptions& options) : - options_(options) { } + RocksCachelibWrapper(const RocksCachelibOptions& options); ~RocksCachelibWrapper() override; - static const char* kClassName() const { return "RocksCachelibWrapper"; } + static const char* kClassName() { return "RocksCachelibWrapper"; } const char* Name() const override { return kClassName(); } ROCKSDB_NAMESPACE::Status Insert( @@ -132,7 +131,8 @@ class RocksCachelibWrapper : public ROCKSDB_NAMESPACE::SecondaryCache { // TODO std::string GetPrintableOptions() const override { return ""; } - + ROCKSDB_NAMESPACE::Status PrepareOptions(const ROCKSDB_NAMESPACE::ConfigOptions& /*options*/) override; + // Calling Close() persists the cachelib state to the file and frees the // cachelib object. After calling Close(), subsequent lookups will fail, // and subsequent inserts will be silently ignored. Close() is not thread @@ -140,8 +140,6 @@ class RocksCachelibWrapper : public ROCKSDB_NAMESPACE::SecondaryCache { // ongoing lookups and inserts by other threads to be quiesced. void Close(); - ROCKSDB_NAMESPACE::Status PrepareOptions(const ConfigOptions& /*options*/) override; - private: RocksCachelibOptions options_; std::atomic cache_; From 6130377095f57638aceab8c41938fdc8a217ff20 Mon Sep 17 00:00:00 2001 From: mrambacher Date: Tue, 29 Nov 2022 14:35:51 -0500 Subject: [PATCH 03/11] Add namespace --- .../rocks_secondary_cache/CachelibWrapper.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp index f2dd00b399..fde9f26abe 100644 --- a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp @@ -131,33 +131,33 @@ class RocksCachelibWrapperHandle : public rocksdb::SecondaryCacheResultHandle { } }; -static std::unordered_map +static std::unordered_map rocks_cachelib_type_info = { #ifndef ROCKSDB_LITE {"cachename", - {offsetof(struct RocksCachelibOptions, cacheName), OptionType::kString}}, + {offsetof(struct RocksCachelibOptions, cacheName), ROCKSDB_NAMESPACE::OptionType::kString}}, {"filename", - {offsetof(struct RocksCachelibOptions, fileName), OptionType::kString}}, + {offsetof(struct RocksCachelibOptions, fileName), ROCKSDB_NAMESPACE::OptionType::kString}}, {"size", - {offsetof(struct RocksCachelibOptions, size), OptionType::kSizeT}}, + {offsetof(struct RocksCachelibOptions, size), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, {"block_size", - {offsetof(struct RocksCachelibOptions, blockSize), OptionType::kSizeT}}, + {offsetof(struct RocksCachelibOptions, blockSize), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, {"region_size", - {offsetof(struct RocksCachelibOptions, regionSize), OptionType::kSizeT}}, + {offsetof(struct RocksCachelibOptions, regionSize), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, {"policy", - {offsetof(struct RocksCachelibOptions, admPolicy), OptionType::kString}}, + {offsetof(struct RocksCachelibOptions, admPolicy), ROCKSDB_NAMESPACE::OptionType::kString}}, {"probability", - {offsetof(struct RocksCachelibOptions, admProbability), OptionType::kDouble}}, + {offsetof(struct RocksCachelibOptions, admProbability), ROCKSDB_NAMESPACE::OptionType::kDouble}}, {"max_write_rate", - {offsetof(struct RocksCachelibOptions, maxWriteRate), OptionType::kUInt64T}}, + {offsetof(struct RocksCachelibOptions, maxWriteRate), ROCKSDB_NAMESPACE::OptionType::kUInt64T}}, {"admission_write_rate", - {offsetof(struct RocksCachelibOptions, admissionWriteRate), OptionType::kUInt64T}}, + {offsetof(struct RocksCachelibOptions, admissionWriteRate), ROCKSDB_NAMESPACE::OptionType::kUInt64T}}, {"volatile_size", - {offsetof(struct RocksCachelibOptions, volatileSize), OptionType::kSizeT}}, + {offsetof(struct RocksCachelibOptions, volatileSize), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, {"bucket_power", - {offsetof(struct RocksCachelibOptions, bktPower), OptionType::kUInt32T}}, + {offsetof(struct RocksCachelibOptions, bktPower), ROCKSDB_NAMESPACE::OptionType::kUInt32T}}, {"lock_power", - {offsetof(struct RocksCachelibOptions, lockPower), OptionType::kUInt32T}}, + {offsetof(struct RocksCachelibOptions, lockPower), ROCKSDB_NAMESPACE::OptionType::kUInt32T}}, #endif // ROCKSDB_LITE }; } // namespace From 8392fb2b83dccfb0167ec39ca475d34ef4a94aca Mon Sep 17 00:00:00 2001 From: mrambacher Date: Tue, 29 Nov 2022 14:50:03 -0500 Subject: [PATCH 04/11] Attempt to fix test to build --- .../rocks_secondary_cache/tests/CachelibWrapperTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp index 2bd72b9cad..bc2e67e032 100644 --- a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp @@ -14,8 +14,8 @@ * limitations under the License. */ -#include -#include +#include "cachelib/CachelibWrapper.h" +#include "cachelib/common/Utils.h" #include #include #include @@ -60,7 +60,7 @@ class CachelibWrapperTest : public ::testing::Test { CachelibWrapperTest() : fail_create_(false) { RocksCachelibOptions opts; - path_ = files::FileUtil::recreateRandomTempDir("CachelibWrapperTest"); + path_ = util::getUniqueTempDir("CachelibWrapperTest"); opts.volatileSize = kVolatileSize; opts.cacheName = "CachelibWrapperTest"; opts.fileName = path_ + "/cachelib_wrapper_test_file"; From 7f3b1a19ebc6fe89b16d6a9e236bbd05bcd2dcaa Mon Sep 17 00:00:00 2001 From: mrambacher Date: Tue, 29 Nov 2022 14:52:26 -0500 Subject: [PATCH 05/11] Another build change --- .../rocks_secondary_cache/tests/CachelibWrapperTest.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp index bc2e67e032..f96f3c44fc 100644 --- a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "cachelib/CachelibWrapper.h" +#include "plugin/cachelib/CachelibWrapper.h" #include "cachelib/common/Utils.h" #include #include @@ -525,6 +525,7 @@ TEST_F(CachelibWrapperTest, WaitAllWhileCloseTest) { pthread_mutex_destroy(&mu); } +#if 0 TEST_F(CachelibWrapperTest, UpdateMaxRateTest) { RocksCachelibOptions opts; opts.volatileSize = kVolatileSize; @@ -539,7 +540,8 @@ TEST_F(CachelibWrapperTest, UpdateMaxRateTest) { ASSERT_TRUE(static_cast(sec_cache.get()) ->UpdateMaxWriteRateForDynamicRandom(32 << 20)); } - +#endif + TEST_F(CachelibWrapperTest, LargeItemTest) { std::string str1 = RandomString(8 << 20); TestItem item1(str1.data(), str1.length()); From ec1186f8f5e27e0b6608b586e3ecae9f30d65098 Mon Sep 17 00:00:00 2001 From: mrambacher Date: Mon, 5 Dec 2022 11:24:49 -0500 Subject: [PATCH 06/11] Next pass at CacheLib as a SecondaryCache --- .../rocks_secondary_cache/CMakeLists.txt | 3 +- .../rocks_secondary_cache/CachelibWrapper.cpp | 3 +- .../rocks_secondary_cache/CachelibWrapper.h | 2 + .../tests/CachelibWrapperTest.cpp | 54 +++++++++++++++++-- 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt b/cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt index 806dfa2db4..498ab77c44 100644 --- a/cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt +++ b/cachelib/adaptor/rocks_secondary_cache/CMakeLists.txt @@ -6,7 +6,8 @@ find_package(cachelib REQUIRED) set(cachelib_SOURCES CachelibWrapper.cpp PARENT_SCOPE) set(cachelib_INCLUDE_PATHS ${CACHELIB_INCLUDE_DIR}/.. PARENT_SCOPE) set(cachelib_COMPILE_FLAGS -Wno-error=class-memaccess -Wno-error=sign-compare -Wno-error=deprecated-declarationsPARENT_SCOPE) -set(cachelib_LIBS "cachelib_allocator" "cachelib_shm" "cachelib_navy" "cachelib_common" "thriftcpp2" "thriftfrozen2" "thriftmetadata" "thriftanyrep" "thrifttype" "thrifttyperep" "thriftannotation" "thriftprotocol" "async" "wangle" "fizz" "sodium" "rt" PARENT_SCOPE) +#set(cachelib_LIBS "cachelib_allocator" "cachelib_shm" "cachelib_navy" "cachelib_common" "thriftcpp2" "thriftfrozen2" "thriftmetadata" "thriftanyrep" "thrifttype" "thrifttyperep" "thriftannotation" "thriftprotocol" "async" "wangle" "fizz" "sodium" "rt" PARENT_SCOPE) +set(cachelib_LIBS "cachelib_allocator" "cachelib_shm" "cachelib_navy" "cachelib_common" "thriftcpp2" "thriftfrozen2" "thriftmetadata" "thriftanyrep" "thrifttype" "thrifttyperep" "thriftannotation" "thriftprotocol" "async" "wangle" "fizz" "folly" "folly_test_util" "fmtd" "glogd" "sodium" "boost_context" "rt" PARENT_SCOPE) set(cachelib_FUNC register_CachelibObjects PARENT_SCOPE) set(cachelib_LINK_PATHS ${CMAKE_PREFIX_PATH}/lib PARENT_SCOPE) set(cachelib_TESTS tests/CachelibWrapperTest.cpp PARENT_SCOPE) diff --git a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp index fde9f26abe..21e4378ee8 100644 --- a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp @@ -163,7 +163,8 @@ rocks_cachelib_type_info = { } // namespace RocksCachelibWrapper::RocksCachelibWrapper(const RocksCachelibOptions& options) - : options_(options) { + : options_(options), cache_(nullptr) { + RegisterOptions(options_, rocks_cachelib_type_info); } ROCKSDB_NAMESPACE::Status RocksCachelibWrapper::PrepareOptions(const ROCKSDB_NAMESPACE::ConfigOptions& opts) { diff --git a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h index cd867c4cef..05b5b456af 100644 --- a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h +++ b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.h @@ -28,6 +28,8 @@ namespace facebook { namespace rocks_secondary_cache { // Options structure for configuring a Cachelib SecondaryCache instance struct RocksCachelibOptions { + static const char *kName() { return "RocksCachelibOptions"; } + // A name for the use case std::string cacheName; diff --git a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp index f96f3c44fc..817e8ac77c 100644 --- a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp @@ -16,6 +16,8 @@ #include "plugin/cachelib/CachelibWrapper.h" #include "cachelib/common/Utils.h" +#include "test_util/testharness.h" + #include #include #include @@ -60,7 +62,7 @@ class CachelibWrapperTest : public ::testing::Test { CachelibWrapperTest() : fail_create_(false) { RocksCachelibOptions opts; - path_ = util::getUniqueTempDir("CachelibWrapperTest"); + path_ = ROCKSDB_NAMESPACE::test::TmpDir(); opts.volatileSize = kVolatileSize; opts.cacheName = "CachelibWrapperTest"; opts.fileName = path_ + "/cachelib_wrapper_test_file"; @@ -162,7 +164,7 @@ TEST_F(CachelibWrapperTest, BasicTest) { ASSERT_EQ(cache()->Insert("k2", &item2, &CachelibWrapperTest::helper_), Status::OK()); - std::unique_ptr handle; + std::unique_ptr handle; bool is_in_sec_cache{false}; handle = cache()->Lookup("k2", test_item_creator, true #if ROCKSDB_MAJOR > 7 || (ROCKSDB_MAJOR == 7 && ROCKSDB_MINOR >= 7) @@ -192,7 +194,7 @@ TEST_F(CachelibWrapperTest, BasicTest) { } TEST_F(CachelibWrapperTest, BasicFailTest) { - std::unique_ptr handle; + std::unique_ptr handle; bool is_in_sec_cache{false}; handle = cache()->Lookup("k1", test_item_creator, true #if ROCKSDB_MAJOR > 7 || (ROCKSDB_MAJOR == 7 && ROCKSDB_MINOR >= 7) @@ -548,7 +550,7 @@ TEST_F(CachelibWrapperTest, LargeItemTest) { ASSERT_EQ(cache()->Insert("k1", &item1, &CachelibWrapperTest::helper_), Status::InvalidArgument()); - std::unique_ptr handle; + std::unique_ptr handle; bool is_in_sec_cache{false}; handle = cache()->Lookup("k1", test_item_creator, true, #if ROCKSDB_MAJOR > 7 || (ROCKSDB_MAJOR == 7 && ROCKSDB_MINOR >= 7) @@ -559,5 +561,49 @@ TEST_F(CachelibWrapperTest, LargeItemTest) { handle.reset(); } +#ifndef ROCKSDB_LITE +TEST_F(CachelibWrapperTest, CreateFromString) { + ROCKSDB::NAMESPACE::ConfigOptions opts; + opts.invoke_prepare_options = true; + std::shared_ptr scache; + std::string props = "cachename=foo;" + "filename=bar;" + "size=1000000;" + "block_size=8192;" + "region_size=4096;" + "policy=unknown;" + "probablity=0.50;" + "max_write_rate=1024;" + "admission_write_rate=2048;" + "volatile_size=2000000;" + "bucket_power=48;" + "lock_power=24;"; + + ASSERT_EQ(ROCKSDB_NAMESPACE::SecondaryCache::CreateFromString(opts, + props + "id=" + RocksCachelibWrapper::kClassName() + + &scache), + ROCKSDB_NAMESPACE::Status::OK()); + auto rco = scache->GetOptions(); + ASSERT_NE(rco, nullptr); + ASSERT_STREQ(rco->cachename, "foo"); + ASSERT_STREQ(rco->filename, "bar"); + ASSERT_EQ(rco->size, 1000000); + ASSERT_EQ(rco->block_size, 8192); + ASSERT_EQ(rco->region_size, 4096); + ASSERT_EQ(rco->probability, 0.5); + ASSERT_EQ(rco->admPolicy, "unknown"); + ASSERT_EQ(rco->max_write_rate, 1024); + ASSERT_EQ(rco->admission_write_rate, 2048); + ASSERT_EQ(rco->volatile_size, 2000000); + ASSERT_EQ(rco->bucket_power, 48); + ASSERT_EQ(rco->lock_power, 24); + +} +#endif // ROCKSDB_LITE } // namespace rocks_secondary_cache } // namespace facebook + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} From 143ac0d75f90302ce4bfed3a7fc6292785e63fe0 Mon Sep 17 00:00:00 2001 From: mrambacher Date: Mon, 5 Dec 2022 11:29:51 -0500 Subject: [PATCH 07/11] Fix bad var names --- .../rocks_secondary_cache/CachelibWrapper.cpp | 2 +- .../tests/CachelibWrapperTest.cpp | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp index 21e4378ee8..7c0be08f8d 100644 --- a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp @@ -164,7 +164,7 @@ rocks_cachelib_type_info = { RocksCachelibWrapper::RocksCachelibWrapper(const RocksCachelibOptions& options) : options_(options), cache_(nullptr) { - RegisterOptions(options_, rocks_cachelib_type_info); + RegisterOptions(&options_, &rocks_cachelib_type_info); } ROCKSDB_NAMESPACE::Status RocksCachelibWrapper::PrepareOptions(const ROCKSDB_NAMESPACE::ConfigOptions& opts) { diff --git a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp index 817e8ac77c..ab9bdb92bd 100644 --- a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp @@ -585,18 +585,18 @@ TEST_F(CachelibWrapperTest, CreateFromString) { ROCKSDB_NAMESPACE::Status::OK()); auto rco = scache->GetOptions(); ASSERT_NE(rco, nullptr); - ASSERT_STREQ(rco->cachename, "foo"); - ASSERT_STREQ(rco->filename, "bar"); + ASSERT_STREQ(rco->cacheName, "foo"); + ASSERT_STREQ(rco->fileName, "bar"); ASSERT_EQ(rco->size, 1000000); - ASSERT_EQ(rco->block_size, 8192); - ASSERT_EQ(rco->region_size, 4096); - ASSERT_EQ(rco->probability, 0.5); + ASSERT_EQ(rco->blockSize, 8192); + ASSERT_EQ(rco->regionSize, 4096); + ASSERT_EQ(rco->admProbability, 0.5); ASSERT_EQ(rco->admPolicy, "unknown"); - ASSERT_EQ(rco->max_write_rate, 1024); - ASSERT_EQ(rco->admission_write_rate, 2048); - ASSERT_EQ(rco->volatile_size, 2000000); - ASSERT_EQ(rco->bucket_power, 48); - ASSERT_EQ(rco->lock_power, 24); + ASSERT_EQ(rco->maxWriteRate, 1024); + ASSERT_EQ(rco->admissionWriteRate, 2048); + ASSERT_EQ(rco->volatileSize, 2000000); + ASSERT_EQ(rco->bktPower, 48); + ASSERT_EQ(rco->lockPower, 24); } #endif // ROCKSDB_LITE From d825c15aba0001dba4b9b36fe303d1e7fd2b16c6 Mon Sep 17 00:00:00 2001 From: mrambacher Date: Mon, 5 Dec 2022 11:39:57 -0500 Subject: [PATCH 08/11] Fix test --- .../tests/CachelibWrapperTest.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp index ab9bdb92bd..b295db2d16 100644 --- a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp @@ -15,6 +15,7 @@ */ #include "plugin/cachelib/CachelibWrapper.h" +#include "rocksdb/convenience.h" #include "cachelib/common/Utils.h" #include "test_util/testharness.h" @@ -563,38 +564,38 @@ TEST_F(CachelibWrapperTest, LargeItemTest) { #ifndef ROCKSDB_LITE TEST_F(CachelibWrapperTest, CreateFromString) { - ROCKSDB::NAMESPACE::ConfigOptions opts; - opts.invoke_prepare_options = true; + ROCKSDB_NAMESPACE::ConfigOptions opts; + opts.invoke_prepare_options = false; std::shared_ptr scache; std::string props = "cachename=foo;" "filename=bar;" - "size=1000000;" + "size=1048576;" "block_size=8192;" "region_size=4096;" "policy=unknown;" "probablity=0.50;" "max_write_rate=1024;" "admission_write_rate=2048;" - "volatile_size=2000000;" + "volatile_size=524288;" "bucket_power=48;" "lock_power=24;"; ASSERT_EQ(ROCKSDB_NAMESPACE::SecondaryCache::CreateFromString(opts, - props + "id=" + RocksCachelibWrapper::kClassName() + + props + "id=" + RocksCachelibWrapper::kClassName(), &scache), ROCKSDB_NAMESPACE::Status::OK()); auto rco = scache->GetOptions(); ASSERT_NE(rco, nullptr); - ASSERT_STREQ(rco->cacheName, "foo"); - ASSERT_STREQ(rco->fileName, "bar"); - ASSERT_EQ(rco->size, 1000000); + ASSERT_EQ(rco->cacheName, "foo"); + ASSERT_EQ(rco->fileName, "bar"); + ASSERT_EQ(rco->size, 1048576); ASSERT_EQ(rco->blockSize, 8192); ASSERT_EQ(rco->regionSize, 4096); ASSERT_EQ(rco->admProbability, 0.5); ASSERT_EQ(rco->admPolicy, "unknown"); ASSERT_EQ(rco->maxWriteRate, 1024); ASSERT_EQ(rco->admissionWriteRate, 2048); - ASSERT_EQ(rco->volatileSize, 2000000); + ASSERT_EQ(rco->volatileSize, 524288; ASSERT_EQ(rco->bktPower, 48); ASSERT_EQ(rco->lockPower, 24); From 75a540c6e5b6cad993cd15b163fbc3f3f3a34b38 Mon Sep 17 00:00:00 2001 From: mrambacher Date: Mon, 5 Dec 2022 13:40:29 -0500 Subject: [PATCH 09/11] Cleanup tests --- .../rocks_secondary_cache/CachelibWrapper.cpp | 36 +++++++------------ .../tests/CachelibWrapperTest.cpp | 24 ++++++------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp index 7c0be08f8d..5094e29b80 100644 --- a/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/CachelibWrapper.cpp @@ -134,30 +134,18 @@ class RocksCachelibWrapperHandle : public rocksdb::SecondaryCacheResultHandle { static std::unordered_map rocks_cachelib_type_info = { #ifndef ROCKSDB_LITE - {"cachename", - {offsetof(struct RocksCachelibOptions, cacheName), ROCKSDB_NAMESPACE::OptionType::kString}}, - {"filename", - {offsetof(struct RocksCachelibOptions, fileName), ROCKSDB_NAMESPACE::OptionType::kString}}, - {"size", - {offsetof(struct RocksCachelibOptions, size), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, - {"block_size", - {offsetof(struct RocksCachelibOptions, blockSize), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, - {"region_size", - {offsetof(struct RocksCachelibOptions, regionSize), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, - {"policy", - {offsetof(struct RocksCachelibOptions, admPolicy), ROCKSDB_NAMESPACE::OptionType::kString}}, - {"probability", - {offsetof(struct RocksCachelibOptions, admProbability), ROCKSDB_NAMESPACE::OptionType::kDouble}}, - {"max_write_rate", - {offsetof(struct RocksCachelibOptions, maxWriteRate), ROCKSDB_NAMESPACE::OptionType::kUInt64T}}, - {"admission_write_rate", - {offsetof(struct RocksCachelibOptions, admissionWriteRate), ROCKSDB_NAMESPACE::OptionType::kUInt64T}}, - {"volatile_size", - {offsetof(struct RocksCachelibOptions, volatileSize), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, - {"bucket_power", - {offsetof(struct RocksCachelibOptions, bktPower), ROCKSDB_NAMESPACE::OptionType::kUInt32T}}, - {"lock_power", - {offsetof(struct RocksCachelibOptions, lockPower), ROCKSDB_NAMESPACE::OptionType::kUInt32T}}, + {"cachename", {offsetof(struct RocksCachelibOptions, cacheName), ROCKSDB_NAMESPACE::OptionType::kString}}, + {"filename", {offsetof(struct RocksCachelibOptions, fileName), ROCKSDB_NAMESPACE::OptionType::kString}}, + {"size", {offsetof(struct RocksCachelibOptions, size), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, + {"block_size", {offsetof(struct RocksCachelibOptions, blockSize), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, + {"region_size",{offsetof(struct RocksCachelibOptions, regionSize), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, + {"policy", {offsetof(struct RocksCachelibOptions, admPolicy), ROCKSDB_NAMESPACE::OptionType::kString}}, + {"probability",{offsetof(struct RocksCachelibOptions, admProbability), ROCKSDB_NAMESPACE::OptionType::kDouble}}, + {"max_write_rate",{offsetof(struct RocksCachelibOptions, maxWriteRate), ROCKSDB_NAMESPACE::OptionType::kUInt64T}}, + {"admission_write_rate",{offsetof(struct RocksCachelibOptions, admissionWriteRate), ROCKSDB_NAMESPACE::OptionType::kUInt64T}}, + {"volatile_size",{offsetof(struct RocksCachelibOptions, volatileSize), ROCKSDB_NAMESPACE::OptionType::kSizeT}}, + {"bucket_power", {offsetof(struct RocksCachelibOptions, bktPower), ROCKSDB_NAMESPACE::OptionType::kUInt32T}}, + {"lock_power", {offsetof(struct RocksCachelibOptions, lockPower), ROCKSDB_NAMESPACE::OptionType::kUInt32T}}, #endif // ROCKSDB_LITE }; } // namespace diff --git a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp index b295db2d16..1318d55630 100644 --- a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp @@ -569,14 +569,14 @@ TEST_F(CachelibWrapperTest, CreateFromString) { std::shared_ptr scache; std::string props = "cachename=foo;" "filename=bar;" - "size=1048576;" - "block_size=8192;" + "size=10000;" + "block_size=512;" "region_size=4096;" + "volatile_size=1024;" "policy=unknown;" - "probablity=0.50;" - "max_write_rate=1024;" - "admission_write_rate=2048;" - "volatile_size=524288;" + "probablity=0.42;" + "max_write_rate=11;" + "admission_write_rate=22;" "bucket_power=48;" "lock_power=24;"; @@ -588,14 +588,14 @@ TEST_F(CachelibWrapperTest, CreateFromString) { ASSERT_NE(rco, nullptr); ASSERT_EQ(rco->cacheName, "foo"); ASSERT_EQ(rco->fileName, "bar"); - ASSERT_EQ(rco->size, 1048576); - ASSERT_EQ(rco->blockSize, 8192); + ASSERT_EQ(rco->size, 10000); + ASSERT_EQ(rco->blockSize, 512); ASSERT_EQ(rco->regionSize, 4096); - ASSERT_EQ(rco->admProbability, 0.5); + ASSERT_EQ(rco->admProbability, 0.42); ASSERT_EQ(rco->admPolicy, "unknown"); - ASSERT_EQ(rco->maxWriteRate, 1024); - ASSERT_EQ(rco->admissionWriteRate, 2048); - ASSERT_EQ(rco->volatileSize, 524288; + ASSERT_EQ(rco->maxWriteRate, 11); + ASSERT_EQ(rco->admissionWriteRate, 22); + ASSERT_EQ(rco->volatileSize, 1024); ASSERT_EQ(rco->bktPower, 48); ASSERT_EQ(rco->lockPower, 24); From 28a8ae3acbf024edfe2ebb4977077142edcc876e Mon Sep 17 00:00:00 2001 From: mrambacher Date: Fri, 23 Dec 2022 10:59:51 -0500 Subject: [PATCH 10/11] Add README, fix test issue --- .../adaptor/rocks_secondary_cache/README.md | 44 +++++++++++++++++++ .../tests/CachelibWrapperTest.cpp | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 cachelib/adaptor/rocks_secondary_cache/README.md diff --git a/cachelib/adaptor/rocks_secondary_cache/README.md b/cachelib/adaptor/rocks_secondary_cache/README.md new file mode 100644 index 0000000000..92011a134b --- /dev/null +++ b/cachelib/adaptor/rocks_secondary_cache/README.md @@ -0,0 +1,44 @@ +# RocksDB CacheLib Secondary Cache + +This directory contains files and tests for building Cachelib as a SecondaryCache for RocksDB. + +# Build + +Currently the build is only supported via cmake. + +First, build cachelib through the normal build procedure. + +To build under RocksDB, link this directory adaptor/rocksdb_secondary_cache) to the plugins/cachelib directory under RocksDB: +``` +$ln -s .../secondary_cache .../plugins/cachelib). +``` +This will allow RocksDB to find and build the CacheLib plugin code. + +Next, under the RocksDB build directory, instruct RocksDB to build and include the cachelib plugin: +``` +$cmake -DROCKSDB_PLUGINS=cachelib -DCMAKE_PREFIX_PATH= -DCMAKE_MODULE_PATH="" -DWITH_GFLAGS=OFF .. +``` +where the prefix path points to the opt/cachelib directory and module path points to the cachelib/cmake directory. + +Finally, build RocksDB using "make". + +# Using the RocksDB Cachelib Secondary Cache + +The Secondary Cache can be created via either the SecondaryCache::CreateFromString or NewRocksCachelibWrapper APIs. +``` +SecondaryCache::CreateFromString(..., "id=RocksCachelibWrapper; ..."); + +RoksCachelibOptions options; +NewRocksCachelibWrapper(options); +``` + +When using CreateFromString API, the options can be specified as name-value pairs on the command line. The mapping between the field names and options is found in CacheLibWrapper.cpp. + +# Issues and TODO + +* There are incompatibilities between RocksDB and Cachelib on the version of GTEST required and supported. In order to successfully build, you must use the GTEST version in Cachelib and remove the gtest from the RocksDB build. This requirement is true whether or not you are building tests. In the RocksDB build, you must remove GTEST from the "include_directories" and "add_subdirectories" and add " -Wno-error=deprecated-declarations" to the CMAKE_CXX_FLAGS. You may also need to add "-Wno-error=sign-compare" to build the RocksDB tests, depending on your compiler. + +* RocksDB does not currently enable plugins to build their own tests (see PR11052). When the CachelibWrapperTest is added, additional link libraries may be required (See the CMakeLists.txt file). No investigation as to the reason has been undertaken. + + + diff --git a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp index 1318d55630..6a566aabfd 100644 --- a/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp +++ b/cachelib/adaptor/rocks_secondary_cache/tests/CachelibWrapperTest.cpp @@ -574,7 +574,7 @@ TEST_F(CachelibWrapperTest, CreateFromString) { "region_size=4096;" "volatile_size=1024;" "policy=unknown;" - "probablity=0.42;" + "probability=0.42;" "max_write_rate=11;" "admission_write_rate=22;" "bucket_power=48;" From 52e2d8e908ad07efe643f6f1f9a4baf2aab8a721 Mon Sep 17 00:00:00 2001 From: mrambacher Date: Fri, 23 Dec 2022 12:12:41 -0500 Subject: [PATCH 11/11] Fix typos --- cachelib/adaptor/rocks_secondary_cache/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cachelib/adaptor/rocks_secondary_cache/README.md b/cachelib/adaptor/rocks_secondary_cache/README.md index 92011a134b..09cb067caa 100644 --- a/cachelib/adaptor/rocks_secondary_cache/README.md +++ b/cachelib/adaptor/rocks_secondary_cache/README.md @@ -10,13 +10,13 @@ First, build cachelib through the normal build procedure. To build under RocksDB, link this directory adaptor/rocksdb_secondary_cache) to the plugins/cachelib directory under RocksDB: ``` -$ln -s .../secondary_cache .../plugins/cachelib). +$ln -s .../secondary_cache .../plugins/cachelib ``` This will allow RocksDB to find and build the CacheLib plugin code. Next, under the RocksDB build directory, instruct RocksDB to build and include the cachelib plugin: ``` -$cmake -DROCKSDB_PLUGINS=cachelib -DCMAKE_PREFIX_PATH= -DCMAKE_MODULE_PATH="" -DWITH_GFLAGS=OFF .. +$cmake -DROCKSDB_PLUGINS=cachelib -DCMAKE_PREFIX_PATH= -DCMAKE_MODULE_PATH="" .. ``` where the prefix path points to the opt/cachelib directory and module path points to the cachelib/cmake directory.