From 2d1d51d3856218a21f634ddf650b249e3a378e66 Mon Sep 17 00:00:00 2001 From: sdong Date: Tue, 30 Jun 2020 12:00:32 -0700 Subject: [PATCH] db_stress: deep clean directory before checkpoint (#7039) Summary: We see crash test occassionally fails with "A checkpoint operation failed with: Invalid argument: Directory exists". The suspicious is that the directory fails to be deleted because some trash files. Deep clean the directory after a DestroyDB() call. Also add more debugging printf in case it fails. Also, preserve the DB if verification fails. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7039 Test Plan: Run db_stress with low --checkpoint_one_in value Reviewed By: riversand963 Differential Revision: D22271694 fbshipit-source-id: 6a9b2abb664fc69a4dc666741df4f6b23703cd6d --- db_stress_tool/db_stress_test_base.cc | 28 +++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/db_stress_tool/db_stress_test_base.cc b/db_stress_tool/db_stress_test_base.cc index 9c94d15e5..d2232ccfb 100644 --- a/db_stress_tool/db_stress_test_base.cc +++ b/db_stress_tool/db_stress_test_base.cc @@ -1335,10 +1335,34 @@ Status StressTest::TestCheckpoint(ThreadState* thread, DestroyDB(checkpoint_dir, tmp_opts); + if (db_stress_env->FileExists(checkpoint_dir).ok()) { + // If the directory might still exist, try to delete the files one by one. + // Likely a trash file is still there. + Status my_s = test::DestroyDir(db_stress_env, checkpoint_dir); + if (!my_s.ok()) { + fprintf(stderr, "Fail to destory directory before checkpoint: %s", + my_s.ToString().c_str()); + } + } + Checkpoint* checkpoint = nullptr; Status s = Checkpoint::Create(db_, &checkpoint); if (s.ok()) { s = checkpoint->CreateCheckpoint(checkpoint_dir); + if (!s.ok()) { + fprintf(stderr, "Fail to create checkpoint to %s\n", + checkpoint_dir.c_str()); + std::vector files; + Status my_s = db_stress_env->GetChildren(checkpoint_dir, &files); + if (my_s.ok()) { + for (const auto& f : files) { + fprintf(stderr, " %s\n", f.c_str()); + } + } else { + fprintf(stderr, "Fail to get files under the directory to %s\n", + my_s.ToString().c_str()); + } + } } std::vector cf_handles; DB* checkpoint_db = nullptr; @@ -1391,11 +1415,11 @@ Status StressTest::TestCheckpoint(ThreadState* thread, checkpoint_db = nullptr; } - DestroyDB(checkpoint_dir, tmp_opts); - if (!s.ok()) { fprintf(stderr, "A checkpoint operation failed with: %s\n", s.ToString().c_str()); + } else { + DestroyDB(checkpoint_dir, tmp_opts); } return s; } -- GitLab