-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix] [ml] fix wrong cursor state if repeat do close #18340
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] [ml] fix wrong cursor state if repeat do close #18340
Conversation
|
this PR should merge into these branches:
|
gaozhangmin
left a comment
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.
LGTM
Codecov Report
@@ Coverage Diff @@
## master #18340 +/- ##
============================================
- Coverage 51.47% 47.00% -4.47%
- Complexity 7410 10360 +2950
============================================
Files 405 692 +287
Lines 44012 67775 +23763
Branches 4517 7263 +2746
============================================
+ Hits 22656 31860 +9204
- Misses 18935 32325 +13390
- Partials 2421 3590 +1169
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Technoboy-
left a comment
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.
It's better to compare all the state.
1c7534a to
1c82674
Compare
already fixed. Thanks |
| * @return false if the {@link #state} already is {@link State#Closing} or {@link State#Closed}. | ||
| */ | ||
| private boolean trySetStateToClosing() { | ||
| if (STATE_UPDATER.compareAndSet(this, State.Uninitialized, State.Closing)){ |
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.
What about using updateAndGet?
This way we can use a switch block
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.
Thanks, this is a really good way to deal with this problem.
already fixed
| final AtomicBoolean notClosing = new AtomicBoolean(false); | ||
| STATE_UPDATER.updateAndGet(this, state -> { | ||
| switch (state){ | ||
| case Closing: | ||
| case Closed: return state; | ||
| default: { | ||
| notClosing.set(true); | ||
| return State.Closing; | ||
| } |
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.
updateAndGet doc says:
The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.
So I guess notClosing.set(true) may cause tricky bugs. How about just
comparing the state that before and after updateAndGet?
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.
Or, we can add notClosing.set(false) in Closing and Closed cases to make this operation idempotent.
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.
Or, we can add notClosing.set(false) in Closing and Closed cases to make this operation idempotent.
Yes, you are right. already fixed
labuladong
left a comment
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.
LGTM
eolivelli
left a comment
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.
LGTM
|
/pulsarbot rerun-failure-checks |
|
Can this PR merge? (^_^) |
Motivation
Do
curosr.closetwice.expect cursor state:
Closedactual cursor state:
ClosingModifications
Fixed the state change logic
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: