-
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
Introduce options.check_flush_compaction_key_order #7467
Conversation
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.
@siying has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@siying has updated the pull request. You must reimport the pull request before landing. |
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.
@siying has imported this pull request. If you are a Facebook 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.
Thanks @siying for the PR. LGTM with a few minor comments.
db/output_validator.h
Outdated
paranoid_hash_ = | ||
Hash64(value.data(), value.size(), paranoid_hash_); | ||
} | ||
if (enable_order_check_) { |
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 feel that if we enable hash check, then we should also enable order check since its overhead is relatively low.
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.
The order check is likely to be more expensive than hash check. It needs to make a copy to every key, which is not cheap.
db/compaction/compaction_job.cc
Outdated
meta.file_creation_time = current_time; | ||
sub_compact->outputs.emplace_back( | ||
std::move(meta), cfd->internal_comparator(), | ||
/*enable_order_check*/ |
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.
/*enable_order_check=*/
db/builder.cc
Outdated
uint64_t paranoid_hash = 0; | ||
OutputValidator output_validator( | ||
internal_comparator, | ||
/*enable_order_check*/ |
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.
/*enable_order_check=*/
ASSERT_OK(db_->SetOptions({{"check_flush_compaction_key_order", "false"}})); | ||
DBImpl* dbi = static_cast_with_check<DBImpl>(db_); | ||
|
||
SyncPoint::GetInstance()->SetCallBack( |
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: maybe clear all callbacks after the test.
db/output_validator.h
Outdated
icmp_(_icmp), enable_order_check_(_enable_order_check), enable_hash_(_enable_hash) {} | ||
Status Add(const Slice& key, const Slice& value) { | ||
if (enable_hash_) { | ||
// Generate a rolling 64-bit hash of the key and values |
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 curious, any plan to make the hash algorithm configurable?
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.
The hash is not exposed to users, unless the hash is not good enough I don't see a reason to make it configerable.
hmm, the test failures seem legit and need be fixed. |
db/builder.cc
Outdated
} | ||
s = it->status(); | ||
if (s.ok() && check_hash != paranoid_hash) { | ||
if (s.ok() && output_validator.GetHash() != file_validator.GetHash()) { |
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.
It might be better to move this check inside the OutputValidator, so that others can be added later.
db/output_validator.h
Outdated
} | ||
if (enable_order_check_) { | ||
TEST_SYNC_POINT_CALLBACK("OutputValidator::Add:order_check", /*arg=*/nullptr); | ||
if (key.size() < 8) { |
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.
Any chance of making "8" a constant? Much easier to find and understand...
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.
Will do.
db/output_validator.h
Outdated
bool _enable_order_check, bool _enable_hash) : | ||
icmp_(_icmp), enable_order_check_(_enable_order_check), enable_hash_(_enable_hash) {} |
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 thought the coding standard only used an underscore prefix when assigning to structs, not classes?
db/output_validator.h
Outdated
Status Add(const Slice& key, const Slice& value) { | ||
if (enable_hash_) { |
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 we move the implementation into a C++ file instead of a header and clean up the includes?
@@ -375,6 +375,7 @@ class MemTableIterator : public InternalIterator { | |||
PERF_COUNTER_ADD(next_on_memtable_count, 1); | |||
assert(Valid()); | |||
iter_->Next(); | |||
TEST_SYNC_POINT_CALLBACK("MemTableIterator::Next:0", iter_); |
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 curious as to what this has to do with this change?
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 didn't find a good way to fake a memtable that generates out of order keys. If there is a better way, will do it.
db/corruption_test.cc
Outdated
Status s; | ||
delete db_; | ||
db_ = nullptr; | ||
s = DestroyDB(dbname_, options); |
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.
Should this status be asserted?
db/compaction/compaction_job.cc
Outdated
sub_compact->AddToBuilder(kv.first.Encode(), kv.second) | ||
.PermitUncheckedError(); |
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.
Don't you need to check this Status to see out of order keys?
@siying has updated the pull request. You must reimport the pull request before landing. |
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.
@siying has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
4927da0
to
b5bbce3
Compare
@siying has updated the pull request. You must reimport the pull request before landing. |
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.
@siying has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
b5bbce3
to
3a68b96
Compare
@siying has updated the pull request. You must reimport the pull request before landing. |
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.
@siying has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@siying has updated the pull request. You must reimport the pull request before landing. |
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.
@siying has imported this pull request. If you are a Facebook 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.
Awesome!
sub_compact->AddToBuilder(kv.first.Encode(), kv.second, | ||
paranoid_file_checks_); | ||
// Range tombstone is not supported by output validator yet. | ||
sub_compact->builder->Add(kv.first.Encode(), kv.second); |
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.
This fixes the problem with paranoid_file_checks
+ DeleteRange()
, right? @mrambacher would it solve the problem to extract this into a separate PR that we can easily backport to 6.12 and 6.13?
Summary: Introduce an new option options.check_flush_compaction_key_order, by default set to true, which checks key order of flush and compaction, and fail the operation if the order is violated. Also did minor refactor hash checking code, which consolidates the hashing logic to a vlidation class, where the key ordering logic is added. Test Plan: Add unit tests to validate the check can catch reordering in flush and compaction, and can be properly disabled.
48556c0
to
3801434
Compare
@siying has updated the pull request. You must reimport the pull request before landing. |
3801434
to
2a80b4b
Compare
@siying has updated the pull request. You must reimport the pull request before landing. |
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.
@siying has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
This pull request has been merged in 7508175. |
Summary: Introduce an new option options.check_flush_compaction_key_order, by default set to true, which checks key order of flush and compaction, and fail the operation if the order is violated. Also did minor refactor hash checking code, which consolidates the hashing logic to a vlidation class, where the key ordering logic is added. Pull Request resolved: facebook#7467 Test Plan: Add unit tests to validate the check can catch reordering in flush and compaction, and can be properly disabled. Reviewed By: riversand963 Differential Revision: D24010683 fbshipit-source-id: 8dd6292d2cda8006054e9ded7cfa4bf405f0527c
Summary:
Introduce an new option options.check_flush_compaction_key_order, by default set to true, which checks key order of flush and compaction, and fail the operation if the order is violated.
Also did minor refactor hash checking code, which consolidates the hashing logic to a vlidation class, where the key ordering logic is added.
Test Plan: Add unit tests to validate the check can catch reordering in flush and compaction, and can be properly disabled.