1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
12 #include "db_stress_tool/db_stress_common.h"
14 namespace ROCKSDB_NAMESPACE
{
15 class DbStressEnvWrapper
: public EnvWrapper
{
17 explicit DbStressEnvWrapper(Env
* t
) : EnvWrapper(t
) {}
18 static const char* kClassName() { return "DbStressEnv"; }
19 const char* Name() const override
{ return kClassName(); }
21 Status
DeleteFile(const std::string
& f
) override
{
22 // We determine whether it is a manifest file by searching a strong,
23 // so that there will be false positive if the directory path contains the
24 // keyword but it is unlikely.
25 // Checkpoint, backup, and restore directories needs to be exempted.
26 if (!if_preserve_all_manifests
||
27 f
.find("MANIFEST-") == std::string::npos
||
28 f
.find("checkpoint") != std::string::npos
||
29 f
.find(".backup") != std::string::npos
||
30 f
.find(".restore") != std::string::npos
) {
31 return target()->DeleteFile(f
);
33 // Rename the file instead of deletion to keep the history, and
34 // at the same time it is not visible to RocksDB.
35 return target()->RenameFile(f
, f
+ "_renamed_");
38 // If true, all manifest files will not be delted in DeleteFile().
39 bool if_preserve_all_manifests
= true;
41 } // namespace ROCKSDB_NAMESPACE