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

Method MakeAddRequests

phxqueue/producer/producer.cpp:182–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

180
181
182comm::RetCode Producer::MakeAddRequests(const int topic_id,
183 const std::vector<std::shared_ptr<comm::proto::QItem> > &items,
184 vector<unique_ptr<comm::proto::AddRequest> > &reqs,
185 ItemUpdateFunc item_update_func) {
186
187 reqs.clear();
188
189 comm::ProducerBP::GetThreadInstance()->OnMakeAddRequests(topic_id, items);
190
191 comm::RetCode ret;
192
193 shared_ptr<const config::TopicConfig> topic_config;
194 if (comm::RetCode::RET_OK != (ret = config::GlobalConfig::GetThreadInstance()->GetTopicConfigByTopicID(topic_id, topic_config))) {
195 comm::ProducerBP::GetThreadInstance()->OnValidTopicID(topic_id);
196 NLErr("GetTopicConfigByTopicID ret %d", as_integer(ret));
197 return ret;
198 }
199
200 size_t byte_size_limit = topic_config->GetProto().topic().items_byte_size_limit();
201 int batch_limit = topic_config->GetProto().topic().batch_limit();
202
203
204 map<int, vector<unique_ptr<comm::proto::QItem> > > queue_info_id2new_items;
205 for (auto &&item : items) {
206 if (nullptr == item) continue;
207
208 auto new_item = unique_ptr<comm::proto::QItem>(new comm::proto::QItem());
209 new_item->CopyFrom(*item);
210 if (item_update_func) item_update_func(*new_item);
211
212 int queue_info_id = 0;
213 if (comm::RetCode::RET_OK != (ret = topic_config->GetQueueInfoIDByCount(new_item->pub_id(), new_item->count(), queue_info_id))) {
214 if (comm::RetCode::RET_ERR_RANGE_CNT == ret) {
215 comm::ProducerBP::GetThreadInstance()->OnCountLimit(topic_id, new_item->pub_id(), *item);
216 NLInfo("skip. GetQueueInfoIDByCount ret %d count %d "
217 "handle_id %d ori_pub_id %d pub_id %d sub_ids %" PRIu64 " hash %" PRIu64 " uin %" PRIu64,
218 as_integer(ret), new_item->count(),
219 new_item->meta().handle_id(), new_item->meta().pub_id(), new_item->pub_id(), (uint64_t)new_item->sub_ids(),
220 (uint64_t)new_item->meta().hash(), (uint64_t)new_item->meta().uin());
221 } else {
222 NLErr("GetQueueInfoIDByCount ret %d count %d "
223 "handle_id %d ori_pub_id %d pub_id %d sub_ids %" PRIu64 " hash %" PRIu64 " uin %" PRIu64,
224 as_integer(ret), new_item->count(),
225 new_item->meta().handle_id(), new_item->meta().pub_id(), new_item->pub_id(), (uint64_t)new_item->sub_ids(),
226 (uint64_t)new_item->meta().hash(), (uint64_t)new_item->meta().uin());
227 }
228 continue;
229 }
230
231 queue_info_id2new_items[queue_info_id].push_back(move(new_item));
232 }
233
234
235 for (auto &&kv : queue_info_id2new_items) {
236 auto &&new_items = kv.second;
237
238 unique_ptr<comm::proto::AddRequest> req = nullptr;
239 int batch = 0;

Callers

nothing calls this directly

Calls 8

as_integerFunction · 0.85
OnMakeAddRequestsMethod · 0.80
OnValidTopicIDMethod · 0.80
GetQueueInfoIDByCountMethod · 0.80
OnCountLimitMethod · 0.80
OnItemSizeTooLargeMethod · 0.80
OnMakeAddRequestsSuccMethod · 0.80

Tested by

no test coverage detected