-
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] Topic policy can not be work well if replay policy message has any exception. #20613
Conversation
} | ||
})); | ||
})); | ||
} catch (Exception e) { |
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.
Throwable
is better
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.
Fixed.
policiesCache.forEach(((topicName, topicPolicies) -> { | ||
if (listeners.get(topicName) != null) { | ||
for (TopicPolicyListener<TopicPolicies> listener : listeners.get(topicName)) { | ||
listener.onUpdate(topicPolicies); |
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.
Can we easily catch the onUpdate
method's exception with the warn log and then normally complete the future?
IMO, Because it is an implementation problem(bug) in the listener logic, we can't let one bad apple spoils the whole bunch. :)
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.
If we complete directly, it may introduce data inconsistency? Complete directly or throws exception depends on the importance of this method. From the source pr(#11136) of this code, I think this method is very important.
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.
If the listener throws an exception, it should be a bug. Do you have any ability to auto-fix it by retry?
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.
We need to fix this bug instead of ignoring it.
})); | ||
} catch (Throwable e) { | ||
log.error("[{}] Failed to replay policy message.", reader.getSystemTopic().getTopicName(), e); | ||
future.completeExceptionally(e); |
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 callback will invoke before cleanCacheAndCloseReader
, which may cause some inconsistent status. :)
- Considering someone who checks the cache and reader status in the future callback.
- Considering
completeExceptionally
throw exception. (logically)
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.
cleanCacheAndCloseReader had delete from here.
} catch (Throwable e) { | ||
log.error("[{}] Failed to replay policy message.", reader.getSystemTopic().getTopicName(), e); | ||
future.completeExceptionally(e); | ||
cleanCacheAndCloseReader(reader.getSystemTopic().getTopicName().getNamespaceObject(), false); |
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.
We should not close the reader here because the caller will close 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.
yes, right. We shouldn't close the reader here
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.
cleanCacheAndCloseReader had delete from here.
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.
We shouldn't close the reader there
cleanCacheAndCloseReader had delete from here. And I will make a new pr to fix some other use case. |
|
I think we need to process like this :
|
why? |
If the listener has an error, the reader cannot be closed here, because the reader is at the namespace level. Nor can other listeners not receive notifications because of a problem with one topic listener. So, only log output can be printed here |
@Technoboy- Makes sense. Thanks for your explanation. I also caught exceptions in the notifyListener() method to prevent a listener callback from failing to terminate the remaining listener callbacks. Please take a look again. |
6237502
to
2871cc9
Compare
Codecov Report
@@ Coverage Diff @@
## master #20613 +/- ##
============================================
+ Coverage 33.58% 36.92% +3.33%
+ Complexity 12127 12118 -9
============================================
Files 1613 1690 +77
Lines 126241 129192 +2951
Branches 13770 14091 +321
============================================
+ Hits 42396 47698 +5302
+ Misses 78331 75232 -3099
- Partials 5514 6262 +748
Flags with carried forward coverage won't be shown. Click here to find out more.
|
…age has any exception. (#20613)
…age has any exception. (#20613)
…age has any exception. (apache#20613) (cherry picked from commit 200fb56) (cherry picked from commit 0a69f66)
Motivation
If listener.onUpdate has any exception, the future can not be complete. We should catch the exception and make the method more safety, otherwise thread would be block.
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: