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

Method Sync

phxqueue/consumer/hblock.cpp:552–626  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

550
551
552comm::RetCode HeartBeatLock::Sync() {
553 QLInfo("Sync begin");
554
555 comm::RetCode ret;
556
557 const int topic_id = impl_->consumer->GetTopicID();
558
559 UpdateProcUsed();
560
561 comm::ConsumerHeartBeatLockBP::GetThreadInstance()->OnSync(topic_id);
562 comm::ConsumerHeartBeatLockBP::GetThreadInstance()->OnProcUsed(topic_id, impl_->nproc, impl_->proc_used);
563 if (impl_->proc_used >= impl_->nproc) {
564 comm::ConsumerHeartBeatLockBP::GetThreadInstance()->OnProcUsedExceed(topic_id, impl_->nproc, impl_->proc_used);
565 QLErr("ERR: impl_->proc_used(%d) >= nproc(%d)", impl_->proc_used, impl_->nproc);
566 }
567
568 QLInfo("nproc %d proc_used %d", impl_->nproc, impl_->proc_used);
569
570 SubID2AddrScales sub_id2addr_scales;
571 if (comm::RetCode::RET_OK != (ret = GetAddrScale(sub_id2addr_scales))) {
572 QLErr("ERR: GetAddrScale ret %d", comm::as_integer(ret));
573 return ret;
574 }
575
576 std::set<int> valid_sub_ids;
577 for (auto &&kv : sub_id2addr_scales) {
578 valid_sub_ids.insert(kv.first);
579 }
580 ClearInvalidSubIDs(valid_sub_ids);
581
582 uint64_t conf_last_mod_time = config::GlobalConfig::GetThreadInstance()->GetLastModTime(topic_id);
583
584 map<int, vector<Queue_t> > sub_id2pending_queues;
585 for (auto &&it : sub_id2addr_scales) {
586 auto &&sub_id = it.first;
587 auto &&addr_scale = it.second;
588
589 QLVerb("sub_id %d addr_scale.size %zu", sub_id, addr_scale.size());
590
591 uint64_t scale_hash = CalHash(addr_scale);
592
593 comm::ConsumerHeartBeatLockBP::GetThreadInstance()->OnScaleHash(topic_id, sub_id, scale_hash);
594
595 if (LOCK_BUF_MAGIC == impl_->buf->magic &&
596 conf_last_mod_time == impl_->conf_last_mod_time &&
597 scale_hash == impl_->scale_hashs[sub_id]) {
598 QLInfo("no need to adjust scale. sub_id %d scale_hash %" PRIu64, sub_id, scale_hash);
599 continue;
600 }
601
602 comm::ConsumerHeartBeatLockBP::GetThreadInstance()->OnAdjustScale(topic_id, sub_id);
603
604 std::vector<Queue_t> all_queues;
605 if (comm::RetCode::RET_OK != (ret = GetAllQueues(sub_id, all_queues))) {
606 QLErr("ERR: GetAllQueues ret %d", comm::as_integer(ret));
607 return ret;
608 }
609

Callers

nothing calls this directly

Calls 10

as_integerFunction · 0.85
CalHashFunction · 0.85
OnSyncMethod · 0.80
OnProcUsedMethod · 0.80
OnProcUsedExceedMethod · 0.80
OnScaleHashMethod · 0.80
OnAdjustScaleMethod · 0.80
OnSyncSuccMethod · 0.80
GetTopicIDMethod · 0.45
GetLastModTimeMethod · 0.45

Tested by

no test coverage detected