YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/utilities/env_mirror.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2015, Red Hat, Inc.  All rights reserved.
2
// This source code is licensed under the BSD-style license found in the
3
// LICENSE file in the root directory of this source tree. An additional grant
4
// of patent rights can be found in the PATENTS file in the same directory.
5
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
6
// Use of this source code is governed by a BSD-style license that can be
7
// found in the LICENSE file. See the AUTHORS file for names of contributors.
8
//
9
// The following only applies to changes made to this file as part of YugaByte development.
10
//
11
// Portions Copyright (c) YugaByte, Inc.
12
//
13
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
14
// in compliance with the License.  You may obtain a copy of the License at
15
//
16
// http://www.apache.org/licenses/LICENSE-2.0
17
//
18
// Unless required by applicable law or agreed to in writing, software distributed under the License
19
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
20
// or implied.  See the License for the specific language governing permissions and limitations
21
// under the License.
22
//
23
// MirrorEnv is an Env implementation that mirrors all file-related
24
// operations to two backing Env's (provided at construction time).
25
// Writes are mirrored.  For read operations, we do the read from both
26
// backends and assert that the results match.
27
//
28
// This is useful when implementing a new Env and ensuring that the
29
// semantics and behavior are correct (in that they match that of an
30
// existing, stable Env, like the default POSIX one).
31
#ifndef YB_ROCKSDB_UTILITIES_ENV_MIRROR_H
32
#define YB_ROCKSDB_UTILITIES_ENV_MIRROR_H
33
34
#ifndef ROCKSDB_LITE
35
36
#include <iostream>
37
#include <algorithm>
38
#include <vector>
39
#include "yb/rocksdb/env.h"
40
41
namespace rocksdb {
42
43
class SequentialFileMirror;
44
class RandomAccessFileMirror;
45
class WritableFileMirror;
46
47
class EnvMirror : public EnvWrapper {
48
  Env* a_, *b_;
49
50
 public:
51
0
  EnvMirror(Env* a, Env* b) : EnvWrapper(a), a_(a), b_(b) {}
52
53
  Status NewSequentialFile(const std::string& f, unique_ptr<SequentialFile>* r,
54
                           const EnvOptions& options) override;
55
  Status NewRandomAccessFile(const std::string& f,
56
                             unique_ptr<RandomAccessFile>* r,
57
                             const EnvOptions& options) override;
58
  Status NewWritableFile(const std::string& f, unique_ptr<WritableFile>* r,
59
                         const EnvOptions& options) override;
60
  Status ReuseWritableFile(const std::string& fname,
61
                           const std::string& old_fname,
62
                           unique_ptr<WritableFile>* r,
63
                           const EnvOptions& options) override;
64
  Status NewDirectory(const std::string& name,
65
                      unique_ptr<Directory>* result) override;
66
  Status FileExists(const std::string& f) override;
67
  Status GetChildren(const std::string& dir,
68
                     std::vector<std::string>* r) override;
69
  Status DeleteFile(const std::string& f) override;
70
  Status CreateDir(const std::string& d) override;
71
  Status CreateDirIfMissing(const std::string& d) override;
72
  Status DeleteDir(const std::string& d) override;
73
  Status GetFileSize(const std::string& f, uint64_t* s) override;
74
75
  Status GetFileModificationTime(const std::string& fname,
76
                                 uint64_t* file_mtime) override;
77
78
  Status RenameFile(const std::string& s, const std::string& t) override;
79
80
  Status LinkFile(const std::string& s, const std::string& t) override;
81
82
  class FileLockMirror : public FileLock {
83
   public:
84
    FileLock* a_, *b_;
85
0
    FileLockMirror(FileLock* a, FileLock* b) : a_(a), b_(b) {}
86
  };
87
88
  Status LockFile(const std::string& f, FileLock** l) override;
89
90
  Status UnlockFile(FileLock* l) override;
91
};
92
93
}  // namespace rocksdb
94
95
#endif  // ROCKSDB_LITE
96
97
#endif  // YB_ROCKSDB_UTILITIES_ENV_MIRROR_H