diff --git a/db/repair.cc b/db/repair.cc index 195689418..a856de0eb 100644 --- a/db/repair.cc +++ b/db/repair.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 logs_; std::vector tables_; uint64_t next_file_number_; + // Lock over the persistent DB state. Non-nullptr iff successfully + // acquired. + FileLock* db_lock_; Status FindFiles() { std::vector filenames; diff --git a/db/repair_test.cc b/db/repair_test.cc index 72abd62a5..3422532da 100644 --- a/db/repair_test.cc +++ b/db/repair_test.cc @@ -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}},