Clean snapshot dir before taking snapshot (#7156)

Summary:
`DBTest::SnapshotFiles` runs the tests in a `while` loop.
Currently, the snapshot directory is not cleaned up in each loop, so previous snapshot files may remain in the next loop's snapshot.
When I'm working on https://github.com/facebook/rocksdb/pull/7129, when checking the tracked WALs in MANIFEST, I find that this test always fails because it reads some unknown WAL. It turns out that the unknown WAL is left from previous loops.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/7156

Test Plan: make db_test && ./db_test --gtest_filters=*SnapshotFiles

Reviewed By: siying

Differential Revision: D22668360

Pulled By: cheng-chang

fbshipit-source-id: 69d4aa3506038ba30e218e8ae966357935a99c6c
This commit is contained in:
Cheng Chang 2020-07-22 13:52:45 -07:00 committed by Facebook GitHub Bot
parent d44cbc5314
commit 96ce0470a7

View File

@ -2210,7 +2210,10 @@ TEST_F(DBTest, SnapshotFiles) {
// copy these files to a new snapshot directory
std::string snapdir = dbname_ + ".snapdir/";
ASSERT_OK(env_->CreateDirIfMissing(snapdir));
if (env_->FileExists(snapdir).ok()) {
ASSERT_OK(DestroyDir(env_, snapdir));
}
ASSERT_OK(env_->CreateDir(snapdir));
for (size_t i = 0; i < files.size(); i++) {
// our clients require that GetLiveFiles returns