YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/table/iterator.cc
Line
Count
Source (jump to first uncovered line)
1
//  Copyright (c) 2011-present, Facebook, 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
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
21
// Use of this source code is governed by a BSD-style license that can be
22
// found in the LICENSE file. See the AUTHORS file for names of contributors.
23
24
#include "yb/rocksdb/iterator.h"
25
#include "yb/rocksdb/table/internal_iterator.h"
26
#include "yb/rocksdb/util/arena.h"
27
28
namespace rocksdb {
29
30
144M
Cleanable::Cleanable() {
31
144M
  cleanup_.function = nullptr;
32
144M
  cleanup_.next = nullptr;
33
144M
}
34
35
132M
Cleanable::~Cleanable() {
36
132M
  if (cleanup_.function != nullptr) {
37
41.4M
    (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2);
38
41.4M
    for (Cleanup* c = cleanup_.next; c != nullptr; ) {
39
0
      (*c->function)(c->arg1, c->arg2);
40
0
      Cleanup* next = c->next;
41
0
      delete c;
42
0
      c = next;
43
0
    }
44
41.4M
  }
45
132M
}
46
47
41.4M
void Cleanable::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) {
48
41.4M
  assert(func != nullptr);
49
41.4M
  Cleanup* c;
50
41.4M
  if (cleanup_.function == nullptr) {
51
41.4M
    c = &cleanup_;
52
18.4E
  } else {
53
18.4E
    c = new Cleanup;
54
18.4E
    c->next = cleanup_.next;
55
18.4E
    cleanup_.next = c;
56
18.4E
  }
57
41.4M
  c->function = func;
58
41.4M
  c->arg1 = arg1;
59
41.4M
  c->arg2 = arg2;
60
41.4M
}
61
62
0
Status Iterator::GetProperty(std::string prop_name, std::string* prop) {
63
0
  if (prop == nullptr) {
64
0
    return STATUS(InvalidArgument, "prop is nullptr");
65
0
  }
66
0
  if (prop_name == "rocksdb.iterator.is-key-pinned") {
67
0
    *prop = "0";
68
0
    return Status::OK();
69
0
  }
70
0
  return STATUS(InvalidArgument, "Undentified property.");
71
0
}
72
73
namespace {
74
class EmptyIterator : public Iterator {
75
 public:
76
1
  explicit EmptyIterator(const Status& s) : status_(s) { }
77
0
  bool Valid() const override { return false; }
78
0
  void Seek(const Slice& target) override {}
79
0
  void SeekToFirst() override {}
80
0
  void SeekToLast() override {}
81
0
  void Next() override { assert(false); }
82
0
  void Prev() override { assert(false); }
83
0
  Slice key() const override {
84
0
    assert(false);
85
0
    return Slice();
86
0
  }
87
0
  Slice value() const override {
88
0
    assert(false);
89
0
    return Slice();
90
0
  }
91
1
  Status status() const override { return status_; }
92
93
 private:
94
  Status status_;
95
};
96
97
class EmptyInternalIterator : public InternalIterator {
98
 public:
99
83
  explicit EmptyInternalIterator(const Status& s) : status_(s) {}
100
101
  bool Valid() const override { return false; }
101
3
  void Seek(const Slice& target) override {}
102
50
  void SeekToFirst() override {}
103
0
  void SeekToLast() override {}
104
0
  void Next() override { assert(false); }
105
0
  void Prev() override { assert(false); }
106
0
  Slice key() const override {
107
0
    assert(false);
108
0
    return Slice();
109
0
  }
110
0
  Slice value() const override {
111
0
    assert(false);
112
0
    return Slice();
113
0
  }
114
197
  Status status() const override { return status_; }
115
116
 private:
117
  Status status_;
118
};
119
}  // namespace
120
121
0
Iterator* NewEmptyIterator() {
122
0
  return new EmptyIterator(Status::OK());
123
0
}
124
125
1
Iterator* NewErrorIterator(const Status& status) {
126
1
  return new EmptyIterator(status);
127
1
}
128
129
0
InternalIterator* NewEmptyInternalIterator() {
130
0
  return new EmptyInternalIterator(Status::OK());
131
0
}
132
133
0
InternalIterator* NewEmptyInternalIterator(Arena* arena) {
134
0
  if (arena == nullptr) {
135
0
    return NewEmptyInternalIterator();
136
0
  } else {
137
0
    auto mem = arena->AllocateAligned(sizeof(EmptyIterator));
138
0
    return new (mem) EmptyInternalIterator(Status::OK());
139
0
  }
140
0
}
141
142
83
InternalIterator* NewErrorInternalIterator(const Status& status) {
143
83
  return new EmptyInternalIterator(status);
144
83
}
145
146
33
InternalIterator* NewErrorInternalIterator(const Status& status, Arena* arena) {
147
33
  if (arena == nullptr) {
148
33
    return NewErrorInternalIterator(status);
149
0
  } else {
150
0
    auto mem = arena->AllocateAligned(sizeof(EmptyIterator));
151
0
    return new (mem) EmptyInternalIterator(status);
152
0
  }
153
33
}
154
155
}  // namespace rocksdb