| 299 | |
| 300 | |
| 301 | comm::RetCode Producer::SelectAndAdd(comm::proto::AddRequest &req, comm::proto::AddResponse &resp, StoreSelector *ss, QueueSelector *qs) { |
| 302 | QLVerb("SelectAndAdd"); |
| 303 | |
| 304 | comm::ProducerBP::GetThreadInstance()->OnSelectAndAdd(req); |
| 305 | |
| 306 | if (0 == req.items_size()) return comm::RetCode::RET_OK; |
| 307 | |
| 308 | auto pub_id = req.items(0).pub_id(); |
| 309 | auto uin = req.items(0).meta().uin(); |
| 310 | auto count = req.items(0).count(); |
| 311 | |
| 312 | comm::RetCode ret; |
| 313 | |
| 314 | shared_ptr<const config::TopicConfig> topic_config; |
| 315 | if (comm::RetCode::RET_OK != (ret = config::GlobalConfig::GetThreadInstance()->GetTopicConfigByTopicID(req.topic_id(), topic_config))) { |
| 316 | comm::ProducerBP::GetThreadInstance()->OnTopicIDInvalid(req); |
| 317 | QLErr("GetTopicConfigByTopicID ret %d topic_id %d", as_integer(ret), req.topic_id(), uin); |
| 318 | return ret; |
| 319 | } |
| 320 | |
| 321 | std::unique_ptr<QueueSelector> default_qs; |
| 322 | if (!qs) { |
| 323 | default_qs = NewQueueSelector(req.topic_id(), pub_id, uin, count, topic_config->GetProto().topic().producer_retry_switch_queue()); |
| 324 | qs = default_qs.get(); |
| 325 | comm::ProducerBP::GetThreadInstance()->OnUseDefaultQueueSelector(req); |
| 326 | } else { |
| 327 | comm::ProducerBP::GetThreadInstance()->OnUseCustomQueueSelector(req); |
| 328 | } |
| 329 | |
| 330 | std::unique_ptr<StoreSelector> default_ss; |
| 331 | if (!ss) { |
| 332 | default_ss = NewStoreSelector(req.topic_id(), pub_id, uin, topic_config->GetProto().topic().producer_retry_switch_store()); |
| 333 | ss = default_ss.get(); |
| 334 | comm::ProducerBP::GetThreadInstance()->OnUseDefaultStoreSelector(req); |
| 335 | } else { |
| 336 | comm::ProducerBP::GetThreadInstance()->OnUseCustomStoreSelector(req); |
| 337 | } |
| 338 | |
| 339 | int nretry_raw_add{topic_config->GetProto().topic().producer_nretry_raw_add()}; |
| 340 | do { |
| 341 | int queue_id; |
| 342 | if (comm::RetCode::RET_OK != (ret = qs->GetQueueID(queue_id))) { |
| 343 | comm::ProducerBP::GetThreadInstance()->OnGetQueueIDFail(req); |
| 344 | QLErr("GetQueue ret %d", as_integer(ret)); |
| 345 | return ret; |
| 346 | } |
| 347 | req.set_queue_id(queue_id); |
| 348 | |
| 349 | int store_id; |
| 350 | if (comm::RetCode::RET_OK != (ret = ss->GetStoreID(store_id))) { |
| 351 | comm::ProducerBP::GetThreadInstance()->OnGetStoreIDFail(req); |
| 352 | QLErr("GetStore ret %d", as_integer(ret)); |
| 353 | return ret; |
| 354 | } |
| 355 | req.set_store_id(store_id); |
| 356 | |
| 357 | if (nullptr != impl_->batch_helper) { |
| 358 | if (comm::RetCode::RET_OK != (ret = impl_->batch_helper->BatchRawAdd(req))) { |
no test coverage detected