Skip to content

Fix sequence number race when allowing writes during external SST ingestion (#435) - #437

Merged
ti-chi-bot[bot] merged 2 commits into
tikv:6.29.tikvfrom
ti-chi-bot:cherry-pick-435-to-6.29.tikv
Aug 12, 2026
Merged

Fix sequence number race when allowing writes during external SST ingestion (#435)#437
ti-chi-bot[bot] merged 2 commits into
tikv:6.29.tikvfrom
ti-chi-bot:cherry-pick-435-to-6.29.tikv

Conversation

@ti-chi-bot

Copy link
Copy Markdown
Member

This is an automated cherry-pick of #435

Ref tikv/tikv#19891 (comment)

When allow_write=true, external SST ingestion may assign sequence numbers
concurrently with foreground writes. This can cause duplicate sequence numbers
or make the global sequence-number state move backwards.

This change briefly blocks writers to reserve enough sequence numbers before
running the ingestion jobs. Writers are resumed immediately after the
reservation, so SST processing and MANIFEST updates remain outside the
write-blocking period.

The existing behavior for allow_write=false is unchanged.

This also fixes an enable_multi_batch_write edge case where writers that fail
to write WAL still publish their allocated sequence numbers but were not counted
as pending. They are now included in pending-write accounting, preventing
ingestion from reserving sequence numbers before their sequence publication
completes.

Summary by CodeRabbit

  • Bug Fixes

    • Improved external SST file ingestion while writes occur concurrently.
    • Ensured ingestion waits for pending writes before applying imported data.
    • Preserved consistent sequence numbering and prevented conflicts with new writes.
    • Maintained snapshot isolation so earlier snapshots do not expose newly ingested files.
  • Documentation

    • Clarified concurrent-write requirements and snapshot behavior for external file ingestion.
  • Tests

    • Added coverage for concurrent writes and multi-file ingestion.
    • Verified write ordering, final values, sequence assignments, and snapshot visibility.

ref tikv/tikv#19891

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added dco-signoff: yes Indicates the PR's author has signed the dco. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-6.29.tikv labels Aug 11, 2026
@ti-chi-bot

Copy link
Copy Markdown
Member Author

@gengliqi This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8845a33c-080e-4147-9986-861ce3d3207d

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

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.

Signed-off-by: gengliqi <gengliqiii@gmail.com>
@gengliqi
gengliqi requested a balanced review from Copilot August 11, 2026 10:55
@gengliqi gengliqi removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes sequence-number races between foreground writes and external SST ingestion.

Changes:

  • Reserves ingestion sequence numbers while writers are briefly blocked.
  • Extends pending-write accounting to failed multi-batch writes.
  • Adds concurrency, ordering, and snapshot tests plus API documentation.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
include/rocksdb/options.h Documents concurrent ingestion constraints.
db/external_sst_file_test.cc Adds concurrency regression tests.
db/external_sst_file_ingestion_job.h Passes sequence baseline into ingestion jobs.
db/external_sst_file_ingestion_job.cc Uses the reserved sequence baseline.
db/db_impl/db_impl.h Clarifies pending-write accounting.
db/db_impl/db_impl.cc Blocks writers and reserves ingestion sequences.
db/db_impl/db_impl_write.cc Accounts for failed multi-batch writes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread db/db_impl/db_impl.cc
WaitForPendingWrites();
}

SequenceNumber last_seqno = versions_->LastSequence();
@ti-chi-bot ti-chi-bot Bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Aug 11, 2026
@gengliqi
gengliqi requested review from Connor1996 and hhwyt August 11, 2026 15:09
@ti-chi-bot

ti-chi-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gengliqi, overvenus

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

The pull request process is described 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

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 12, 2026
@ti-chi-bot

ti-chi-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-08-11 11:35:27.906744376 +0000 UTC m=+3132713.942839432: ☑️ agreed by gengliqi.
  • 2026-08-12 06:12:33.760937406 +0000 UTC m=+3199739.797032462: ☑️ agreed by overvenus.

@ti-chi-bot
ti-chi-bot Bot merged commit 094d47c into tikv:6.29.tikv Aug 12, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-6.29.tikv

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants