| 310 | } |
| 311 | |
| 312 | comm::RetCode Lock::PaxosInit(const string &mirror_dir_path) { |
| 313 | comm::RetCode ret{comm::RetCode::RET_ERR_UNINIT}; |
| 314 | |
| 315 | phxpaxos::Options opts; |
| 316 | |
| 317 | // 1. set members |
| 318 | |
| 319 | const auto &topic_id(impl_->topic_id); |
| 320 | |
| 321 | shared_ptr<const config::TopicConfig> topic_config; |
| 322 | if (comm::RetCode::RET_OK != (ret = config::GlobalConfig::GetThreadInstance()-> |
| 323 | GetTopicConfigByTopicID(topic_id, topic_config))) { |
| 324 | QLErr("GetTopicConfig ret %d topic_id %d", as_integer(ret), topic_id); |
| 325 | |
| 326 | return ret; |
| 327 | } |
| 328 | |
| 329 | shared_ptr<const config::LockConfig> lock_config; |
| 330 | if (comm::RetCode::RET_OK != (ret = config::GlobalConfig::GetThreadInstance()-> |
| 331 | GetLockConfig(topic_id, lock_config))) { |
| 332 | QLErr("GetLockConfig ret %d topic_id %d", as_integer(ret), topic_id); |
| 333 | |
| 334 | return ret; |
| 335 | } |
| 336 | |
| 337 | shared_ptr<const config::proto::Lock> lock; |
| 338 | if (comm::RetCode::RET_OK != (ret = lock_config->GetLockByAddr(impl_->addr, lock))) { |
| 339 | QLErr("GetLockByAddr ret %d", as_integer(ret)); |
| 340 | |
| 341 | return ret; |
| 342 | } |
| 343 | |
| 344 | for (size_t i{0}; i < lock->addrs_size(); ++i) { |
| 345 | auto &&addr(lock->addrs(i)); |
| 346 | opts.vecNodeInfoList.emplace_back(addr.ip(), addr.paxos_port()); |
| 347 | } |
| 348 | |
| 349 | |
| 350 | // 2. set nr_group |
| 351 | opts.iGroupCount = impl_->opt.nr_group; |
| 352 | for (int i{0}; i < opts.iGroupCount; ++i) { |
| 353 | phxpaxos::GroupSMInfo sm_info; |
| 354 | sm_info.iGroupIdx = i; |
| 355 | unique_ptr<LockSM> sm(new LockSM(this, mirror_dir_path)); |
| 356 | sm_info.vecSMList.push_back(sm.get()); |
| 357 | sm_info.bIsUseMaster = true; |
| 358 | opts.vecGroupSMInfoList.push_back(sm_info); |
| 359 | |
| 360 | impl_->sms.push_back(move(sm)); |
| 361 | } |
| 362 | |
| 363 | |
| 364 | // 3.0. init data path |
| 365 | auto nodedb_dir_path(impl_->opt.data_dir_path + "/nodedb/"); |
| 366 | if (!comm::utils::CreateDir(nodedb_dir_path)) { |
| 367 | QLErr("nodedb_dir_path %s not exist", nodedb_dir_path.c_str()); |
| 368 | return comm::RetCode::RET_DIR_NOT_EXIST; |
| 369 | } |
nothing calls this directly
no test coverage detected