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

enable PinnableSlice for RowCache #2492

Closed
wants to merge 8 commits into from

Conversation

sushmaad
Copy link

This patch enables using PinnableSlice for RowCache, changes include
not releasing the cache handle immediately after lookup in TableCache::Get, instead pass a Cleanble function which does Cache::RleaseHandle.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot
Copy link
Contributor

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

@@ -182,7 +182,7 @@ bool GetContext::SaveValue(const ParsedInternalKey& parsed_key,
}

void replayGetContextLog(const Slice& replay_log, const Slice& user_key,
GetContext* get_context) {
GetContext* get_context, Cleanable* val_pinner_clean) {
Copy link
Contributor

@maysamyabandeh maysamyabandeh Jun 26, 2017

Choose a reason for hiding this comment

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

To be consistent with the existing code, lets call it value_pinner. Lets rename it on other places too.

Copy link
Contributor

@maysamyabandeh maysamyabandeh left a comment

Choose a reason for hiding this comment

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

LGTM. Looking forward to a unit test.

@@ -336,10 +337,17 @@ Status TableCache::Get(const ReadOptions& options,

if (auto row_handle =
ioptions_.row_cache->Lookup(row_cache_key.GetUserKey())) {

Cleanable cache_entry_clean;
// Cleanable routine to release the cache entry
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets put the comment before the definition.

auto found_row_cache_entry = static_cast<const std::string*>(
ioptions_.row_cache->Value(row_handle));
replayGetContextLog(*found_row_cache_entry, user_key, get_context);
ioptions_.row_cache->Release(row_handle);
cache_entry_clean.RegisterCleanup(release_cache_entry_func,
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment to explain that the cleanup function will be delegated to PinnableSlice if the value is found, and otherwise will be invoked when this object is destructed in this code block.

@ot
Copy link
Contributor

ot commented Jun 26, 2017

I'll review this today, but I just wanted to point out that there's a typo in the title, should be PinnableSlice, not PinnacleSlice :)

@siying
Copy link
Contributor

siying commented Jun 26, 2017

@ot no wonder I thought of pineapple when I initially saw this PR.

Copy link
Contributor

@ot ot left a comment

Choose a reason for hiding this comment

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

Thanks! This also good to me as well, after the style changes are applied.

@@ -88,6 +88,7 @@ class GetContext {
};

void replayGetContextLog(const Slice& replay_log, const Slice& user_key,
GetContext* get_context);
GetContext* get_context,
Cleanable *val_pinner_clean = nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Convention in the rest of the code is to juxtapose the *to the type

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

db/db_test.cc Outdated
PinnableSlice value;
ASSERT_EQ(Get("foo", &value), "bar");
// Entry is already in cache, lookup will remove the element from lru
ASSERT_EQ(reinterpret_cast<LRUCache*>(options.row_cache.get())->TEST_GetLRUSize(), 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

can you make sure to run "make format"?

if (s.IsNotFound()) {
result = "NOT_FOUND";
} else if (!s.ok()) {
result = s.ToString();
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the motivation for mixing status and result value?

Copy link
Author

Choose a reason for hiding this comment

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

Just to keep the testcase format similar to RowCache Test

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we can have them not mixed? The convention in the code base is for the return value to be Status.

Copy link
Author

Choose a reason for hiding this comment

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

test cases for Get calls in db_test.cc are validated using ASSERT_EQ statements, which checks if the return value is same as the value expected. So result of DBTestBase::Get() returns actual value in case of success and returns status code strings incase of failure. If the code is confusing and looks mixed up, I can change it to
{
.
.
Status s = dbfull()->Get(options, dbfull()->DefaultColumnFamily(), k, v);
std::string result(v->data());
if (s.IsNotFound()) {
result = "NOT_FOUND";
} else if (!s.ok()) {
result = s.ToString();
}
return result;
}

which is exactly same as which is exactly same as std::string DBTestBase::Get(int cf, const std::string& k,
const Snapshot* snapshot) in db_test_util.cc

@@ -336,10 +337,21 @@ Status TableCache::Get(const ReadOptions& options,

if (auto row_handle =
ioptions_.row_cache->Lookup(row_cache_key.GetUserKey())) {

// Cleanable routine to release the cache entry
Cleanable cache_entry_clean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make sure to consider this comment? #2492 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please apply the comment?

Copy link
Author

Choose a reason for hiding this comment

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

can you let me know what comment you are mentioning here? I have put the comment before definition

Copy link
Contributor

@maysamyabandeh maysamyabandeh Jul 13, 2017

Choose a reason for hiding this comment

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

If you click on the link that is pasted in my comment:

Can you make sure to consider this comment? #2492 (comment)

it will take you to this comment:

To be consistent with the existing code, lets call it value_pinner. Lets rename it on other places too.

auto found_row_cache_entry = static_cast<const std::string*>(
ioptions_.row_cache->Value(row_handle));
replayGetContextLog(*found_row_cache_entry, user_key, get_context);
ioptions_.row_cache->Release(row_handle);
// If it comes here value is located on the cache, input PinnableSlice (get_context.pinnable_slice_) will now
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets try again to make the comment more clear.

It says "input PinnableSlice (get_context.pinnable_slice_) will now point to"? It is pointing now or it will point after replayGetContextLog?

Would be great to clarify these points in the comment:

  1. found_row_cache_entry points to the value on cache
  2. cache_entry_clean (that you will rename it to value_pinner) will have the cleanup procedure for the cached entry.
  3. After replayGetContextLog, get_context.pinnable_slice_ might point to the cached entry (or a copy based on that) and the value_pinner cleanups are delegated to get_context.pinnable_slice_
  4. The cached entry is released after get_context.pinnable_slice_ is reset.

Copy link
Author

Choose a reason for hiding this comment

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

  // If it comes here value is located on the cache.
  // found_row_cache_entry points to the value on cache,
  // and cache_entry_clean has cleanup procedure for the cached entry.
  // After replayGetContextLog() returns get_context.pinnable_slice_
  // will point to cache entry buffer ((or a copy based on that) and
  // cleanup routine under cache_entry_clean will be delegated to
  // get_context.pinnable_slice_. Cache entry is released when
  // get_context.pinnable_slice_ is reset

Let me know if it needs to be tweaked again

Copy link
Contributor

Choose a reason for hiding this comment

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

You wanted to rename cache_entry_clean to value_pinner.

Nits:
After replayGetContextLog() returns => After replayGetContextLog() returns,
((or a => (or a
is reset => is reset.

@sushmaad sushmaad changed the title enable PinnacleSlice for RowCache enable PinnableSlice for RowCache Jul 6, 2017
@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

ioptions_.row_cache->Release(row_handle);
// If it comes here value is located on the cache,
// found_row_cache_entry points to the value on cache,
// cache_entry_clean has cleanup procedure for the cached entry,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: // and cache_entry_clean has ...

To make it easier to read, lets have clear sentences with a begin and an end. In that interest, let finish this sentence here: "for the cached entry."

// If it comes here value is located on the cache,
// found_row_cache_entry points to the value on cache,
// cache_entry_clean has cleanup procedure for the cached entry,
// after replayGetContextLog() returns get_context.pinnable_slice_
Copy link
Contributor

Choose a reason for hiding this comment

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

after => After
"returns " => "returns " // one space is extra

// found_row_cache_entry points to the value on cache,
// cache_entry_clean has cleanup procedure for the cached entry,
// after replayGetContextLog() returns get_context.pinnable_slice_
// will point to cache entry buffer and
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please make this change: "entry buffer" => "entry buffer (or a copy based on that)"

// after replayGetContextLog() returns get_context.pinnable_slice_
// will point to cache entry buffer and
// cleanup routine under cache_entry_clean will be delegated to
// get_context.pinnable_slice_, cache entry is released when
Copy link
Contributor

Choose a reason for hiding this comment

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

", cache" => ". Cache"

@@ -336,10 +337,21 @@ Status TableCache::Get(const ReadOptions& options,

if (auto row_handle =
ioptions_.row_cache->Lookup(row_cache_key.GetUserKey())) {

// Cleanable routine to release the cache entry
Cleanable cache_entry_clean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please apply the comment?

// cleanup routine under cache_entry_clean will be delegated to
// get_context.pinnable_slice_, cache entry is released when
// get_context.pinnable_slice_ is reset
cache_entry_clean.RegisterCleanup(release_cache_entry_func,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please apply this comment: ee5273e#r124070427

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

result = std::string(v->data());
}
return result;
value = std::string(v->data());
Copy link
Contributor

Choose a reason for hiding this comment

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

What is that you need to convert PinnableSlice to string? Seems redundant, does not it? Can't the function that calls ::Get read the value from v?

db/db_test.cc Outdated
PinnableSlice pin_slice;
std::string value;
ASSERT_EQ(Get("foo", &pin_slice, value), Status::OK());
ASSERT_EQ(value, "bar");
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you can do pin_slice.ToString

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

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

@maysamyabandeh
Copy link
Contributor

LGTM. Will land if the tests pass.

@maysamyabandeh
Copy link
Contributor

@sushmaad can you run "make format" please.

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

@sushmaad updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

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

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

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

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.

5 participants