From 96ce0470a71be5464b912fa4be41f9a6b2dd405d Mon Sep 17 00:00:00 2001 From: Cheng Chang Date: Wed, 22 Jul 2020 13:52:45 -0700 Subject: [PATCH] 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 --- db/db_test.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/db_test.cc b/db/db_test.cc index 00668cc06..6e858bf84 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -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