YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/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
357M
Cleanable::Cleanable() {
31
357M
  cleanup_.function = nullptr;
32
357M
  cleanup_.next = nullptr;
33
357M
}
34
35
329M
Cleanable::~Cleanable() {
36
329M
  if (cleanup_.function != nullptr) {
37
115M
    (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2);
38
115M
    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
115M
  }
45
329M
}
46
47
114M
void Cleanable::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) {
48
114M
  assert(func != nullptr);
49
0
  Cleanup* c;
50
114M
  if (
cleanup_.function == nullptr114M
) {
51
114M
    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
114M
  c->function = func;
58
114M
  c->arg1 = arg1;
59
114M
  c->arg2 = arg2;
60
114M
}
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
107
  explicit EmptyInternalIterator(const Status& s) : status_(s) {}
100
154
  bool Valid() const override { return false; }
101
10
  void Seek(const Slice& target) override {}
102
74
  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
199
  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
2
InternalIterator* NewEmptyInternalIterator() {
130
2
  return new EmptyInternalIterator(Status::OK());
131
2
}
132
133
2
InternalIterator* NewEmptyInternalIterator(Arena* arena) {
134
2
  if (arena == nullptr) {
135
2
    return NewEmptyInternalIterator();
136
2
  } else {
137
0
    auto mem = arena->AllocateAligned(sizeof(EmptyIterator));
138
0
    return new (mem) EmptyInternalIterator(Status::OK());
139
0
  }
140
2
}
141
142
83
InternalIterator* NewErrorInternalIterator(const Status& status) {
143
83
  return new EmptyInternalIterator(status);
144
83
}
145
146
55
InternalIterator* NewErrorInternalIterator(const Status& status, Arena* arena) {
147
55
  if (arena == nullptr) {
148
33
    return NewErrorInternalIterator(status);
149
33
  } else {
150
22
    auto mem = arena->AllocateAligned(sizeof(EmptyIterator));
151
22
    return new (mem) EmptyInternalIterator(status);
152
22
  }
153
55
}
154
155
}  // namespace rocksdb