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

Add hash of key/value checks when paranoid_file_checks=true #7134

Closed
wants to merge 1 commit into from

Conversation

mrambacher
Copy link
Contributor

When paraoid_files_checks=true, a rolling key-value hash is generated and compared to what is written to the file. If the values do not match, the SST file is rejected.

Code put in place for the check for both flush and compaction jobs. Corresponding test added to corruption_test.

Copy link
Contributor

@siying siying left a comment

Choose a reason for hiding this comment

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

Thanks for working on it!
I'm generally good with this workflow. But I hope @ajkr also takes a look and sees whether it is OK for him.
We need to update HISTORY.md to mention the new feature there.

db/builder.cc Show resolved Hide resolved
curr->paranoid_hash = Hash64(key.data(), key.size(), curr->paranoid_hash);
curr->paranoid_hash =
Hash64(value.data(), value.size(), curr->paranoid_hash);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this logic (Add() and paranoid check) into sub_compact->builder, so that in case in the future we add K/Vs in another place, we won't miss this paranoid check.

Btw, I remember there is another place we call sub_compact->builder->Add(), do we need to cover that path too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting TableBuilder::Add do this calculation? That could be done, but then all of the implementations of TableBuilder would need to perform the calculation (or pass it to a higher layer).

There are other places Builder::Add is called, to add things like range deletes. Should those also be covered by this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I meant to move to sub_compact. I didn't mean to move into Builder::Add(). I hope this hash check is independent of table builder implementation.

table/mock_table.cc Show resolved Hide resolved
Build(10, 2);
mock->SetCorruptionMode(mode);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
dbi->TEST_FlushMemTable();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I missed something but how do we make sure flush doesn't hit the corruption but the compaction range below hit it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re-arranged the test to set the corruption after the flush but before the compaction.

Copy link
Contributor

@siying siying left a comment

Choose a reason for hiding this comment

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

I still look forward to the new entry in HISTORY.md.

And I think we should mention this behavior in the code comment before the option paranoid_file_checks in options.h.

Other than that, the PR looks great to me. I still hope Andrew can take another look.

db/compaction/compaction_job.cc Outdated Show resolved Hide resolved
db/corruption_test.cc Outdated Show resolved Hide resolved
db/builder.cc Show resolved Hide resolved
@mrambacher mrambacher requested a review from ajkr July 17, 2020 15:14
Copy link
Contributor

@siying siying left a comment

Choose a reason for hiding this comment

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

It looks good to me. Andrew is busy for now, but since there is no interface change, I think it's OK for him to take a look later.
I can merge if it is rebased to recent master.

Copy link
Contributor

@siying siying left a comment

Choose a reason for hiding this comment

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

Also, don't forget to update advanced_options.h for paranoid_file_checks option to make it more accurate now.

When paraoid_files_checks=true, a rolling key-value hash is generated and compared to what is written to the file.  If the values do not match, the SST file is rejected.
@mrambacher
Copy link
Contributor Author

Rebased to master and squashed the commits. Updated the comment in advanced_options.h

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@siying siying left a comment

Choose a reason for hiding this comment

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

I copy&paste some warnings reported by some internal code analysis tool. Considering the long round-trip of running all tests, I might just merge the change, but I hope they are addressed in a follow-up PR.

@@ -27,6 +27,154 @@ stl_wrappers::KVMap MakeMockFile(
return stl_wrappers::KVMap(l, stl_wrappers::LessOfComparator(&icmp_));
}

class MockTableReader : public TableReader {
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning:

Encapsulate structs and classes defined in cpp files with anonymous namespace
Struct and class definitions should either be defined in a header file, declared in a header file with the same base name and path as the definition file, or in an anonymous namespace to prevent possible shadowing of other classes.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are similar calls in other new classes in the file.

}

// REQUIRES: Either Finish() or Abandon() has been called.
~MockTableBuilder() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

nternal_repo_rocksdb/repo/table/mock_table.cc:61:3: warning: '~MockTableReader' overrides a destructor but is not marked 'override'

There are similar calls in other new classes in the file.

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in d44cbc5.

codingrhythm pushed a commit to SafetyCulture/rocksdb that referenced this pull request Mar 5, 2021
…#7134)

Summary:
When paraoid_files_checks=true, a rolling key-value hash is generated and compared to what is written to the file.  If the values do not match, the SST file is rejected.

Code put in place for the check for both flush and compaction jobs.  Corresponding test added to corruption_test.

Pull Request resolved: facebook#7134

Reviewed By: cheng-chang

Differential Revision: D22646149

fbshipit-source-id: 8fde1984a1a11edd3bd82a413acffc5ea7aa683f
@mrambacher mrambacher deleted the ParanoidChecks branch May 16, 2022 16:37
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.

[Project] Validate all key values using a checksum when options.paranoid_file_checks is set
3 participants