Skip to content

Commit

Permalink
Restart full sync if failing to reopen db
Browse files Browse the repository at this point in the history
  • Loading branch information
ShooterIT committed Mar 19, 2021
1 parent ff4187b commit a84174a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/replication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Status ReplicationThread::Start(std::function<void()> &&pre_fullsync_cb,
pre_fullsync_cb_ = std::move(pre_fullsync_cb);
post_fullsync_cb_ = std::move(post_fullsync_cb);

// Clean synced checkpoint fronm old master because replica starts to follow new master
// Clean synced checkpoint from old master because replica starts to follow new master
auto s = rocksdb::DestroyDB(srv_->GetConfig()->sync_checkpoint_dir, rocksdb::Options());
if (!s.ok()) {
LOG(WARNING) << "Can't clean synced checkpoint from master, error: " << s.ToString();
Expand Down
17 changes: 3 additions & 14 deletions src/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,6 @@ Status Storage::RestoreFromBackup() {
return s.ok() ? Status::OK() : Status(Status::DBBackupErr, s.ToString());
}

Status Storage::Reopen() {
auto s = Open();
if (!s.IsOK()) {
LOG(ERROR) << "[storage] Fail to reopen db, error: " << s.Msg();
LOG(ERROR) << "[storage] Exiting...";
exit(1);
}
LOG(INFO) << "[storage] Succeed reopening db";
return Status::OK();
}

Status Storage::RestoreFromCheckpoint() {
std::string dir = config_->sync_checkpoint_dir;
std::string tmp_dir = config_->db_dir + ".tmp";
Expand All @@ -345,14 +334,14 @@ Status Storage::RestoreFromCheckpoint() {
// But only try best effort to make data safe
auto s = backup_env_->RenameFile(config_->db_dir, tmp_dir);
if (!s.ok()) {
Reopen();
if (!Open().IsOK()) LOG(ERROR) << "[storage] Fail to reopen db";
return Status(Status::NotOK, "Fail to rename db dir, error: " + s.ToString());
}

// Rename checkpoint dir to db dir
if (!(s = backup_env_->RenameFile(dir, config_->db_dir)).ok()) {
backup_env_->RenameFile(tmp_dir, config_->db_dir);
Reopen();
if (!Open().IsOK()) LOG(ERROR) << "[storage] Fail to reopen db";
return Status(Status::NotOK, "Fail to rename checkpoint dir, error: " + s.ToString());
}

Expand All @@ -362,7 +351,7 @@ Status Storage::RestoreFromCheckpoint() {
LOG(WARNING) << "[storage] Fail to open master checkpoint, error: " << s2.Msg();
rocksdb::DestroyDB(config_->db_dir, rocksdb::Options());
backup_env_->RenameFile(tmp_dir, config_->db_dir);
Reopen();
if (!Open().IsOK()) LOG(ERROR) << "[storage] Fail to reopen db";
return Status(Status::DBOpenErr,
"Fail to open master checkpoint, error: " + s2.Msg());
}
Expand Down
1 change: 0 additions & 1 deletion src/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Storage {

Status Open(bool read_only);
Status Open();
Status Reopen();
Status OpenForReadOnly();
void CloseDB();
void InitOptions(rocksdb::Options *options);
Expand Down

0 comments on commit a84174a

Please sign in to comment.