-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Create Cache as a Customizable Object #10084
base: main
Are you sure you want to change the base?
Conversation
Allow db_bench and cache_bench to create Cache from URI.
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.
- Rebase or merge to fix protobuf CI issue
- Fix clang-analyze issue
- Add to HISTORY.md
- Other inline suggestions
cache/clock_cache.cc
Outdated
|
||
void WaitAll(std::vector<Handle*>& /*handles*/) override {} | ||
CacheShard* ClockCache::GetShard(uint32_t shard) { | ||
#ifdef SUPPORT_CLOCK_CACHE |
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.
I don't like all this repeated ifdef, but I can accept it since we're likely getting rid of this code soon.
@@ -535,9 +537,6 @@ class Cache { | |||
// thread safe and should only be called by the caller holding a reference | |||
// to each of the handles. | |||
virtual void WaitAll(std::vector<Handle*>& /*handles*/) {} | |||
|
|||
private: | |||
std::shared_ptr<MemoryAllocator> memory_allocator_; |
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.
OK by me. As long as we are clear in HISTORY.md that the API updates to Cache require some updates to custom implementations, I think it will be fine.
options/customizable.cc
Outdated
} else { | ||
auto ipos = id.find("@"); | ||
auto tpos = that_id.find("@"); | ||
if (ipos != std::string::npos && tpos != std::string::npos) { |
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.
Here or in API comment say that it ignores trailing @<anything>
?
@pdillinger I believe I resolved your comments. As for the "analyze" test that is failing, I tried on an ubuntu docker container with a comparable setup (same version of clang, etc) and see no errors. Would there be any way to get the errors off the Circle box into the log or some other way to tell what is failing? TIA! |
The errors are in the output (with enough scrolling)
|
Weird error. I thought it was talking about zero-initialized memory, but I think it means |
@pdillinger has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
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.
Seems to be good now
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.
LGTM. Can you please run benchmark and share the result. Thanks.
And a few minor format issues would be nice to fix.
cache/cache.cc
Outdated
if (!s.ok()) { | ||
*errmsg = s.ToString(); | ||
} | ||
guard->reset(clock.release()); |
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.
Nit:
guard->reset(clock.release()); | |
*guard = std::move(clock); |
cache/cache.cc
Outdated
if (!s.ok()) { | ||
*errmsg = s.ToString(); | ||
} | ||
guard->reset(clock.release()); |
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.
nit:
guard->reset(clock.release()); | |
*guard = std::move(clock); |
cache/cache.cc
Outdated
#ifndef ROCKSDB_LITE | ||
static std::once_flag once; | ||
std::call_once(once, [&]() { | ||
RegisterBuiltinCache(*(ObjectLibrary::Default().get()), ""); |
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.
nit:
RegisterBuiltinCache(*(ObjectLibrary::Default().get()), ""); | |
RegisterBuiltinCache(*(ObjectLibrary::Default()), ""); |
cache/cache.cc
Outdated
lru_cache::LRUCache::kClassName()), | ||
[](const std::string& /*uri*/, std::unique_ptr<Cache>* guard, | ||
std::string* /* errmsg */) { | ||
guard->reset(new lru_cache::LRUCache()); |
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.
nit:
guard->reset(new lru_cache::LRUCache()); | |
*guard = std::make_unique<lru_cache::LRUCache>(); |
cache/clock_cache.h
Outdated
class ClockCacheShard; | ||
|
||
struct ClockCacheOptions { | ||
ClockCacheOptions() {} |
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.
nit:
ClockCacheOptions() {} | |
ClockCacheOptions() = default; |
cache/clock_cache.h
Outdated
virtual std::string GetPrintableOptions() const override; | ||
|
||
virtual void SetCapacity(size_t capacity) override; | ||
virtual void SetStrictCapacityLimit(bool strict_capacity_limit) override; | ||
virtual size_t GetCapacity() const override; | ||
virtual bool HasStrictCapacityLimit() const override; |
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.
nit, virtual is redundant with override:
virtual std::string GetPrintableOptions() const override; | |
virtual void SetCapacity(size_t capacity) override; | |
virtual void SetStrictCapacityLimit(bool strict_capacity_limit) override; | |
virtual size_t GetCapacity() const override; | |
virtual bool HasStrictCapacityLimit() const override; | |
std::string GetPrintableOptions() const override; | |
void SetCapacity(size_t capacity) override; | |
void SetStrictCapacityLimit(bool strict_capacity_limit) override; | |
size_t GetCapacity() const override; | |
bool HasStrictCapacityLimit() const override; |
namespace { | ||
// Splits an IndividualId into its three components (name@addr#pid). | ||
// Returns true if the input id had all components and false otherwise. | ||
static bool IsIndividualId(const std::string& id, size_t* addr, |
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.
nit:
static bool IsIndividualId(const std::string& id, size_t* addr, | |
bool IsIndividualId(const std::string& id, size_t* addr, |
static bool IsIndividualId(const std::string& id, size_t* addr, | ||
size_t* pid = nullptr) { | ||
auto hoff = std::string::npos; | ||
*addr = id.find("@"); |
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.
nit:
*addr = id.find("@"); | |
*addr = id.find('@'); |
auto hoff = std::string::npos; | ||
*addr = id.find("@"); | ||
if (*addr != std::string::npos) { | ||
hoff = id.find("#", *addr); |
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.
hoff = id.find("#", *addr); | |
hoff = id.find('#', *addr); |
Merge to latest cache implementations. Fixed some issues with tests and initializations.
@mrambacher has updated the pull request. You must reimport the pull request before landing. |
@mrambacher has updated the pull request. You must reimport the pull request before landing. |
1 similar comment
@mrambacher has updated the pull request. You must reimport the pull request before landing. |
@mrambacher has updated the pull request. You must reimport the pull request before landing. |
@mrambacher has updated the pull request. You must reimport the pull request before landing. |
@pdillinger @jay-zhuang I think I have addressed all of the PR comments. Can this be merged soon? Keeping up with the Cache changes is getting to be tricky. Thanks! |
May have chosen a bad time to merge 🙁 (#10434 ) |
I created #10387 to eliminate many of the extra calls to PrepareOptions that were potential with #10375. In #9756, I changed code that will also eliminate some of the potential PrepareOptions calls (if bad name=value were passed to Configure), as well as improve the performance. I do not know if these PRs will address the other race conditions, but I would think they might and are worth a look. Also note that if Cache is not marked as Mutable, it cannot be changed via SetOptions. If the properties themselves (e.g. "capacity" are not mutable, they cannot be changed via SetOptions and only via the corresponding API. I doubt the same race condition(s) apply here. |
Fix merge related compilation issue
@mrambacher has updated the pull request. You must reimport the pull request before landing. |
This is a predecessor to #8998. This change adds the ability to create a Cache from the ObjectRegistry. Unlike 8998, each call to Cache::CreateFromString will create a new object -- no managed object code is involved here.