| 399 | } |
| 400 | |
| 401 | comm::RetCode Lock::CheckMaster(const int paxos_group_id, comm::proto::Addr &redirect_addr) { |
| 402 | comm::RetCode ret; |
| 403 | |
| 404 | if (impl_->node->IsIMMaster(paxos_group_id)) |
| 405 | return comm::RetCode::RET_OK; |
| 406 | |
| 407 | auto &&node_info = impl_->node->GetMaster(paxos_group_id); |
| 408 | if (node_info.GetIP().empty() || 0 == node_info.GetPort() || "0.0.0.0" == node_info.GetIP()) |
| 409 | return comm::RetCode::RET_ERR_NO_MASTER; |
| 410 | |
| 411 | const auto &topic_id(impl_->topic_id); |
| 412 | |
| 413 | shared_ptr<const config::LockConfig> lock_config; |
| 414 | if (comm::RetCode::RET_OK != (ret = config::GlobalConfig::GetThreadInstance()-> |
| 415 | GetLockConfig(topic_id, lock_config))) { |
| 416 | QLErr("GetLockConfig ret %d topic_id %d", as_integer(ret), topic_id); |
| 417 | |
| 418 | return ret; |
| 419 | } |
| 420 | |
| 421 | shared_ptr<const config::proto::Lock> lock; |
| 422 | if (comm::RetCode::RET_OK != (ret = lock_config->GetLockByAddr(impl_->addr, lock))) { |
| 423 | QLErr("GetLockByAddr ret %d", as_integer(ret)); |
| 424 | |
| 425 | return ret; |
| 426 | } |
| 427 | |
| 428 | for (size_t i{0}; lock->addrs_size() > i; ++i) { |
| 429 | auto &&tmp_addr(lock->addrs(i)); |
| 430 | if (tmp_addr.ip() == node_info.GetIP() && tmp_addr.paxos_port() == node_info.GetPort()) { |
| 431 | redirect_addr = tmp_addr; |
| 432 | |
| 433 | return comm::RetCode::RET_ERR_NOT_MASTER; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | return comm::RetCode::RET_ERR_RANGE_ADDR; |
| 438 | } |
| 439 | |
| 440 | // ret: RET_OK if acquired, others if not acquired |
| 441 | comm::RetCode Lock::PaxosAcquireLock(const comm::proto::AcquireLockRequest &req, |
nothing calls this directly
no test coverage detected