Skip to content

sst_importer: ensure cleanup of temporary files on error#19240

Merged
ti-chi-bot[bot] merged 4 commits intotikv:masterfrom
YuJuncen:fix-batch-download-cleanup
Dec 31, 2025
Merged

sst_importer: ensure cleanup of temporary files on error#19240
ti-chi-bot[bot] merged 4 commits intotikv:masterfrom
YuJuncen:fix-batch-download-cleanup

Conversation

@YuJuncen
Copy link
Contributor

@YuJuncen YuJuncen commented Dec 26, 2025

What is changed and how it works?

Issue Number: Close #19239, ref #17283

What's Changed:

sst_importer: enhance failpoint handling and ensure cleanup of temporary files on error

- Ensure temporary files are cleaned up when a download fails in sst_importer
- Add a new failpoint `download_files_ext_after_download` to inject errors right after batch downloads complete, improving test coverage of cleanup paths

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test (extends tests to verify temporary files and encryption metadata are cleaned up)
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Release note

Fix a bug where temporary SST files could be left behind when a download failed in sst_importer.

…ary files on error

Signed-off-by: Juncen Yu <yujuncen@pingcap.com>
Copilot AI review requested due to automatic review settings December 26, 2025 06:22
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-triage-completed dco-signoff: yes Indicates the PR's author has signed the dco. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 26, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where temporary SST files could be left behind when downloads fail in the sst_importer component. The fix ensures that cleanup happens on all exit paths (both success and error) by using Rust's defer! macro pattern.

Key Changes:

  • Implemented automatic cleanup of temporary files using the defer! macro to ensure cleanup occurs on both success and error paths
  • Added a new failpoint download_files_ext_after_download to enable testing of the cleanup behavior when errors occur after downloads complete
  • Added comprehensive test coverage to verify temporary files are properly cleaned up on error

Reviewed changes

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

File Description
components/sst_importer/src/sst_importer.rs Modified download_files_ext to use defer! for guaranteed cleanup of temporary files, added failpoint for testing, and included a new test test_download_files_ext_cleanup_temp_files_on_error
components/sst_importer/Cargo.toml Added tikv/failpoints dependency to the failpoints feature to enable failpoint testing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Juncen Yu <yujuncen@pingcap.com>
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 29, 2025
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 29, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 29, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-12-29 06:55:06.544837556 +0000 UTC m=+2665651.358615148: ☑️ agreed by 3pointer.
  • 2025-12-29 07:12:51.998677151 +0000 UTC m=+2666716.812454713: ☑️ agreed by Leavrth.

Signed-off-by: Juncen Yu <yujuncen@pingcap.com>
…download-cleanup

Signed-off-by: Juncen Yu <yujuncen@pingcap.com>
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Dec 31, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 3pointer, iosmanthus, Leavrth

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 the approved label Dec 31, 2025
@YuJuncen
Copy link
Contributor Author

/test pull-unit-test

@ti-chi-bot ti-chi-bot bot added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Dec 31, 2025
@ti-chi-bot ti-chi-bot bot merged commit a9caab4 into tikv:master Dec 31, 2025
9 checks passed
@ti-chi-bot ti-chi-bot bot added this to the Pool milestone Dec 31, 2025
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #19256.

YuJuncen added a commit to YuJuncen/tikv that referenced this pull request Dec 31, 2025
ref tikv#17283, close tikv#19239

sst_importer: enhance failpoint handling and ensure cleanup of temporary files on error

- Ensure temporary files are cleaned up when a download fails in sst_importer
- Add a new failpoint `download_files_ext_after_download` to inject errors right after batch downloads complete, improving test coverage of cleanup paths

Signed-off-by: Juncen Yu <yujuncen@pingcap.com>
YuJuncen added a commit that referenced this pull request Dec 31, 2025
* sst_importer: set fill cache to false when merge downloaded SST files (#19229)

close #19228

set fill cache to false when merge downloaded SST files

Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>

* sst_importer: ensure cleanup of temporary files on error (#19240)

ref #17283, close #19239

sst_importer: enhance failpoint handling and ensure cleanup of temporary files on error

- Ensure temporary files are cleaned up when a download fails in sst_importer
- Add a new failpoint `download_files_ext_after_download` to inject errors right after batch downloads complete, improving test coverage of cleanup paths

Signed-off-by: Juncen Yu <yujuncen@pingcap.com>

* Squashed commit of the following:

commit 5a14b2b
Author: Juncen Yu <yujuncen@pingcap.com>
Date:   Mon Dec 29 15:11:06 2025 +0800

    make clippy happy

    Signed-off-by: Juncen Yu <yujuncen@pingcap.com>

commit ace595e
Merge: bd5bff3 147cacc
Author: Juncen Yu <yujuncen@pingcap.com>
Date:   Fri Dec 26 17:51:36 2025 +0800

    Merge branch 'master' of https://github.com/tikv/tikv into resolve-compact-conflict

commit bd5bff3
Merge: fde14ce 301984c
Author: Juncen Yu <yujuncen@pingcap.com>
Date:   Mon Dec 22 12:10:59 2025 +0800

    Merge branch 'master' of https://github.com/tikv/tikv into resolve-compact-conflict

    Signed-off-by: Juncen Yu <yujuncen@pingcap.com>

commit fde14ce
Author: Juncen Yu <yujuncen@pingcap.com>
Date:   Tue Mar 18 15:44:06 2025 +0800

    added more checks

    Signed-off-by: Juncen Yu <yujuncen@pingcap.com>

commit d0801cb
Author: Juncen Yu <yujuncen@pingcap.com>
Date:   Tue Mar 18 15:27:14 2025 +0800

    added more case about collapsed rollback

    Signed-off-by: Juncen Yu <yujuncen@pingcap.com>

commit 6d2b994
Author: Juncen Yu <yujuncen@pingcap.com>
Date:   Tue Mar 18 14:52:40 2025 +0800

    compact-log-backup: try to resolve conflict encountering during compacting

    Signed-off-by: Juncen Yu <yujuncen@pingcap.com>

Signed-off-by: Juncen Yu <yujuncen@pingcap.com>

* *: upgrade cargo-deny version to make it compatible to further developments.

Signed-off-by: lucasliang <nkcs_lykx@hotmail.com>

---------

Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Juncen Yu <yujuncen@pingcap.com>
Signed-off-by: lucasliang <nkcs_lykx@hotmail.com>
Co-authored-by: Jianjun Liao <36503113+Leavrth@users.noreply.github.com>
Co-authored-by: lucasliang <nkcs_lykx@hotmail.com>
ti-chi-bot bot pushed a commit that referenced this pull request Jan 7, 2026
…9256)

ref #17283, close #19239

sst_importer: enhance failpoint handling and ensure cleanup of temporary files on error

- Ensure temporary files are cleaned up when a download fails in sst_importer
- Add a new failpoint `download_files_ext_after_download` to inject errors right after batch downloads complete, improving test coverage of cleanup paths

Signed-off-by: Juncen Yu <yujuncen@pingcap.com>
Signed-off-by: 山岚 <36239017+YuJuncen@users.noreply.github.com>

Co-authored-by: Juncen Yu <yujuncen@pingcap.com>
Co-authored-by: 山岚 <36239017+YuJuncen@users.noreply.github.com>
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 needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sst_importer: orphan files may left in disk when download partically failed

6 participants