Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][broker] Fix future of clear delayed message can't complete #20075

Merged
merged 4 commits into from
Apr 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1101,9 +1101,13 @@ public CompletableFuture<Void> clearDelayedMessages() {
if (delayedDeliveryTracker.isEmpty() && topic.getBrokerService()
.getDelayedDeliveryTrackerFactory() instanceof BucketDelayedDeliveryTrackerFactory) {
synchronized (this) {
if (delayedDeliveryTracker.isEmpty()) {
delayedDeliveryTracker = Optional
.of(topic.getBrokerService().getDelayedDeliveryTrackerFactory().newTracker(this));
try {
if (delayedDeliveryTracker.isEmpty()) {
delayedDeliveryTracker = Optional
.of(topic.getBrokerService().getDelayedDeliveryTrackerFactory().newTracker(this));
Copy link
Contributor

Choose a reason for hiding this comment

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

If we never touch the method trackDelayedDelivery(), then the variable delayedDeliveryTracker is always is empty, right?

If yes, why need we initialize it when we should clear delayed messages? Can we just return a completed future?

Copy link
Member Author

@coderzc coderzc Apr 12, 2023

Choose a reason for hiding this comment

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

@poorbarcode Because the dispatcher was closed before unsubscribe was called, this lead to the tracker reference being lost, so we need to reinitialize the tracker to clean up residual persistent data.

Please see: line-1320、line-1356

subscriptions.forEach((s, sub) -> futures.add(sub.disconnect()));
if (closeIfClientsConnected) {
replicators.forEach((cluster, replicator) -> futures.add(replicator.disconnect()));
shadowReplicators.forEach((__, replicator) -> futures.add(replicator.disconnect()));
producers.values().forEach(producer -> futures.add(producer.disconnect()));
}
FutureUtil.waitForAll(futures).thenRunAsync(() -> {
closeClientFuture.complete(null);
}, getOrderedExecutor()).exceptionally(ex -> {
log.error("[{}] Error closing clients", topic, ex);
unfenceTopicToResume();
closeClientFuture.completeExceptionally(ex);
return null;
});
closeClientFuture.thenAccept(__ -> {
CompletableFuture<Void> deleteTopicAuthenticationFuture = new CompletableFuture<>();
brokerService.deleteTopicAuthenticationWithRetry(topic, deleteTopicAuthenticationFuture, 5);
deleteTopicAuthenticationFuture.thenCompose(ignore -> deleteSchema())
.thenCompose(ignore -> {
if (!SystemTopicNames.isTopicPoliciesSystemTopic(topic)
&& brokerService.getPulsar().getConfiguration().isSystemTopicEnabled()) {
return deleteTopicPolicies();
} else {
return CompletableFuture.completedFuture(null);
}
})
.thenCompose(ignore -> transactionBufferCleanupAndClose())
.whenComplete((v, ex) -> {
if (ex != null) {
log.error("[{}] Error deleting topic", topic, ex);
unfenceTopicToResume();
deleteFuture.completeExceptionally(ex);
} else {
List<CompletableFuture<Void>> subsDeleteFutures = new ArrayList<>();
subscriptions.forEach((sub, p) -> subsDeleteFutures.add(unsubscribe(sub)));

Copy link
Contributor

Choose a reason for hiding this comment

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

Because the dispatcher was closed before unsubscribe was called, this lead to the tracker reference being lost, so we need to reinitialize the tracker to clean up residual persistent data.

I see. Another question: the method new tracker will call recover internally, right? If yes, I feel it is an expensive task. Can we only set the Tracker to an unavailable state when closing the dispatcher to avoid recover the second time?

Copy link
Member Author

@coderzc coderzc Apr 13, 2023

Choose a reason for hiding this comment

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

You are right, I think we should use another way to clean up data to avoid unnecessary recover, such as add a clean method in the factory.

}
} catch (Exception e) {
return FutureUtil.failedFuture(e);
}
}
}
Expand Down