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

Method GetQueueByAddrScale

phxqueue/consumer/consumer.cpp:782–838  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

780
781
782comm::RetCode
783Consumer::GetQueueByAddrScale(const vector<consumer::Queue_t> &queues,
784 const consumer::AddrScales &addr_scales,
785 set<size_t> &queue_idxs) {
786 queue_idxs.clear();
787
788 map<uint32_t, uint64_t> hash2encoded_addr;
789
790 comm::proto::Addr local_addr;
791 local_addr.set_ip(impl_->opt.ip);
792 local_addr.set_port(impl_->opt.port);
793
794 uint64_t local_encoded_addr = comm::utils::EncodeAddr(local_addr);
795
796 for (int i{0}; i < addr_scales.size(); ++i) {
797 auto &addr = addr_scales[i].addr();
798 auto scale = addr_scales[i].scale();
799
800 uint64_t encoded_addr = comm::utils::EncodeAddr(addr);
801 for (int j{0}; j < scale; ++j) {
802 size_t h = 0;
803 h = comm::utils::MurmurHash64(&encoded_addr, sizeof(uint64_t), h);
804 h = comm::utils::MurmurHash64(&j, sizeof(int), h);
805
806
807 hash2encoded_addr.emplace(h, encoded_addr);
808 //QLInfo("insert h %u encoded_addr %" PRIu64 " j %d", h, encoded_addr, j);
809 }
810 }
811
812 if (hash2encoded_addr.empty()) {
813 QLWarn("hash2encoded_addr empty");
814 return comm::RetCode::RET_OK;
815 }
816
817 for (int i{0}; i < queues.size(); ++i) {
818 auto &&queue = queues[i];
819 size_t h = 0;
820 h = comm::utils::MurmurHash64(&queue.sub_id, sizeof(uint32_t), h);
821 h = comm::utils::MurmurHash64(&queue.store_id, sizeof(uint32_t), h);
822 h = comm::utils::MurmurHash64(&queue.queue_id, sizeof(uint32_t), h);
823
824
825 auto &&it = hash2encoded_addr.lower_bound(h);
826 if (hash2encoded_addr.end() == it) it = hash2encoded_addr.begin();
827
828 //QLInfo("find h %u %" PRIu64, h, it->second);
829
830 if (it->second == local_encoded_addr) {
831 queue_idxs.insert(i);
832 }
833 }
834 QLInfo("queues.size %zu addrscales.size %zu queue_idxs.size %zu local_encoded_addr %" PRIu64, queues.size(),
835 addr_scales.size(), queue_idxs.size(), local_encoded_addr);
836
837 return phxqueue::comm::RetCode::RET_OK;
838}
839

Callers 1

GetPendingQueuesMethod · 0.45

Calls 2

EncodeAddrFunction · 0.85
MurmurHash64Function · 0.85

Tested by

no test coverage detected