| 70 | } |
| 71 | |
| 72 | comm::RetCode SimpleScheduler::AcquireLock(const comm::proto::AcquireLockRequest &req, |
| 73 | comm::proto::AcquireLockResponse &resp) { |
| 74 | QLVerb("AcquireLock topic_id %d lock_id %d lock_key %s", |
| 75 | req.topic_id(), req.lock_id(), req.lock_info().lock_key().c_str()); |
| 76 | |
| 77 | shared_ptr<const config::LockConfig> lock_config; |
| 78 | comm::RetCode ret{config::GlobalConfig::GetThreadInstance()-> |
| 79 | GetLockConfig(req.topic_id(), lock_config)}; |
| 80 | if (comm::RetCode::RET_OK != ret) { |
| 81 | QLErr("GetLockConfig ret %d topic_id %d", as_integer(ret), req.topic_id()); |
| 82 | |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | shared_ptr<const config::proto::Lock> lock; |
| 87 | ret = lock_config->GetLockByLockID(req.lock_id(), lock); |
| 88 | if (comm::RetCode::RET_OK != ret) { |
| 89 | QLErr("GetLockByLockID ret %d lock_id %d", as_integer(ret), req.lock_id()); |
| 90 | |
| 91 | return ret; |
| 92 | } |
| 93 | |
| 94 | assert(lock->addrs_size() >= 2); |
| 95 | comm::proto::Addr master_addr = lock->addrs(1); |
| 96 | |
| 97 | if (req.master_addr().ip() == master_addr.ip() && |
| 98 | req.master_addr().port() == master_addr.port() && |
| 99 | req.master_addr().paxos_port() == master_addr.paxos_port()) { |
| 100 | |
| 101 | return comm::RetCode::RET_OK; |
| 102 | } |
| 103 | resp.mutable_redirect_addr()->CopyFrom(master_addr); |
| 104 | |
| 105 | return comm::RetCode::RET_ERR_NOT_MASTER; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | } // namespace test |
nothing calls this directly
no test coverage detected