-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable the CacheLibWrapper class as a RocksDB Plugin #184
Open
mrambacher
wants to merge
12
commits into
facebook:main
Choose a base branch
from
mrambacher:CachelibRocksDB
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+227
−90
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
00c775a
First pass at adding Cachelib as Pluggable Secondary Cache
mrambacher fea3f81
Next pass at Cachelib/Rocks integration
mrambacher 6130377
Add namespace
mrambacher 8392fb2
Attempt to fix test to build
mrambacher 7f3b1a1
Another build change
mrambacher ec1186f
Next pass at CacheLib as a SecondaryCache
mrambacher 143ac0d
Fix bad var names
mrambacher d825c15
Fix test
mrambacher 75a540c
Cleanup tests
mrambacher 28a8ae3
Add README, fix test issue
mrambacher 52e2d8e
Fix typos
mrambacher 7e62abf
Merge remote-tracking branch 'upstream/main' into CachelibRocksDB
mrambacher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
First pass at adding Cachelib as Pluggable Secondary Cache
commit 00c775a365970cd8f61404fc86e9cca21c81ce6f
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<FbCache>; | ||
|
||
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<FbCache> 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<FbCache>(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<rocksdb::SecondaryCache> NewRocksCachelibWrapper( | ||
const RocksCachelibOptions& opts) { | ||
std::unique_ptr<FbCache> cache; | ||
std::unique_ptr<cachelib::CacheAdmin> admin; | ||
cachelib::PoolId defaultPool; | ||
FbCacheConfig config; | ||
NvmCacheConfig nvmConfig; | ||
|
@@ -274,15 +296,23 @@ std::unique_ptr<rocksdb::SecondaryCache> NewRocksCachelibWrapper( | |
defaultPool = | ||
cache->addPool("default", cache->getCacheMemoryStats().cacheSize); | ||
|
||
if (opts.fb303Stats) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is CacheAdmin for stats not supported? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @anand1976 This is another piece that is internal to Facebook/Meta and is not in the public API. |
||
cachelib::CacheAdmin::Config adminConfig; | ||
adminConfig.oncall = opts.oncallName; | ||
admin = std::make_unique<cachelib::CacheAdmin>(*cache, adminConfig); | ||
} | ||
|
||
return std::unique_ptr<rocksdb::SecondaryCache>(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<ROCKSDB_NAMESPACE::SecondaryCache>(CachelibWrapper::kClassName(), | ||
[](const std::string& uri, std::unique_ptr<ROCKSDB_NAMESPACE::SecondaryCache>* 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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this not be supported anymore? Internally, we need this API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anand1976 This is a feature that is internal to Facebook/Meta. The header file that is required for this is not part of the public API.