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

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion db/repair.cc
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions db/repair_test.cc
Expand Up @@ -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}},
Expand Down