Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiaoshuai123 committed Apr 16, 2024
1 parent 851d5b6 commit 0104b46
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ void DB::DoBgSave(const std::string& path, int i) {
}

void DB::CreateCheckpoint(const std::string& path) {
if (0 != pstd::CreatePath(path + '/' + std::to_string(db_index_))) {
WARN("Create dir {} fail !", path + '/' + std::to_string(db_index_));
auto tmp_path = path + '/' + std::to_string(db_index_);
if (0 != pstd::CreatePath(tmp_path)) {
WARN("Create dir {} fail !", tmp_path);
return;
}
checkpoint_manager_->CreateCheckpoint(path);
Expand Down
15 changes: 8 additions & 7 deletions src/praft/praft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,13 @@ void PRaft::AppendLog(const Binlog& log, std::promise<rocksdb::Status>&& promise
node_->apply(task);
}

void PRaft::add_all_files(const std::filesystem::path& dir, braft::SnapshotWriter* writer, const std::string& path) {
void PRaft::AddAllFiles(const std::filesystem::path& dir, braft::SnapshotWriter* writer, const std::string& path) {
assert(writer);
for (const auto& entry : std::filesystem::directory_iterator(dir)) {
if (entry.is_directory()) {
if (entry.path() != "." && entry.path() != "..") {
INFO("dir_path = {}", entry.path().string());
add_all_files(entry.path(), writer, path);
AddAllFiles(entry.path(), writer, path);
}
} else {
INFO("file_path = {}", std::filesystem::relative(entry.path(), path).string());
Expand All @@ -388,9 +389,9 @@ void PRaft::add_all_files(const std::filesystem::path& dir, braft::SnapshotWrite
}
}

void PRaft::recursive_copy(const std::filesystem::path& source, const std::filesystem::path& destination) {
void PRaft::RecursiveCopy(const std::filesystem::path& source, const std::filesystem::path& destination) {
if (std::filesystem::is_regular_file(source)) {
if (source.filename() == "__raft_snapshot_meta") {
if (source.filename() == PBRAFT_SNAPSHOT_META_FILE) {
return;
} else if (source.extension() == ".sst") {
// Create a hard link
Expand All @@ -407,7 +408,7 @@ void PRaft::recursive_copy(const std::filesystem::path& source, const std::files
}

for (const auto& entry : std::filesystem::directory_iterator(source)) {
recursive_copy(entry.path(), destination / entry.path().filename());
RecursiveCopy(entry.path(), destination / entry.path().filename());
}
}
}
Expand Down Expand Up @@ -453,7 +454,7 @@ void PRaft::on_snapshot_save(braft::SnapshotWriter* writer, braft::Closure* done
PSTORE.DoSomeThingSpecificDB(tasks);
PSTORE.WaitForCheckpointDone();
auto writer_path = writer->get_path();
add_all_files(writer_path, writer, writer_path);
AddAllFiles(writer_path, writer, writer_path);
}

int PRaft::on_snapshot_load(braft::SnapshotReader* reader) {
Expand All @@ -466,7 +467,7 @@ int PRaft::on_snapshot_load(braft::SnapshotReader* reader) {
pstd::DeleteDirIfExist(sub_path);
}
db_path.pop_back();
recursive_copy(reader_path, db_path);
RecursiveCopy(reader_path, db_path);
PSTORE.Init();
return 0;
}
Expand Down
5 changes: 3 additions & 2 deletions src/praft/praft.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace pikiwidb {

#define RAFT_DBID_LEN 32
#define PBRAFT_SNAPSHOT_META_FILE "__raft_snapshot_meta"

#define PRAFT PRaft::Instance()

Expand Down Expand Up @@ -139,9 +140,9 @@ class PRaft : public braft::StateMachine {
void on_start_following(const ::braft::LeaderChangeContext& ctx) override;

private:
void add_all_files(const std::filesystem::path& dir, braft::SnapshotWriter* writer, const std::string& path);
void AddAllFiles(const std::filesystem::path& dir, braft::SnapshotWriter* writer, const std::string& path);

void recursive_copy(const std::filesystem::path& source, const std::filesystem::path& destination);
void RecursiveCopy(const std::filesystem::path& source, const std::filesystem::path& destination);

private:
std::unique_ptr<brpc::Server> server_{nullptr}; // brpc
Expand Down

0 comments on commit 0104b46

Please sign in to comment.