Skip to content
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

Open
wants to merge 44 commits into
base: main
Choose a base branch
from

Conversation

mrambacher
Copy link
Contributor

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.

Copy link
Contributor

@pdillinger pdillinger left a 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


void WaitAll(std::vector<Handle*>& /*handles*/) override {}
CacheShard* ClockCache::GetShard(uint32_t shard) {
#ifdef SUPPORT_CLOCK_CACHE
Copy link
Contributor

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.

cache/sharded_cache.h Outdated Show resolved Hide resolved
@@ -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_;
Copy link
Contributor

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.

} else {
auto ipos = id.find("@");
auto tpos = that_id.find("@");
if (ipos != std::string::npos && tpos != std::string::npos) {
Copy link
Contributor

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>?

@mrambacher
Copy link
Contributor Author

@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!

@pdillinger
Copy link
Contributor

The errors are in the output (with enough scrolling)

cache/cache_bench_tool.cc:809:35: warning: Use of zero-allocated memory
      dbs_[db_i].orig_file_number += 1;
                                  ^
cache/cache_bench_tool.cc:900:32: warning: Use of zero-allocated memory
      dbs_[0].orig_file_number = 0;
                               ^
2 warnings generated.

@pdillinger
Copy link
Contributor

Weird error. I thought it was talking about zero-initialized memory, but I think it means db_count might be zero. If you coerce or assert db_count >= 1 that should suffice.

@facebook-github-bot
Copy link
Contributor

@pdillinger has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@pdillinger pdillinger left a 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

Copy link
Contributor

@jay-zhuang jay-zhuang left a 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 Show resolved Hide resolved
cache/cache.cc Outdated
if (!s.ok()) {
*errmsg = s.ToString();
}
guard->reset(clock.release());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
guard->reset(clock.release());
*guard = std::move(clock);

cache/cache.cc Outdated
if (!s.ok()) {
*errmsg = s.ToString();
}
guard->reset(clock.release());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
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()), "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
guard->reset(new lru_cache::LRUCache());
*guard = std::make_unique<lru_cache::LRUCache>();

class ClockCacheShard;

struct ClockCacheOptions {
ClockCacheOptions() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
ClockCacheOptions() {}
ClockCacheOptions() = default;

Comment on lines 75 to 80
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;
Copy link
Contributor

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:

Suggested change
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
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("@");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
*addr = id.find("@");
*addr = id.find('@');

auto hoff = std::string::npos;
*addr = id.find("@");
if (*addr != std::string::npos) {
hoff = id.find("#", *addr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hoff = id.find("#", *addr);
hoff = id.find('#', *addr);

Merge to latest cache implementations.  Fixed some issues with tests and initializations.
@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@mrambacher
Copy link
Contributor Author

@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!

@pdillinger
Copy link
Contributor

May have chosen a bad time to merge 🙁 (#10434 )

@pdillinger
Copy link
Contributor

Also, we are concerned about the race conditions in customizable / setoptions infrastructure, e.g. #10079 and #10375. Plus we're cautious about other functional regressions like the one patched in #10378

@mrambacher
Copy link
Contributor Author

Also, we are concerned about the race conditions in customizable / setoptions infrastructure, e.g. #10079 and #10375. Plus we're cautious about other functional regressions like the one patched in #10378

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.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants