-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Conversation
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! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@maysamyabandeh has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
table/get_context.cc
Outdated
@@ -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) { |
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.
To be consistent with the existing code, lets call it value_pinner. Lets rename it on other places too.
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. Looking forward to a unit test.
db/table_cache.cc
Outdated
@@ -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 |
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.
Lets put the comment before the definition.
db/table_cache.cc
Outdated
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, |
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.
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.
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 :) |
@ot no wonder I thought of pineapple when I initially saw this PR. |
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.
Thanks! This also good to me as well, after the style changes are applied.
table/get_context.h
Outdated
@@ -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); |
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.
Convention in the rest of the code is to juxtapose the *
to the type
@sushmaad updated the pull request - view changes - changes since last import |
@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); |
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 you make sure to run "make format"?
db/db_test_util.cc
Outdated
if (s.IsNotFound()) { | ||
result = "NOT_FOUND"; | ||
} else if (!s.ok()) { | ||
result = s.ToString(); |
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.
What is the motivation for mixing status and result value?
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.
Just to keep the testcase format similar to RowCache Test
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.
Do you think we can have them not mixed? The convention in the code base is for the return value to be Status.
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.
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
db/table_cache.cc
Outdated
@@ -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; |
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 you make sure to consider this comment? #2492 (comment)
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 you please apply the comment?
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 you let me know what comment you are mentioning here? I have put the comment before definition
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.
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.
db/table_cache.cc
Outdated
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 |
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.
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:
- found_row_cache_entry points to the value on cache
- cache_entry_clean (that you will rename it to value_pinner) will have the cleanup procedure for the cached entry.
- 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_
- The cached entry is released after get_context.pinnable_slice_ is reset.
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.
// 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
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.
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 updated the pull request - view changes - changes since last import |
@sushmaad updated the pull request - view changes - changes since last import |
811200a
to
ee5273e
Compare
@sushmaad updated the pull request - view changes - changes since last import |
@sushmaad updated the pull request - view changes - changes since last import |
a89a9d9
to
ee5273e
Compare
@sushmaad updated the pull request - view changes - changes since last import |
@sushmaad updated the pull request - view changes - changes since last import |
db/table_cache.cc
Outdated
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, |
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: // 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."
db/table_cache.cc
Outdated
// 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_ |
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.
after => After
"returns " => "returns " // one space is extra
db/table_cache.cc
Outdated
// 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 |
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 you please make this change: "entry buffer" => "entry buffer (or a copy based on that)"
db/table_cache.cc
Outdated
// 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 |
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.
", cache" => ". Cache"
db/table_cache.cc
Outdated
@@ -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; |
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 you please apply the comment?
db/table_cache.cc
Outdated
// 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, |
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 you please apply this comment: ee5273e#r124070427
@sushmaad updated the pull request - view changes - changes since last import |
@sushmaad updated the pull request - view changes - changes since last import |
db/db_test_util.cc
Outdated
result = std::string(v->data()); | ||
} | ||
return result; | ||
value = std::string(v->data()); |
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.
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"); |
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 you can do pin_slice.ToString
@sushmaad updated the pull request - view changes - changes since last import |
@maysamyabandeh has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
LGTM. Will land if the tests pass. |
@sushmaad can you run "make format" please. |
@sushmaad updated the pull request - view changes - changes since last import |
@maysamyabandeh has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
3092dc8
to
372568b
Compare
@sushmaad updated the pull request - view changes - changes since last import |
@maysamyabandeh has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
1 similar comment
@maysamyabandeh has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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.