Skip to content

fix(storage): fsync the backup parent directory after rename - #3838

Closed
dragonknightk wants to merge 1 commit into
apache:unstablefrom
dragonknightk:fix/3836
Closed

dragonknightk wants to merge 1 commit into
apache:unstablefrom
dragonknightk:fix/3836

Conversation

@dragonknightk

Copy link
Copy Markdown

Issue

closes #3836

Description

After renaming the new checkpoint into backup-dir, CreateBackup now fsyncs the parent directory, because without that fsync a power cut can leave the previous backup there after the call has already returned OK.

If opening or fsyncing the parent fails, return an error so BGSAVE does not report ok. The DestroyDB unlinks just before the rename live in the same parent, so one fsync after the rename also covers them. The window between DestroyDB and the rename is left unchanged, because CreateBackup has not returned OK yet.

RocksDB's Checkpoint already fsyncs the checkpoint directory itself after it is created under backup-dir.tmp. That does not persist the later rename of that directory into backup-dir.

Tests

The existing Storage.* tests pass. Storage's Env is fixed to Env::Default(), so a failing fsync cannot be injected, and no new test was added.

AI usage

Grok Bot, working for dragonknightk, assisted with the changes, the description, and the verification. All content was reviewed by a human, and the submitter understands and can maintain these changes.

## Issue

Closes issue 3836

## Description

After renaming the new checkpoint into backup-dir, CreateBackup now fsyncs the parent directory, because without that fsync a power cut can leave the previous backup there after the call has already returned OK.

If opening or fsyncing the parent fails, return an error so BGSAVE does not report ok. The DestroyDB unlinks just before the rename live in the same parent, so one fsync after the rename also covers them. The window between DestroyDB and the rename is left unchanged, because CreateBackup has not returned OK yet.

RocksDB's Checkpoint already fsyncs the checkpoint directory itself after it is created under backup-dir.tmp. That does not persist the later rename of that directory into backup-dir.

## Tests

The existing Storage.* tests pass. Storage's Env is fixed to Env::Default(), so a failing fsync cannot be injected, and no new test was added.

Signed-off-by: dragonknightk <37928252+dragonknightk@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Hi @dragonknightk,

Thank you for your pull request. Please review our Contributing Guide.

Please make sure you understand your changes and explain your reasoning in this pull request. Low-quality pull requests may be closed.

@git-hulk

Copy link
Copy Markdown
Member

Don't need to fix this issue, explains in issue.

@git-hulk git-hulk closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After a power cut, backup-dir holds the previous backup although BGSAVE reported the new one done and ok

2 participants