MCPcopy Create free account
hub / github.com/Tencent/phxqueue / LoadCheckpointState

Method LoadCheckpointState

phxqueue/lock/locksm.cpp:281–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279}
280
281int LockSM::LoadCheckpointState(const int paxos_group_id,
282 const string &checkpoint_tmp_file_dir_path,
283 const vector<string> &file_list,
284 const uint64_t checkpoint_instance_id) {
285 comm::LockSMBP::GetThreadInstance()->
286 OnLoadCheckpointState(impl_->lock->GetTopicID(), paxos_group_id);
287 QLInfo("topic_id %d paxos_group_id %d dir \"%s\" cp_instance_id %llu",
288 impl_->lock->GetTopicID(), paxos_group_id,
289 checkpoint_tmp_file_dir_path.c_str(), checkpoint_instance_id);
290
291 // 1. check
292 if (checkpoint_tmp_file_dir_path.empty() || 0 >= file_list.size()) {
293 QLErr("topic_id %d paxos_group_id %d dir %s cp_instance_id %llu file_list empty",
294 impl_->lock->GetTopicID(), paxos_group_id,
295 checkpoint_tmp_file_dir_path.c_str(), checkpoint_instance_id);
296
297 return -1;
298 }
299
300 impl_->lock->GetLockMgr()->leveldb(paxos_group_id).Dispose();
301
302 string mirror_path{impl_->mirror_dir_path + to_string(paxos_group_id)};
303
304 // 2. clear mirror
305 int ret{comm::utils::RecursiveRemoveDir(mirror_path, true, false)};
306 if (0 != ret) {
307 QLErr("topic_id %d paxos_group_id %d RecursiveRemoveDir \"%s\" err %d",
308 impl_->lock->GetTopicID(), paxos_group_id, mirror_path.c_str(), ret);
309
310 return -1;
311 }
312
313 // 3. copy files from tmp to mirror
314 ret = comm::utils::RecursiveCopyDir(checkpoint_tmp_file_dir_path, mirror_path, true, false);
315 if (0 != ret) {
316 QLErr("topic_id %d paxos_group_id %d RecursiveCopyDir \"%s\" -> \"%s\" err %d",
317 impl_->lock->GetTopicID(), paxos_group_id,
318 checkpoint_tmp_file_dir_path.c_str(), mirror_path.c_str(), ret);
319
320 return -1;
321 }
322
323 //for (auto &&file_path : file_list) {
324 // int sub_ret{CopyFile(checkpoint_tmp_file_dir_path + "/" +
325 // file_path, mirror_path + "/" + file_path)};
326 // CLogImpt("topic_id %d paxos_group_id %d file \"%s\"",
327 // impl_->lock->GetTopicID(), paxos_group_id, file_path.c_str());
328 // if (0 != sub_ret) {
329 // CLogErr("topic_id %d paxos_group_id %d CopyFile \"%s\" err %d",
330 // impl_->lock->GetTopicID(), paxos_group_id, file_path.c_str(), ret);
331
332 // return -1;
333 // }
334 //}
335
336 // no need to recover map and leveldb, paxos will restart myself immediately
337
338 constexpr uint32_t sleep_s{10u};

Callers

nothing calls this directly

Calls 6

RecursiveRemoveDirFunction · 0.85
RecursiveCopyDirFunction · 0.85
OnLoadCheckpointStateMethod · 0.80
GetLockMgrMethod · 0.80
GetTopicIDMethod · 0.45
DisposeMethod · 0.45

Tested by

no test coverage detected