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
main
Chinmay Kamat 6 years ago committed by Facebook Github Bot
parent 5d809ecef7
commit 6422356a27
  1. 12
      db/repair.cc
  2. 1
      db/repair_test.cc

@ -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;

@ -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}},

Loading…
Cancel
Save