-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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] Remove failed future when topic load error #20561
base: master
Are you sure you want to change the base?
Conversation
@@ -1091,6 +1091,9 @@ public CompletableFuture<Optional<Topic>> getTopic(final TopicName topicName, bo | |||
} | |||
}); | |||
} | |||
final CompletableFuture<Optional<Topic>> topicFutureToRemove = topicFuture; | |||
topicFuture.whenComplete((ignore, ex) -> topics.remove(topicName.toString(), topicFutureToRemove)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please note that you are appending a new whenComplete listener every time this method is called and the object is already in the map.
we have to call "whenComplete" only if the body of the lambda expression in computeIfAbsent is executed.
I know that it sounds ugly, but we must to it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry. I lost a check: if (ex != null)
. It only is removed if the future was failed, and we call remove(k, v)
, and this method will not do incorrect deletions. Could you take a look again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that we call whenComplete every time we invoke this method and only the first time we create the object and add it to the Map.
So everytime we enqueue the execution. If this method is called in an hotpath you will see many allocations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Thanks, already fixed
this is already covered in #20540 which was created before this PR. It uses a different approach in the |
The pr had no activity for 30 days, mark with Stale label. |
fixes: #14941
Motivation
Issue-1(this PR fixes)
When a topic load fails due to
timeout ex
, Broker will not clean up the exception future, causing other APIs to fail when they touch this future. You can reproduce it bytestUnloadNamespaceAfterLoadTopicFailed
Issue-2
If the program is executed as the flow below, there will still be one orphan topic that is not closed.
create topic
timeout check
I will try to reproduce this scenario later(not in this PR)
Contexts
Modifications
Remove failed future when topic load error.
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: x