Skip to content

[fix][broker]fail to update partition meta of topic due to ConflictException: subscription already exists for topic - #17251

Merged
AnonHxy merged 9 commits into
apache:masterfrom
HQebupt:fixUpdatePartition
Aug 28, 2022
Merged

[fix][broker]fail to update partition meta of topic due to ConflictException: subscription already exists for topic#17251
AnonHxy merged 9 commits into
apache:masterfrom
HQebupt:fixUpdatePartition

Conversation

@HQebupt

@HQebupt HQebupt commented Aug 24, 2022

Copy link
Copy Markdown
Contributor

fixed #10374

Motivation

#10374 wants to handle the existing subscriptions when updating partition with force command parameter. However, it could not update the partition metadata if the Subscription already exists for topic exception comes. Because it miss updating when handling such exception.

private CompletableFuture<Void> updatePartitionedTopic(TopicName topicName, int numPartitions, boolean force) {
CompletableFuture<Void> result = new CompletableFuture<>();
createSubscriptions(topicName, numPartitions).thenCompose(__ -> {
CompletableFuture<Void> future = namespaceResources().getPartitionedTopicResources()
.updatePartitionedTopicAsync(topicName, p -> new PartitionedTopicMetadata(numPartitions));
future.exceptionally(ex -> {
// 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;
});
return null;
});
return future;
}).thenAccept(__ -> result.complete(null)).exceptionally(ex -> {
if (force && ex.getCause() instanceof PulsarAdminException.ConflictException) {
result.complete(null);
return null;
}
result.completeExceptionally(ex);
return null;
});
return result;
}

The line 4364 updatePartitionedTopicAsync could not reach if the line 4362 createSubscriptions occur an exception of PulsarAdminException$ConflictException: Subscription already exists for topic.

Caused by: org.apache.pulsar.client.admin.PulsarAdminException$ConflictException: Subscription already exists for topic
	at org.apache.pulsar.client.admin.internal.BaseResource.getApiException(BaseResource.java:219) ~[classes/:?]
	at org.apache.pulsar.client.admin.internal.BaseResource$1.failed(BaseResource.java:129) ~[classes/:?]
	at org.glassfish.jersey.client.JerseyInvocation$1.failed(JerseyInvocation.java:839) ~[jersey-client-2.31.jar:?]
	at org.glassfish.jersey.client.JerseyInvocation$1.completed(JerseyInvocation.java:820) ~[jersey-client-2.31.jar:?]
	at org.glassfish.jersey.client.ClientRuntime.processResponse(ClientRuntime.java:229) ~[jersey-client-2.31.jar:?]
	at org.glassfish.jersey.client.ClientRuntime.access$200(ClientRuntime.java:62) ~[jersey-client-2.31.jar:?]
	at org.glassfish.jersey.client.ClientRuntime$2.lambda$response$0(ClientRuntime.java:173) ~[jersey-client-2.31.jar:?]
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248) ~[jersey-common-2.31.jar:?]
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244) ~[jersey-common-2.31.jar:?]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:292) ~[jersey-common-2.31.jar:?]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:274) ~[jersey-common-2.31.jar:?]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:244) ~[jersey-common-2.31.jar:?]
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:288) ~[jersey-common-2.31.jar:?]
	at org.glassfish.jersey.client.ClientRuntime$2.response(ClientRuntime.java:173) ~[jersey-client-2.31.jar:?]
	at org.apache.pulsar.client.admin.internal.http.AsyncHttpConnector.lambda$0(AsyncHttpConnector.java:212) ~[classes/:?]

Modifications

update topic partition metadata when handling ConflictException.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

Documentation

Check the box below and label this PR (if you have committer privilege).

Need to update docs?

  • doc-not-needed

@HQebupt HQebupt changed the title fail to update partition meta of topic due to ConflictException: subs [fix][broker]fail to update partition meta of topic due to ConflictException: subscription already exists for topic Aug 24, 2022
@Jason918 Jason918 added the type/bug The PR fixed a bug or issue reported a bug label Aug 24, 2022
@HQebupt
HQebupt requested review from codelipenghui and removed request for Jason918, Technoboy- and mattisonchao August 24, 2022 09:11
@HQebupt
HQebupt force-pushed the fixUpdatePartition branch from a0b7ae8 to 4a8a48e Compare August 24, 2022 09:44
@AnonHxy
AnonHxy requested a review from Jason918 August 25, 2022 07:18
@AnonHxy AnonHxy assigned HQebupt and unassigned HQebupt Aug 25, 2022
@HQebupt

HQebupt commented Aug 26, 2022

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

1 similar comment
@HQebupt

HQebupt commented Aug 26, 2022

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@Jason918 Jason918 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix LGTM.
We can also consider add a "force" parameter in admin.topics().createSubscription() to ignore conflict exception when the subscription already exists.

@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Aug 26, 2022
@AnonHxy

AnonHxy commented Aug 26, 2022

Copy link
Copy Markdown
Contributor

LGTM now, left minor commnet :) @HQebupt

@HQebupt

HQebupt commented Aug 26, 2022

Copy link
Copy Markdown
Contributor Author

This fix LGTM.
We can also consider add a "force" parameter in admin.topics().createSubscription() to ignore conflict exception when the subscription already exists.

I will continue to pay attention to this point.

@HQebupt

HQebupt commented Aug 26, 2022

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@HQebupt

HQebupt commented Aug 27, 2022

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

1 similar comment
@HQebupt

HQebupt commented Aug 27, 2022

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@codelipenghui codelipenghui added this to the 2.12.0 milestone Aug 28, 2022
@AnonHxy
AnonHxy merged commit 3422ab4 into apache:master Aug 28, 2022
Pomelongan pushed a commit to Pomelongan/pulsar that referenced this pull request Aug 28, 2022
…ception: subscription already exists for topic (apache#17251)

### Motivation
apache#10374 wants to handle the existing subscriptions when updating partition with `force` command parameter. However, it could not update the partition metadata if the `Subscription already exists for topic` exception comes. Because it miss updating when handling such exception.
@Jason918

Jason918 commented Sep 4, 2022

Copy link
Copy Markdown
Contributor

Can you help open a new PR to branch-2.10? There are a lot conflict when cherry-pick directly. @HQebupt

@HQebupt

HQebupt commented Sep 5, 2022

Copy link
Copy Markdown
Contributor Author

Can you help open a new PR to branch-2.10? There are a lot conflict when cherry-pick directly. @HQebupt

Sure

@Jason918

Jason918 commented Sep 7, 2022

Copy link
Copy Markdown
Contributor

Move release/2.10.2 to #17488

Technoboy- pushed a commit that referenced this pull request Mar 6, 2023
…ception: subscription already exists for topic (#17251)

### Motivation
#10374 wants to handle the existing subscriptions when updating partition with `force` command parameter. However, it could not update the partition metadata if the `Subscription already exists for topic` exception comes. Because it miss updating when handling such exception.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/branch-2.11 doc-not-needed Your PR changes do not impact docs release/2.11.1 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants