Skip to content

Conversation

@poorbarcode
Copy link
Contributor

Motivation

Do curosr.close twice.

expect cursor state: Closed

actual cursor state: Closing

Modifications

Fixed the state change logic

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@poorbarcode
Copy link
Contributor Author

poorbarcode commented Nov 4, 2022

this PR should merge into these branches:

  • 2.9
  • 2.10
  • 2.11
  • master

Copy link
Contributor

@gaozhangmin gaozhangmin left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Nov 4, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 4, 2022

Codecov Report

Merging #18340 (bbceaa3) into master (a2c1534) will decrease coverage by 4.46%.
The diff coverage is 63.63%.

Impacted file tree graph

@@             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     
Flag Coverage Δ
unittests 47.00% <63.63%> (-4.47%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...che/bookkeeper/mledger/impl/ManagedCursorImpl.java 36.97% <63.63%> (ø)
...rvice/schema/KeyValueSchemaCompatibilityCheck.java 21.62% <0.00%> (-45.95%) ⬇️
.../apache/pulsar/broker/admin/impl/PackagesBase.java 54.12% <0.00%> (-13.77%) ⬇️
...oker/service/schema/SchemaRegistryServiceImpl.java 57.35% <0.00%> (-6.31%) ⬇️
...pulsar/broker/service/PulsarCommandSenderImpl.java 67.53% <0.00%> (-5.76%) ⬇️
...ava/org/apache/pulsar/broker/service/Consumer.java 69.50% <0.00%> (-2.31%) ⬇️
...pache/pulsar/broker/admin/v2/PersistentTopics.java 71.68% <0.00%> (-2.29%) ⬇️
.../org/apache/pulsar/broker/admin/v2/Namespaces.java 57.36% <0.00%> (-2.14%) ⬇️
...ervice/AbstractDispatcherSingleActiveConsumer.java 69.15% <0.00%> (-1.87%) ⬇️
...rg/apache/pulsar/broker/web/PulsarWebResource.java 56.43% <0.00%> (-1.87%) ⬇️
... and 315 more

@Technoboy- Technoboy- added this to the 2.12.0 milestone Nov 4, 2022
@Technoboy- Technoboy- added type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages area/ML labels Nov 4, 2022
Copy link
Contributor

@Technoboy- Technoboy- left a 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.

@poorbarcode poorbarcode force-pushed the fix/wrong_cursor_state_if_repeate_close branch from 1c7534a to 1c82674 Compare November 5, 2022 15:19
@poorbarcode
Copy link
Contributor Author

@Technoboy-

It's better to compare all the state.

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)){
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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

@poorbarcode poorbarcode requested review from eolivelli and removed request for Technoboy- November 7, 2022 02:12
Comment on lines 2715 to 2723
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;
}
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@labuladong labuladong left a comment

Choose a reason for hiding this comment

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

LGTM

@Technoboy- Technoboy- changed the title [fix][ml]fix wrong cursor state if repeat do close [fix][ml]Fix wrong cursor state if repeat do close Nov 8, 2022
@Technoboy- Technoboy- closed this Nov 8, 2022
@Technoboy- Technoboy- reopened this Nov 8, 2022
@Technoboy- Technoboy- closed this Nov 8, 2022
@Technoboy- Technoboy- reopened this Nov 8, 2022
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

@poorbarcode
Copy link
Contributor Author

/pulsarbot rerun-failure-checks

@poorbarcode poorbarcode changed the title [fix][ml]Fix wrong cursor state if repeat do close [fix] [ml] fix wrong cursor state if repeat do close Nov 10, 2022
@poorbarcode
Copy link
Contributor Author

Can this PR merge? (^_^)

@codelipenghui codelipenghui merged commit cd84b93 into apache:master Nov 11, 2022
@poorbarcode poorbarcode deleted the fix/wrong_cursor_state_if_repeate_close branch November 18, 2022 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ML doc-not-needed Your PR changes do not impact docs ready-to-test type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants