Skip to content

Commit

Permalink
fix(dict): issues with user db recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Dec 28, 2019
1 parent 89b7df2 commit 0f3d0df
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
5 changes: 1 addition & 4 deletions src/rime/dict/level_db.cc
Expand Up @@ -234,10 +234,7 @@ bool LevelDb::Recover() {
auto status = leveldb::RepairDB(file_name(), leveldb::Options());
if (status.ok()) {
LOG(INFO) << "repair finished.";
if (Close() && Open()) {
LOG(INFO) << "db recovery successful.";
return true;
}
return true;
}
LOG(ERROR) << "db recovery failed: " << status.ToString();
return false;
Expand Down
10 changes: 5 additions & 5 deletions src/rime/dict/user_db_recovery_task.cc
Expand Up @@ -30,15 +30,15 @@ bool UserDbRecoveryTask::Run(Deployer* deployer) {
db_->enable();
}
BOOST_SCOPE_EXIT_END
//
auto r = As<Recoverable>(db_);
if (r && r->Recover()) {
return true;
}

if (db_->loaded()) {
LOG(WARNING) << "cannot recover loaded db '" << db_->name() << "'.";
return false;
}
auto r = As<Recoverable>(db_);
if (r && r->Recover()) {
return true;
}
// repair didn't work on the damanged db file; remove and recreate it
LOG(INFO) << "recreating db file.";
if (db_->Exists()) {
Expand Down
6 changes: 2 additions & 4 deletions src/rime/dict/user_dictionary.cc
Expand Up @@ -153,7 +153,7 @@ void UserDictionary::Attach(const an<Table>& table,
}

bool UserDictionary::Load() {
if (!db_)
if (!db_ || db_->disabled())
return false;
if (!db_->loaded() && !db_->Open()) {
// try to recover managed db in available work thread
Expand All @@ -165,9 +165,7 @@ bool UserDictionary::Load() {
}
return false;
}
if (!FetchTickCount() && !Initialize())
return false;
return true;
return FetchTickCount() || Initialize();
}

bool UserDictionary::loaded() const {
Expand Down

0 comments on commit 0f3d0df

Please sign in to comment.