Skip to content

eventstore: fix checkpoint update race#4987

Open
lidezhu wants to merge 3 commits intoldz/optimize-event-store0506from
ldz/optimize-event-store001
Open

eventstore: fix checkpoint update race#4987
lidezhu wants to merge 3 commits intoldz/optimize-event-store0506from
ldz/optimize-event-store001

Conversation

@lidezhu
Copy link
Copy Markdown
Collaborator

@lidezhu lidezhu commented May 3, 2026

What problem does this PR solve?

Issue Number: close #4992

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

If you don't think this PR needs a release note then fill it with `None`.

@ti-chi-bot ti-chi-bot Bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label May 3, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 3, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign tenfyzhong for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 3, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a3dacb26-d5ef-4523-86f8-8c153a3eb552

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ldz/optimize-event-store001

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 3, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request transitions checkpointTs to an atomic type within the dispatcherStat struct and refactors checkpoint update logic to use CompareAndSwap for better concurrency control. Additionally, it replaces bytes.Compare with common.StartCompare and common.EndCompare for key range checks and updates the event store iterator's boundary conditions. Feedback suggests using a monotonic increase utility for updating the dispatcher's checkpoint to prevent potential regressions from stale updates.

return
}
dispatcherStat.checkpointTs = checkpointTs
dispatcherStat.checkpointTs.Store(checkpointTs)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To ensure that the dispatcher's checkpoint timestamp only moves forward and to handle potential concurrent updates safely, it is better to use util.CompareAndMonotonicIncrease instead of a direct Store. This prevents a stale update from regressing the checkpoint, which could incorrectly affect the minimum checkpoint calculation for the shared subscription.

Suggested change
dispatcherStat.checkpointTs.Store(checkpointTs)
util.CompareAndMonotonicIncrease(&dispatcherStat.checkpointTs, checkpointTs)

@lidezhu lidezhu changed the title eventstore: fix potential race eventstore: fix checkpoint update race May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant