Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiaoshuai123 committed Apr 22, 2024
1 parent 6bf07a0 commit 7fd94d7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand Down
2 changes: 1 addition & 1 deletion src/praft/praft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 11 additions & 7 deletions src/store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<DB>(i, g_config.dbpath, g_config.db_instance_num);
backends_.push_back(std::move(db));
}
Expand All @@ -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()) {
Expand All @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions src/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<TaskArg, std::string> 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<TaskArg, std::string>& a, bool s = false)
Expand All @@ -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<std::unique_ptr<DB>> backends_;
};
Expand Down

0 comments on commit 7fd94d7

Please sign in to comment.