YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/db_iterator_wrapper.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) Yugabyte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
13
#ifndef YB_ROCKSDB_DB_DB_ITERATOR_WRAPPER_H
14
#define YB_ROCKSDB_DB_DB_ITERATOR_WRAPPER_H
15
16
#include <memory>
17
18
#include "yb/rocksdb/iterator.h"
19
20
namespace rocksdb {
21
22
class DBIteratorWrapper : public Iterator {
23
 public:
24
  explicit DBIteratorWrapper(Iterator* wrapped)
25
0
      : wrapped_(wrapped) {}
26
27
0
  virtual ~DBIteratorWrapper() {}
28
29
0
  bool Valid() const override {
30
0
    return wrapped_->Valid();
31
0
  }
32
33
0
  void SeekToFirst() override {
34
0
    wrapped_->SeekToFirst();
35
0
  }
36
37
0
  void SeekToLast() override {
38
0
    wrapped_->SeekToLast();
39
0
  }
40
41
0
  void Seek(const Slice& target) override {
42
0
    wrapped_->Seek(target);
43
0
  }
44
45
0
  void Next() override {
46
0
    wrapped_->Next();
47
0
  }
48
49
0
  void Prev() override {
50
0
    wrapped_->Prev();
51
0
  }
52
53
0
  Slice key() const override {
54
0
    return wrapped_->key();
55
0
  }
56
57
0
  Slice value() const override {
58
0
    return wrapped_->value();
59
0
  }
60
61
0
  Status status() const override {
62
0
    return wrapped_->status();
63
0
  }
64
65
0
  Status GetProperty(std::string prop_name, std::string* prop) override {
66
0
    return wrapped_->GetProperty(prop_name, prop);
67
0
  }
68
69
 protected:
70
  std::unique_ptr<Iterator> wrapped_;
71
};
72
73
// A wrapper that logs all operations on the iterator.
74
class TransitionLoggingIteratorWrapper : public DBIteratorWrapper {
75
 public:
76
  TransitionLoggingIteratorWrapper(
77
      Iterator* wrapped,
78
      const std::string& rocksdb_log_prefix)
79
      : DBIteratorWrapper(wrapped),
80
0
        rocksdb_log_prefix_(rocksdb_log_prefix) {}
81
82
  void SeekToFirst() override;
83
  void SeekToLast() override;
84
  void Seek(const Slice& target) override;
85
  void Next() override;
86
  void Prev() override;
87
88
 private:
89
  std::string LogPrefix() const;
90
  std::string StateStr() const;
91
92
  template<typename Functor>
93
  void LogBeforeAndAfter(const std::string& action_str, const Functor& functor);
94
95
  std::string rocksdb_log_prefix_;
96
};
97
98
}  // namespace rocksdb
99
100
#endif  // YB_ROCKSDB_DB_DB_ITERATOR_WRAPPER_H