| 28 | |
| 29 | |
| 30 | comm::RetCode SimpleScheduler::GetLockInfo(const comm::proto::GetLockInfoRequest &req, |
| 31 | comm::proto::GetLockInfoResponse &resp) { |
| 32 | QLVerb("GetLockInfo topic_id %d lock_id %d lock_key %s", |
| 33 | req.topic_id(), req.lock_id(), req.lock_key().c_str()); |
| 34 | |
| 35 | shared_ptr<const config::LockConfig> lock_config; |
| 36 | comm::RetCode ret{config::GlobalConfig::GetThreadInstance()-> |
| 37 | GetLockConfig(req.topic_id(), lock_config)}; |
| 38 | if (comm::RetCode::RET_OK != ret) { |
| 39 | QLErr("GetLockConfig ret %d topic_id %d", as_integer(ret), req.topic_id()); |
| 40 | |
| 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | shared_ptr<const config::proto::Lock> lock; |
| 45 | ret = lock_config->GetLockByLockID(req.lock_id(), lock); |
| 46 | if (comm::RetCode::RET_OK != ret) { |
| 47 | QLErr("GetLockByLockID ret %d lock_id %d", as_integer(ret), req.lock_id()); |
| 48 | |
| 49 | return ret; |
| 50 | } |
| 51 | |
| 52 | assert(lock->addrs_size() >= 2); |
| 53 | comm::proto::Addr master_addr = lock->addrs(1); |
| 54 | |
| 55 | if (req.master_addr().ip() == master_addr.ip() && |
| 56 | req.master_addr().port() == master_addr.port() && |
| 57 | req.master_addr().paxos_port() == master_addr.paxos_port()) { |
| 58 | |
| 59 | auto &&lock_info(resp.mutable_lock_info()); |
| 60 | lock_info->set_lock_key(req.lock_key()); |
| 61 | lock_info->set_version(1); |
| 62 | lock_info->set_client_id("test_client_1"); |
| 63 | lock_info->set_lease_time_ms(10000000); |
| 64 | |
| 65 | return comm::RetCode::RET_OK; |
| 66 | } |
| 67 | resp.mutable_redirect_addr()->CopyFrom(master_addr); |
| 68 | |
| 69 | return comm::RetCode::RET_ERR_NOT_MASTER; |
| 70 | } |
| 71 | |
| 72 | comm::RetCode SimpleScheduler::AcquireLock(const comm::proto::AcquireLockRequest &req, |
| 73 | comm::proto::AcquireLockResponse &resp) { |
nothing calls this directly
no test coverage detected