Skip to content

Conversation

@poorbarcode
Copy link
Contributor

@poorbarcode poorbarcode commented Aug 24, 2022

Motivation

When we call cursor.close will trigger cursor info persistent, there are two steps to persistence( ensure as little data loss as possible ):

  • try to persist to Bookie
  • if Bookie doesn't work, try to persist to ZK

Here's how we want it to work:

  1. change state to closing
  2. try to persist to BK
  3. if Bookie doesn't work, try to persist to ZK
  4. change state to closed

(High light)But there's something wrong with this code, here's how it exactly works:

  1. change state to closing
  2. try to persist to BK
  3. (High light) race condition
    3-1. if Bookie doesn't work, try to persist to ZK. (High light) this command asynchronously works on thread bk client worker, and will fail caused of cursor state check(see code below).
    3-2. change state to closed

if (state == State.Closed) {
ledger.getExecutor().execute(safeRun(() -> callback.operationFailed(new MetaStoreException(
new CursorAlreadyClosedException(name + " cursor already closed")))));
return;
}

Modifications

Make change cursor state to closing always be executed after persistence

Documentation

  • doc-required

  • doc-not-needed

  • doc

  • doc-complete

Copy link
Member

@mattisonchao mattisonchao 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

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Aug 24, 2022
@Technoboy- Technoboy- merged commit 46b1239 into apache:master Aug 25, 2022
Technoboy- pushed a commit to Technoboy-/pulsar that referenced this pull request Aug 25, 2022
@Technoboy- Technoboy- modified the milestones: 2.12.0, 2.11.0 Aug 25, 2022
Nicklee007 pushed a commit to Nicklee007/pulsar that referenced this pull request Aug 29, 2022
zymap pushed a commit that referenced this pull request Sep 15, 2022
@zymap zymap added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Sep 15, 2022
@poorbarcode poorbarcode deleted the fix/closeCursorWhenLedgerWrong branch September 17, 2022 02:45
@congbobo184 congbobo184 added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Nov 12, 2022
tisonkun pushed a commit to tisonkun/pulsar that referenced this pull request Jul 12, 2023
Pulsar Consumer would be closed in SplitReader if it reaches the end of split. The registered Consumer would also be closed in PulsarClient if we call PulsarClient.close(). This would cause race condition. We have to use PulsarClient.shutdown() which don't close Consumer instead.

This closes apache#17255
lhotari added a commit to lhotari/pulsar that referenced this pull request Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/broker cherry-picked/branch-2.8 Archived: 2.8 is end of life cherry-picked/branch-2.9 Archived: 2.9 is end of life cherry-picked/branch-2.11 doc-not-needed Your PR changes do not impact docs release/2.8.5 release/2.9.4 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants