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

Method PaxosAdd

phxqueue/store/store.cpp:483–535  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

481}
482
483comm::RetCode Store::PaxosAdd(const comm::proto::AddRequest &req, comm::proto::AddResponse &resp) {
484 comm::StoreBP::GetThreadInstance()->OnPaxosAdd(req);
485
486 int paxos_group_id{req.queue_id() % impl_->opt.ngroup};
487
488 proto::StorePaxosArgs args;
489 args.set_timestamp(time(nullptr));
490 args.mutable_add_req()->CopyFrom(req);
491
492 string buf;
493 args.SerializeToString(&buf);
494
495 StoreContext sc;
496 sc.result = comm::RetCode::RET_OK;
497
498 comm::StoreBP::GetThreadInstance()->OnBatchPropose(req);
499
500 uint64_t instance_id;
501 uint32_t batch_idx;
502 phxpaxos::SMCtx ctx(StoreSM::ID, &sc);
503
504 uint64_t t1{comm::utils::Time::GetSteadyClockMS()};
505 int paxos_ret{impl_->node->BatchPropose(paxos_group_id, buf, instance_id, batch_idx, &ctx)};
506 uint64_t t2{comm::utils::Time::GetSteadyClockMS()};
507 uint64_t used_time_ms{t2 - t1};
508
509 if (phxpaxos::PaxosTryCommitRet_OK != paxos_ret) {
510 comm::StoreBP::GetThreadInstance()->OnBatchProposeErr(req, used_time_ms);
511 QLErr("BatchPropose paxos_ret %d paxos_group_id %d buf_length %zu",
512 paxos_ret, paxos_group_id, buf.length());
513 switch (paxos_ret) {
514 case phxpaxos::PaxosTryCommitRet_Timeout:
515 comm::StoreBP::GetThreadInstance()->OnBatchProposeErrTimeout(req);
516 return comm::RetCode::RET_ERR_PROPOSE_TIMEOUT;
517 case phxpaxos::PaxosTryCommitRet_TooManyThreadWaiting_Reject:
518 comm::StoreBP::GetThreadInstance()->OnBatchProposeErrTooManyThreadWaitingReject(req);
519 return comm::RetCode::RET_ERR_PROPOSE_FAST_REJECT;
520 case phxpaxos::PaxosTryCommitRet_Value_Size_TooLarge:
521 comm::StoreBP::GetThreadInstance()->OnBatchProposeErrValueSizeTooLarge(req);
522 return comm::RetCode::RET_ERR_SIZE_TOO_LARGE;
523 default:
524 comm::StoreBP::GetThreadInstance()->OnBatchProposeErrOther(req);
525 return comm::RetCode::RET_ERR_PROPOSE;
526 };
527 }
528 comm::StoreBP::GetThreadInstance()->
529 OnBatchProposeSucc(req, instance_id, batch_idx, used_time_ms);
530
531
532 resp.set_cursor_id(instance_id);
533
534 return sc.result;
535}
536
537comm::RetCode Store::Get(const comm::proto::GetRequest &req, comm::proto::GetResponse &resp) {
538 QLVerb("Get");

Callers

nothing calls this directly

Tested by

no test coverage detected