diff --git a/src/db.cc b/src/db.cc index 0129a925f..4c002e146 100644 --- a/src/db.cc +++ b/src/db.cc @@ -78,7 +78,7 @@ void DB::CreateCheckpoint(const std::string& path, bool sync) { } } -void DB::LoadDBFromCheckPoint(const std::string& path, bool sync) { +void DB::LoadDBFromCheckpoint(const std::string& path, bool sync) { opened_.store(false); auto checkpoint_path = path + '/' + std::to_string(db_index_); if (0 != pstd::IsDir(path)) { diff --git a/src/db.h b/src/db.h index 2794ac440..a127e4f16 100644 --- a/src/db.h +++ b/src/db.h @@ -28,7 +28,7 @@ class DB { void CreateCheckpoint(const std::string& path, bool sync); - void LoadDBFromCheckPoint(const std::string& path, bool sync = false); + void LoadDBFromCheckpoint(const std::string& path, bool sync = false); int GetDbIndex() { return db_index_; } diff --git a/src/praft/praft.cc b/src/praft/praft.cc index 4db70e580..ecb4b002c 100644 --- a/src/praft/praft.cc +++ b/src/praft/praft.cc @@ -656,7 +656,7 @@ int PRaft::on_snapshot_load(braft::SnapshotReader* reader) { assert(reader); auto reader_path = reader->get_path(); // xx/snapshot_0000001 auto path = g_config.dbpath + std::to_string(db_id_); // db/db_id - TasksVector tasks(1, {TaskType::kLoadDBFromCheckPoint, db_id_, {{TaskArg::kCheckpointPath, reader_path}}, true}); + TasksVector tasks(1, {TaskType::kLoadDBFromCheckpoint, db_id_, {{TaskArg::kCheckpointPath, reader_path}}, true}); PSTORE.HandleTaskSpecificDB(tasks); return 0; } diff --git a/src/store.cc b/src/store.cc index 4ef54d93f..e3c9e3560 100644 --- a/src/store.cc +++ b/src/store.cc @@ -24,10 +24,10 @@ void PStore::Init() { return; } - dbNum_ = g_config.databases; - backends_.reserve(dbNum_); + db_number_ = g_config.databases; + backends_.reserve(db_number_); if (g_config.backend == kBackEndRocksDB) { - for (int i = 0; i < dbNum_; i++) { + for (int i = 0; i < db_number_; i++) { auto db = std::make_unique(i, g_config.dbpath, g_config.db_instance_num); backends_.push_back(std::move(db)); } @@ -38,11 +38,11 @@ void PStore::Init() { void PStore::HandleTaskSpecificDB(const TasksVector& tasks) { std::for_each(tasks.begin(), tasks.end(), [this](const auto& task) { - if (task.db < 0 || task.db >= dbNum_) { + if (task.db < 0 || task.db >= db_number_) { WARN("The database index is out of range."); return; } - auto& db = backends_[task.db]; + auto& db = backends_.at(task.db); switch (task.type) { case kCheckpoint: { if (auto s = task.args.find(kCheckpointPath); s == task.args.end()) { @@ -54,14 +54,18 @@ void PStore::HandleTaskSpecificDB(const TasksVector& tasks) { db->CreateCheckpoint(path, task.sync); break; } - case kLoadDBFromCheckPoint: { + case kLoadDBFromCheckpoint: { if (auto s = task.args.find(kCheckpointPath); s == task.args.end()) { WARN("The critical parameter 'path' is missing for load a checkpoint."); return; } auto path = task.args.find(kCheckpointPath)->second; pstd::TrimSlash(path); - db->LoadDBFromCheckPoint(path, task.sync); + db->LoadDBFromCheckpoint(path, task.sync); + break; + } + case kEmpty: { + WARN("A empty task was passed in, not doing anything."); break; } default: diff --git a/src/store.h b/src/store.h index e8192f7e3..4bf15c5f3 100644 --- a/src/store.h +++ b/src/store.h @@ -17,17 +17,18 @@ namespace pikiwidb { -enum TaskType { kCheckpoint = 0, kLoadDBFromCheckPoint }; +enum TaskType { kCheckpoint = 0, kLoadDBFromCheckpoint, kEmpty }; enum TaskArg { kCheckpointPath = 0, }; struct TaskContext { - TaskType type; - int db; + TaskType type = kEmpty; + int db = -1; std::map args; - bool sync; + bool sync = false; + TaskContext() = delete; TaskContext(TaskType t, bool s = false) : type(t), sync(s) {} TaskContext(TaskType t, int d, bool s = false) : type(t), db(d), sync(s) {} TaskContext(TaskType t, int d, const std::map& a, bool s = false) @@ -49,12 +50,12 @@ class PStore { void HandleTaskSpecificDB(const TasksVector& task); - int GetDBNumber() const { return dbNum_; } + int GetDBNumber() const { return db_number_; } private: PStore() = default; - int dbNum_ = 0; + int db_number_ = 0; std::vector> backends_; };