You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/04/19 12:16:44 UTC
[GitHub] [pulsar] Technoboy- commented on a diff in pull request #15217: [fix][broker] Fix update topic partitions failed
Technoboy- commented on code in PR #15217:
URL: https://github.com/apache/pulsar/pull/15217#discussion_r852987782
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -4052,7 +4052,26 @@ private CompletableFuture<Void> updatePartitionedTopic(TopicName topicName, int
return future;
}).thenAccept(__ -> result.complete(null)).exceptionally(ex -> {
if (force && ex.getCause() instanceof PulsarAdminException.ConflictException) {
- result.complete(null);
+ CompletableFuture<Void> future = namespaceResources().getPartitionedTopicResources()
+ .updatePartitionedTopicAsync(topicName, p -> new PartitionedTopicMetadata(numPartitions));
+ future.thenAccept(__ -> result.complete(null)).exceptionally(ex2 -> {
+ // If the update operation fails, clean up the partitions that were created
+ getPartitionedTopicMetadataAsync(topicName, false, false).thenAccept(metadata -> {
+ int oldPartition = metadata.partitions;
+ for (int i = oldPartition; i < numPartitions; i++) {
+ topicResources().deletePersistentTopicAsync(topicName.getPartition(i)).exceptionally(ex1 -> {
+ log.warn("[{}] Failed to clean up managedLedger {}", clientAppId(), topicName,
+ ex1.getCause());
+ return null;
+ });
+ }
+ }).exceptionally(e -> {
+ log.warn("[{}] Failed to clean up managedLedger", topicName, e);
+ return null;
+ });
+ result.completeExceptionally(ex2);
+ return null;
+ });
Review Comment:
The `updatePartitionedTopicAsync` has handled the exception, so it can't delegate the exception here.
BTW, could you help refactor this method ?
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org