BewareMyPower commented on code in PR #203:
URL: https://github.com/apache/pulsar-client-cpp/pull/203#discussion_r1122025097
##########
lib/PartitionedProducerImpl.cc:
##########
@@ -439,26 +439,40 @@ void PartitionedProducerImpl::handleGetPartitions(Result
result,
LOG_INFO("new partition count: " << newNumPartitions);
topicMetadata_.reset(new TopicMetadataImpl(newNumPartitions));
+ std::vector<ProducerImplPtr> producers;
+ auto lazy = conf_.getLazyStartPartitionedProducers() &&
+ conf_.getAccessMode() == ProducerConfiguration::Shared;
for (unsigned int i = currentNumPartitions; i < newNumPartitions;
i++) {
- auto lazy = conf_.getLazyStartPartitionedProducers() &&
- conf_.getAccessMode() ==
ProducerConfiguration::Shared;
- auto producer = newInternalProducer(i, lazy);
-
+ ProducerImplPtr producer;
+ try {
+ producer = newInternalProducer(i, lazy);
+ } catch (const std::runtime_error& e) {
+ LOG_ERROR("Failed to create producer for partition " << i
<< ": " << e.what());
+ producers.clear();
+ break;
+ }
+ producers.emplace_back(producer);
+ }
+ if (producers.empty()) {
+ runPartitionUpdateTask();
+ return;
+ }
+ for (unsigned int i = 0; i < producers.size(); i++) {
+ auto&& producer = producers[i];
+ producers_.emplace_back(producer);
if (!lazy) {
producer->start();
}
- producers_.push_back(producer);
}
producersLock.unlock();
// `runPartitionUpdateTask()` will be called in
`handleSinglePartitionProducerCreated()`
interceptors_->onPartitionsChange(getTopic(), newNumPartitions);
- return;
+ runPartitionUpdateTask();
Review Comment:
Yes, it's right, I forgot it. Addressed by moving the comment before the
`return`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]