提交 6422356a 编写于 作者: C Chinmay Kamat 提交者: Facebook Github Bot

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
上级 5d809ece
......@@ -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}},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册