Acquire lock on DB LOCK file before starting repair. (#4435)

Summary:
This commit adds code to acquire lock on the DB LOCK file
before starting the repair process. This will prevent
multiple processes from performing repair on the same DB
simultaneously. Fixes repair_test to work with this change.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4435

Differential Revision: D10361499

Pulled By: riversand963

fbshipit-source-id: 3c512c48b7193d383b2279ccecabdb660ac1cf22
This commit is contained in:
Chinmay Kamat 2018-10-12 10:40:06 -07:00 committed by Facebook Github Bot
parent 5d809ecef7
commit 6422356a27
2 changed files with 12 additions and 1 deletions

View File

@ -163,11 +163,18 @@ class Repairer {
}
~Repairer() {
if (db_lock_ != nullptr) {
env_->UnlockFile(db_lock_);
}
delete table_cache_;
}
Status Run() {
Status status = FindFiles();
Status status = env_->LockFile(LockFileName(dbname_), &db_lock_);
if (!status.ok()) {
return status;
}
status = FindFiles();
if (status.ok()) {
// Discard older manifests and start a fresh one
for (size_t i = 0; i < manifests_.size(); i++) {
@ -245,6 +252,9 @@ class Repairer {
std::vector<uint64_t> logs_;
std::vector<TableInfo> tables_;
uint64_t next_file_number_;
// Lock over the persistent DB state. Non-nullptr iff successfully
// acquired.
FileLock* db_lock_;
Status FindFiles() {
std::vector<std::string> filenames;

View File

@ -313,6 +313,7 @@ TEST_F(RepairTest, RepairColumnFamilyOptions) {
ASSERT_EQ(comparator_name,
fname_and_props.second->comparator_name);
}
Close();
// Also check comparator when it's provided via "unknown" CF options
ASSERT_OK(RepairDB(dbname_, opts, {{"default", opts}},