Skip to content

db_stress option to preserve all files until verification success - #10659

Closed
ajkr wants to merge 8 commits into
meta:mainfrom
ajkr:dbstress-preserve-all-files-until-verified
Closed

ajkr wants to merge 8 commits into
meta:mainfrom
ajkr:dbstress-preserve-all-files-until-verified

Conversation

@ajkr

@ajkr ajkr commented Sep 9, 2022 •

Copy link
Copy Markdown
Contributor

In db_stress, DB and expected state files containing changes leading up to a verification failure are often deleted, which makes debugging such failures difficult. On the DB side, flushed WAL files and compacted SST files are marked obsolete and then deleted. Without those files, we cannot pinpoint where a key that failed verification changed unexpectedly. On the expected state side, files for verifying prefix-recoverability in the presence of unsynced data loss are deleted before verification. These include a baseline state file containing the expected state at the time of the last successful verification, and a trace file containing all operations since then. Without those files, we cannot know the sequence of DB operations expected to be recovered.

This PR attempts to address this gap with a new db_stress flag: preserve_unverified_changes. Setting preserve_unverified_changes=1 has two effects.

First, prior to startup verification, db_stress hardlinks all DB and expected state files in "unverified/" subdirectories of FLAGS_db and FLAGS_expected_values_dir. The separate directories are needed because the pre-verification opening process deletes files written by the previous db_stress run as described above. These "unverified/" subdirectories are cleaned up following startup verification success.

I considered other approaches for preserving DB files through startup verification, like using a read-only DB or preventing deletion of DB files externally, e.g., in the Env layer. However, I decided against it since such an approach would not work for expected state files, and I did not want to change the DB management logic. If there were a way to disable DB file deletions before regular DB open, I would have preferred to use that.

Second, db_stress attempts to keep all DB and expected state files that were live at some point since the start of the db_stress run. This is a bit tricky and involves the following changes.

  • Open the DB with disable_auto_compactions=1 and avoid_flush_during_recovery=1
  • DisableFileDeletions()
  • EnableAutoCompaction()

For this part, too, I would have preferred to use a hypothetical API that disables DB file deletion before regular DB open.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ajkr has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Comment thread db_stress_tool/db_stress_driver.cc Outdated
Comment on lines 64 to 74

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would be nice to preserve any trace+state file that get removed during FileExpectedStateManager::Restore() regardless of FLAGS_preserve_unverified_changes's value. But I am not sure how to make it fit conceptually yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the reason why we need to remove them in FileExpectedStateManager::Restore() other than they takes space if not??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I had the same feeling and tried leaving them there, but it violated an assumption that the any n.{state,trace} that exist can be used to reconstruct LATEST.state: https://github.com/facebook/rocksdb/blob/f79b3d19a77f649536da6321f40e1c0d269bde48/db_stress_tool/db_stress_test_base.cc#L302-L307

If we leave them there through Restore() and delete them later before OperateDb() it is probably fine. There is deletion logic in SaveAtAndAfter() but it isn't enough because non-tracing runs don't call it. So I wasn't sure if there's a clean place to move the deletion logic.

@ajkr
ajkr force-pushed the dbstress-preserve-all-files-until-verified branch from 1bd20b9 to 022ca86 Compare September 10, 2022 19:34
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ajkr has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ajkr has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ajkr has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@ajkr has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@hx235 hx235 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall LGTM! I should have plenty of opportunities to exercise this feature when debugging for #10291 / #10624 's discovered issues.

@ajkr

ajkr commented Sep 12, 2022

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

Tim-Reed pushed a commit to Tim-Reed/rocksdb that referenced this pull request Oct 1, 2026
…ta#10659)

Summary:
In `db_stress`, DB and expected state files containing changes leading up to a verification failure are often deleted, which makes debugging such failures difficult. On the DB side, flushed WAL files and compacted SST files are marked obsolete and then deleted. Without those files, we cannot pinpoint where a key that failed verification changed unexpectedly. On the expected state side, files for verifying prefix-recoverability in the presence of unsynced data loss are deleted before verification. These include a baseline state file containing the expected state at the time of the last successful verification, and a trace file containing all operations since then. Without those files, we cannot know the sequence of DB operations expected to be recovered.

This PR attempts to address this gap with a new `db_stress` flag: `preserve_unverified_changes`. Setting `preserve_unverified_changes=1` has two effects.

First, prior to startup verification, `db_stress` hardlinks all DB and expected state files in "unverified/" subdirectories of `FLAGS_db` and `FLAGS_expected_values_dir`. The separate directories are needed because the pre-verification opening process deletes files written by the previous `db_stress` run as described above. These "unverified/" subdirectories are cleaned up following startup verification success.

I considered other approaches for preserving DB files through startup verification, like using a read-only DB or preventing deletion of DB files externally, e.g., in the `Env` layer. However, I decided against it since such an approach would not work for expected state files, and I did not want to change the DB management logic. If there were a way to disable DB file deletions before regular DB open, I would have preferred to use that.

Second, `db_stress` attempts to keep all DB and expected state files that were live at some point since the start of the `db_stress` run. This is a bit tricky and involves the following changes.

- Open the DB with `disable_auto_compactions=1` and `avoid_flush_during_recovery=1`
- DisableFileDeletions()
- EnableAutoCompactions()

For this part, too, I would have preferred to use a hypothetical API that disables DB file deletion before regular DB open.

Pull Request resolved: meta#10659

Reviewed By: hx235

Differential Revision: D39407454

Pulled By: ajkr

fbshipit-source-id: 6e981025c7dce147649d2e770728471395a7fa53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants