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

Method GetLockInfo

phxqueue/lock/lock.cpp:253–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251}
252
253comm::RetCode Lock::GetLockInfo(const comm::proto::GetLockInfoRequest &req,
254 comm::proto::GetLockInfoResponse &resp) {
255 comm::LockBP::GetThreadInstance()->OnGetLockInfo(req);
256
257 if (0 >= req.lock_key().size()) {
258 comm::LockBP::GetThreadInstance()->OnGetLockInfoRequestInvalid(req);
259 QLErr("lock \"%s\" invalid", req.lock_key().c_str());
260
261 return comm::RetCode::RET_ERR_KEY;
262 }
263
264 uint32_t paxos_group_id{HashUi32(req.lock_key()) % impl_->opt.nr_group};
265
266 comm::RetCode ret{CheckMaster(paxos_group_id, *resp.mutable_redirect_addr())};
267 if (comm::RetCode::RET_OK != ret) {
268 QLErr("paxos_group %d lock \"%s\" CheckMaster err %d",
269 paxos_group_id, req.lock_key().c_str(), ret);
270 // TODO:
271 //OssAttrInc(impl_->opt.oss_attr_id, 23u, 1u);
272
273 return ret;
274 }
275 comm::LockBP::GetThreadInstance()->OnGetLockInfoCheckMasterPass(req);
276 QLVerb("paxos_group %d lock \"%s\" node %" PRIu64 " master 1",
277 paxos_group_id, req.lock_key().c_str(), impl_->node->GetMyNodeID());
278
279 proto::LocalLockInfo local_lock_info;
280
281 // begin mutex
282 {
283
284 // prevent paxos from writing
285 comm::utils::MutexGuard guard(impl_->lock_mgr->map(paxos_group_id).mutex());
286 ret = impl_->lock_mgr->map(paxos_group_id).Get(req.lock_key(), local_lock_info);
287
288 }
289 // end mutex
290
291 if (comm::RetCode::RET_ERR_KEY_NOT_EXIST == ret) {
292 QLVerb("paxos_group %d lock \"%s\" Get not exist", paxos_group_id, req.lock_key().c_str());
293 // TODO:
294 //OssAttrInc(impl_->opt.oss_attr_id, 25u, 1u);
295
296 return ret;
297 } else if (comm::RetCode::RET_OK != ret) {
298 QLErr("paxos_group %d lock \"%s\" Get err %d", paxos_group_id, req.lock_key().c_str(), ret);
299 // TODO:
300 //OssAttrInc(impl_->opt.oss_attr_id, 24u, 1u);
301
302 return ret;
303 }
304
305 LocalLockInfo2LockInfo(local_lock_info, *resp.mutable_lock_info());
306 QLInfo("paxos_group %d lock \"%s\" Get ok map.ver %llu map.client_id \"%s\"", paxos_group_id,
307 req.lock_key().c_str(), resp.lock_info().version(), resp.lock_info().client_id().c_str());
308
309 return ret;
310}

Callers

nothing calls this directly

Calls 7

HashUi32Function · 0.85
LocalLockInfo2LockInfoFunction · 0.85
mutexMethod · 0.80
OnGetLockInfoMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected