-
Notifications
You must be signed in to change notification settings - Fork 304
Extend cachbench with value validation #131
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -50,8 +50,10 @@ uint64_t Cache<Allocator>::fetchNandWrites() const { | |||
template <typename Allocator> | ||||
Cache<Allocator>::Cache(const CacheConfig& config, | ||||
ChainedItemMovingSync movingSync, | ||||
std::string cacheDir) | ||||
std::string cacheDir, | ||||
bool touchValue) | ||||
: config_(config), | ||||
touchValue_(touchValue), | ||||
nandBytesBegin_{fetchNandWrites()}, | ||||
itemRecords_(config_.enableItemDestructorCheck) { | ||||
constexpr size_t MB = 1024ULL * 1024ULL; | ||||
|
@@ -396,6 +398,18 @@ typename Cache<Allocator>::WriteHandle Cache<Allocator>::insertOrReplace( | |||
return rv; | ||||
} | ||||
|
||||
template <typename Allocator> | ||||
void Cache<Allocator>::touchValue(const ReadHandle& it) const { | ||||
XDCHECK(touchValueEnabled()); | ||||
|
||||
auto ptr = reinterpret_cast<const uint8_t*>(getMemory(it)); | ||||
|
||||
/* The accumulate call is intended to access all bytes of the value | ||||
* and nothing more. */ | ||||
auto sum = std::accumulate(ptr, ptr + getSize(it), 0ULL); | ||||
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. leave a comment here that accumulate is intended to access all bytes of the item and nothing more. 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. Done. |
||||
folly::doNotOptimizeAway(sum); | ||||
} | ||||
|
||||
template <typename Allocator> | ||||
typename Cache<Allocator>::ReadHandle Cache<Allocator>::find(Key key) { | ||||
auto findFn = [&]() { | ||||
|
@@ -406,6 +420,11 @@ typename Cache<Allocator>::ReadHandle Cache<Allocator>::find(Key key) { | |||
// find from cache and wait for the result to be ready. | ||||
auto it = cache_->find(key); | ||||
it.wait(); | ||||
|
||||
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. This code looks different from
Are you on a stale base commit for this PR ? 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. Done - rebased. |
||||
if (touchValueEnabled()) { | ||||
touchValue(it); | ||||
} | ||||
|
||||
return it; | ||||
}; | ||||
|
||||
|
@@ -431,6 +450,11 @@ typename Cache<Allocator>::WriteHandle Cache<Allocator>::findToWrite(Key key) { | |||
// find from cache and wait for the result to be ready. | ||||
auto it = cache_->findToWrite(key); | ||||
it.wait(); | ||||
|
||||
if (touchValueEnabled()) { | ||||
touchValue(it); | ||||
} | ||||
|
||||
return it; | ||||
}; | ||||
|
||||
|
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 touchValue be part of the CacheConfig ?
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.
nvm. I understand why it might not be a good idea to do that. We are really bending our back to add this code so that it fits under the place where find() api latency is measured and it is looking a bit convoluted. But that's fine for now.