equanz commented on a change in pull request #10279:
URL: https://github.com/apache/pulsar/pull/10279#discussion_r710855728
##########
File path:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PartitionedProducerImpl.java
##########
@@ -308,39 +348,44 @@ String getHandlerName() {
future.complete(null);
return future;
} else if (oldPartitionNumber < currentPartitionNumber) {
- List<CompletableFuture<Producer<T>>> futureList = list
- .subList(oldPartitionNumber, currentPartitionNumber)
- .stream()
- .map(partitionName -> {
- int partitionIndex =
TopicName.getPartitionIndex(partitionName);
- ProducerImpl<T> producer =
- new ProducerImpl<>(client,
- partitionName, conf, new
CompletableFuture<>(),
- partitionIndex, schema, interceptors);
- producers.add(producer);
- return producer.producerCreatedFuture();
- }).collect(Collectors.toList());
-
- FutureUtil.waitForAll(futureList)
- .thenAccept(finalFuture -> {
- if (log.isDebugEnabled()) {
- log.debug("[{}] success create producers for
extended partitions. old: {}, new: {}",
- topic, oldPartitionNumber,
currentPartitionNumber);
- }
- topicMetadata = new
TopicMetadataImpl(currentPartitionNumber);
- future.complete(null);
- })
- .exceptionally(ex -> {
- // error happened, remove
- log.warn("[{}] fail create producers for extended
partitions. old: {}, new: {}",
- topic, oldPartitionNumber,
currentPartitionNumber);
- List<ProducerImpl<T>> sublist =
producers.subList(oldPartitionNumber, producers.size());
- sublist.forEach(newProducer ->
newProducer.closeAsync());
- sublist.clear();
- future.completeExceptionally(ex);
- return null;
- });
- return null;
+ if (conf.isLazyStartPartitionedProducers() &&
conf.getAccessMode() == ProducerAccessMode.Shared) {
+ topicMetadata = new
TopicMetadataImpl(currentPartitionNumber);
+ future.complete(null);
+ return future;
+ } else {
+ List<CompletableFuture<Producer<T>>> futureList = list
+ .subList(oldPartitionNumber,
currentPartitionNumber)
+ .stream()
+ .map(partitionName -> {
+ int partitionIndex =
TopicName.getPartitionIndex(partitionName);
+ ProducerImpl<T> producer =
+ new ProducerImpl<>(client,
+ partitionName, conf, new
CompletableFuture<>(),
+ partitionIndex, schema,
interceptors);
+ producers.put(partitionIndex, producer);
Review comment:
I've replaced to use `computeIfAbsent`.
--
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]