GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][txn] Fix getting last message ID when there are ongoing transactions by liangyepianzhou · Pull Request #21466 · apache/pulsar

Conversation

@liangyepianzhou

@liangyepianzhou liangyepianzhou commented Oct 30, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Motivation

  1. Consumer/Reader API getLastMessageIds should return the max read position instead of lastConfirmedEntry.

    pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java

    Lines 2117 to 2122 in 2322004

    if (consumerFuture != null && consumerFuture.isDone() && !consumerFuture.isCompletedExceptionally()) {
    Consumer consumer = consumerFuture.getNow(null);
    long requestId = getLastMessageId.getRequestId();
    Topic topic = consumer.getSubscription().getTopic();
    Position lastPosition = topic.getLastPosition();
  2. When the transaction buffer is recovering, the MaxReadPosition of the topic is unknown. Wait it recovers completely is needed.
  3. The MaxReadPosition should be the previous position of the first ongoing transaction position instead of EntryID -1. Because compacted decide whether the topic's managedLedger is null by EntryID == -1

    pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java

    Lines 2161 to 2176 in 2322004

    compactionHorizonFuture.whenComplete((compactionHorizon, ex) -> {
    if (ex != null) {
    log.error("Failed to get compactionHorizon.", ex);
    writeAndFlush(Commands.newError(requestId, ServerError.MetadataError, ex.getMessage()));
    return;
    }
    if (lastPosition.getEntryId() == -1 || (compactionHorizon != null
    && lastPosition.compareTo((PositionImpl) compactionHorizon) <= 0)) {
    handleLastMessageIdFromCompactionService(persistentTopic, requestId, partitionIndex,
    markDeletePosition);
    return;
    }
    // For a valid position, we read the entry out and parse the batch size from its metadata.
    CompletableFuture<Entry> entryFuture = new CompletableFuture<>();

Modifications

  1. Return max read position when calling getLastMessageIds.
  2. Call checkIfTBRecoverCompletely before getting the max read position.
  3. If transaction buffer recovery fails, return Unknown error to the client.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

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

Matching PR in forked repository

PR in forked repository:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@liangyepianzhou
liangyepianzhou requested review from codelipenghui, coderzc and poorbarcode October 30, 2023 03:00
@github-actions github-actions Bot added doc-label-missing doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Oct 30, 2023
@liangyepianzhou
liangyepianzhou force-pushed the getmaxposition branch from 1c19f30 to 92fdf29 Compare November 1, 2023 10:34
@liangyepianzhou liangyepianzhou mentioned this pull request Nov 2, 2023
[improve][txn] Take first snapshot before persisting the first transactional message #21406
Merged
1 of 15 tasks
@apache apache deleted a comment from github-actions Bot Nov 3, 2023
codelipenghui
codelipenghui requested changes Nov 3, 2023
View reviewed changes
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

codelipenghui
codelipenghui requested changes Nov 3, 2023
View reviewed changes
Comment thread ...er/src/test/java/org/apache/pulsar/broker/transaction/buffer/TopicTransactionBufferTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@codelipenghui

codelipenghui commented Nov 3, 2023

Copy link
Copy Markdown
Contributor

@coderzc

Could you please help review

The MaxReadPosition should be the previous position of the first ongoing transaction position instead of EntryID -1.
Compacted decide whether the topic's managedLedger is null by EntryID == -1

I'm not sure what does it actually means.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@liangyepianzhou liangyepianzhou changed the title [fix][txn] Wait TransactionBuffer recover completely when get last message ID [fix][txn] Fix getting last message ID when there are ongoing transactions Nov 6, 2023
@coderzc

coderzc commented Nov 7, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@coderzc

Could you please help review

The MaxReadPosition should be the previous position of the first ongoing transaction position instead of EntryID -1.
Compacted decide whether the topic's managedLedger is null by EntryID == -1

I'm not sure what does it actually means.

@coderzc

Could you please help review

The MaxReadPosition should be the previous position of the first ongoing transaction position instead of EntryID -1.
Compacted decide whether the topic's managedLedger is null by EntryID == -1

I'm not sure what does it actually means.

I think this change is correct since the first entryID of ongoing maybe 0, so its previous entry can't be directly by entryID-1.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderzc

coderzc commented Nov 7, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@liangyepianzhou I think this PR also fixes #21456.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@liangyepianzhou liangyepianzhou self-assigned this Nov 9, 2023
@liangyepianzhou liangyepianzhou added type/bug The PR fixed a bug or issue reported a bug release/2.9.5 release/2.10.6 release/3.1.2 release/3.0.3 release/2.11.4 labels Nov 9, 2023
coderzc
coderzc approved these changes Nov 9, 2023
View reviewed changes
@liangyepianzhou
fix: API getLastMessageIds should return max read position.
02a0633
Modification:
1. Wait transaction buffer ready
2. Use `getPreviousPosition` replace `EntryID - 1`
@liangyepianzhou
liangyepianzhou force-pushed the getmaxposition branch 2 times, most recently from 7a4d0c8 to 1606f20 Compare November 16, 2023 07:54
@AnonHxy AnonHxy added release/3.1.3 and removed release/3.1.2 labels Nov 28, 2023
coderzc
coderzc reviewed Dec 1, 2023
View reviewed changes
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

coderzc
coderzc approved these changes Dec 4, 2023
View reviewed changes
liangyepianzhou added 3 commits December 8, 2023 20:29
@liangyepianzhou
Revert "notes: component -> components"
1138858
This reverts commit 87823cb.
@liangyepianzhou
Revert "err: Add new exception"
c0661e4
This reverts commit 5d5b51f.
@liangyepianzhou
improve: change TransactionComponentLoadFailedException to `BrokerP…
64412a0
…ersistenceException`.
@liangyepianzhou
liangyepianzhou force-pushed the getmaxposition branch from 129fecf to 64412a0 Compare December 8, 2023 12:30
@liangyepianzhou
exception: replace 'BrokerPersistentException' with 'UnKnownException'
501feb5
BewareMyPower
BewareMyPower approved these changes Dec 11, 2023
View reviewed changes
codelipenghui
codelipenghui approved these changes Dec 11, 2023
View reviewed changes
@codelipenghui

codelipenghui commented Dec 11, 2023

Copy link
Copy Markdown
Contributor

/pulsarbot run-failure-checks

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gaoran10
gaoran10 approved these changes Dec 11, 2023
View reviewed changes
@coderzc

coderzc commented Dec 12, 2023

Copy link
Copy Markdown
Member

/pulsarbot run-failure-checks

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@liangyepianzhou
improve: return topic.getLastPosition() when call `getMaxReadPositi…
f229294
…on` to TransactionBufferDisable
@codecov-commenter

codecov-commenter commented Dec 12, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 75.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 73.37%. Comparing base (517961e) to head (f229294).
Report is 1401 commits behind head on master.

Files with missing lines Patch % Lines
...va/org/apache/pulsar/broker/service/ServerCnx.java 73.33% 1 Missing and 3 partials ⚠️
...sar/broker/service/persistent/PersistentTopic.java 50.00% 1 Missing ⚠️
...ransaction/buffer/impl/InMemTransactionBuffer.java 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #21466       +/-   ##
=============================================
+ Coverage     31.82%   73.37%   +41.55%     
- Complexity    11870    32661    +20791     
=============================================
  Files          1511     1893      +382     
  Lines        116133   140721    +24588     
  Branches      12585    15502     +2917     
=============================================
+ Hits          36963   103260    +66297     
+ Misses        74228    29344    -44884     
- Partials       4942     8117     +3175     
Flag Coverage Δ
inttests 24.11% <66.66%> (?)
systests 24.72% <62.50%> (?)
unittests 72.68% <75.00%> (+40.86%) ⬆️

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

Files with missing lines Coverage Δ
...ransaction/buffer/impl/TopicTransactionBuffer.java 87.74% <100.00%> (+67.23%) ⬆️
...nsaction/buffer/impl/TransactionBufferDisable.java 56.52% <100.00%> (+8.90%) ⬆️
...sar/broker/service/persistent/PersistentTopic.java 78.49% <50.00%> (+32.61%) ⬆️
...ransaction/buffer/impl/InMemTransactionBuffer.java 57.57% <50.00%> (+57.57%) ⬆️
...va/org/apache/pulsar/broker/service/ServerCnx.java 72.10% <73.33%> (+35.24%) ⬆️

... and 1575 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderzc
coderzc merged commit 50007c3 into apache:master Dec 13, 2023
Technoboy- pushed a commit that referenced this pull request Jan 16, 2024
@liangyepianzhou @Technoboy-
[fix][txn] Fix getting last message ID when there are ongoing transac…
99cab24
…tions (#21466)
@Technoboy- Technoboy- added the cherry-picked/branch-3.1 label Jan 16, 2024
@thetumbled thetumbled mentioned this pull request Feb 27, 2024
[cherry-pick] [branch-3.0] Fix getting last message ID when there are ongoing transactions #22130
Closed
2 of 15 tasks
mukesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Mar 1, 2024
@liangyepianzhou @mukesh-ctds
[fix][txn] Fix getting last message ID when there are ongoing transac…
6a1d25c
…tions (apache#21466)

(cherry picked from commit 99cab24)
lhotari pushed a commit that referenced this pull request Mar 4, 2024
@liangyepianzhou @lhotari
[fix][txn] Fix getting last message ID when there are ongoing transac…
4489d03
…tions (#21466)

(cherry picked from commit 50007c3)
@lhotari lhotari added cherry-picked/branch-3.0 release/2.10.7 release/2.11.5 and removed release/2.10.6 release/2.11.4 labels Mar 4, 2024
mukesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Mar 6, 2024
@liangyepianzhou @mukesh-ctds
[fix][txn] Fix getting last message ID when there are ongoing transac…
b5f4953
…tions (apache#21466)

(cherry picked from commit 99cab24)
codelipenghui pushed a commit that referenced this pull request Apr 28, 2024
@liangyepianzhou @codelipenghui
[fix][txn] Fix getting last message ID when there are ongoing transac…
78cda11
…tions (#21466)

(cherry picked from commit 50007c3)
@codelipenghui codelipenghui added the cherry-picked/branch-2.11 label Apr 28, 2024
@liangyepianzhou
liangyepianzhou deleted the getmaxposition branch July 23, 2024 08:22
@TakaHiR07 TakaHiR07 mentioned this pull request Oct 28, 2025
[fix][broker] fix getMaxReadPosition in TransactionBufferDisable should return latest #24898
Merged
1 of 15 tasks
@lhotari lhotari mentioned this pull request Oct 28, 2025
[Bug] RawReader.getMessageId should return the messageId of the last committed message #21456
Closed
1 of 2 tasks
@lhotari lhotari mentioned this pull request Oct 22, 2026
[fix][broker] Reply to failed GetLastMessageId with the original request id #27053
Merged
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes
@gaoran10 gaoran10 gaoran10 approved these changes
@BewareMyPower BewareMyPower BewareMyPower approved these changes
@coderzc coderzc coderzc approved these changes
@poorbarcode poorbarcode Awaiting requested review from poorbarcode

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@liangyepianzhou liangyepianzhou

Labels

cherry-picked/branch-2.11 cherry-picked/branch-3.0 cherry-picked/branch-3.1 doc-not-needed Your PR changes do not impact docs release/2.9.5 release/2.10.7 release/2.11.5 release/3.0.3 release/3.1.3 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Milestone

3.2.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@liangyepianzhou @codelipenghui @coderzc @codecov-commenter @gaoran10 @BewareMyPower @lhotari @Technoboy- @AnonHxy
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.