Coverage Report

Created: 2024-07-27 06:53

/src/rocksdb/db/blob/blob_counting_iterator.h
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 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).
5
6
#pragma once
7
8
#include <cassert>
9
10
#include "db/blob/blob_garbage_meter.h"
11
#include "rocksdb/rocksdb_namespace.h"
12
#include "rocksdb/status.h"
13
#include "table/internal_iterator.h"
14
#include "test_util/sync_point.h"
15
16
namespace ROCKSDB_NAMESPACE {
17
18
// An internal iterator that passes each key-value encountered to
19
// BlobGarbageMeter as inflow in order to measure the total number and size of
20
// blobs in the compaction input on a per-blob file basis.
21
class BlobCountingIterator : public InternalIterator {
22
 public:
23
  BlobCountingIterator(InternalIterator* iter,
24
                       BlobGarbageMeter* blob_garbage_meter)
25
0
      : iter_(iter), blob_garbage_meter_(blob_garbage_meter) {
26
0
    assert(iter_);
27
0
    assert(blob_garbage_meter_);
28
29
0
    UpdateAndCountBlobIfNeeded();
30
0
  }
31
32
0
  bool Valid() const override { return iter_->Valid() && status_.ok(); }
33
34
0
  void SeekToFirst() override {
35
0
    iter_->SeekToFirst();
36
0
    UpdateAndCountBlobIfNeeded();
37
0
  }
38
39
0
  void SeekToLast() override {
40
0
    iter_->SeekToLast();
41
0
    UpdateAndCountBlobIfNeeded();
42
0
  }
43
44
0
  void Seek(const Slice& target) override {
45
0
    iter_->Seek(target);
46
0
    UpdateAndCountBlobIfNeeded();
47
0
  }
48
49
0
  void SeekForPrev(const Slice& target) override {
50
0
    iter_->SeekForPrev(target);
51
0
    UpdateAndCountBlobIfNeeded();
52
0
  }
53
54
0
  void Next() override {
55
0
    assert(Valid());
56
57
0
    iter_->Next();
58
0
    UpdateAndCountBlobIfNeeded();
59
0
  }
60
61
0
  bool NextAndGetResult(IterateResult* result) override {
62
0
    assert(Valid());
63
64
0
    const bool res = iter_->NextAndGetResult(result);
65
0
    UpdateAndCountBlobIfNeeded();
66
0
    return res;
67
0
  }
68
69
0
  void Prev() override {
70
0
    assert(Valid());
71
72
0
    iter_->Prev();
73
0
    UpdateAndCountBlobIfNeeded();
74
0
  }
75
76
0
  Slice key() const override {
77
0
    assert(Valid());
78
0
    return iter_->key();
79
0
  }
80
81
0
  Slice user_key() const override {
82
0
    assert(Valid());
83
0
    return iter_->user_key();
84
0
  }
85
86
0
  Slice value() const override {
87
0
    assert(Valid());
88
0
    return iter_->value();
89
0
  }
90
91
0
  Status status() const override { return status_; }
92
93
0
  bool PrepareValue() override {
94
0
    assert(Valid());
95
0
    return iter_->PrepareValue();
96
0
  }
97
98
0
  bool MayBeOutOfLowerBound() override {
99
0
    assert(Valid());
100
0
    return iter_->MayBeOutOfLowerBound();
101
0
  }
102
103
0
  IterBoundCheck UpperBoundCheckResult() override {
104
0
    assert(Valid());
105
0
    return iter_->UpperBoundCheckResult();
106
0
  }
107
108
0
  void SetPinnedItersMgr(PinnedIteratorsManager* pinned_iters_mgr) override {
109
0
    iter_->SetPinnedItersMgr(pinned_iters_mgr);
110
0
  }
111
112
0
  bool IsKeyPinned() const override {
113
0
    assert(Valid());
114
0
    return iter_->IsKeyPinned();
115
0
  }
116
117
0
  bool IsValuePinned() const override {
118
0
    assert(Valid());
119
0
    return iter_->IsValuePinned();
120
0
  }
121
122
0
  Status GetProperty(std::string prop_name, std::string* prop) override {
123
0
    return iter_->GetProperty(prop_name, prop);
124
0
  }
125
126
0
  bool IsDeleteRangeSentinelKey() const override {
127
0
    return iter_->IsDeleteRangeSentinelKey();
128
0
  }
129
130
 private:
131
0
  void UpdateAndCountBlobIfNeeded() {
132
0
    assert(!iter_->Valid() || iter_->status().ok());
133
134
0
    if (!iter_->Valid()) {
135
0
      status_ = iter_->status();
136
0
      return;
137
0
    }
138
139
0
    TEST_SYNC_POINT(
140
0
        "BlobCountingIterator::UpdateAndCountBlobIfNeeded:ProcessInFlow");
141
142
0
    status_ = blob_garbage_meter_->ProcessInFlow(key(), value());
143
0
  }
144
145
  InternalIterator* iter_;
146
  BlobGarbageMeter* blob_garbage_meter_;
147
  Status status_;
148
};
149
150
}  // namespace ROCKSDB_NAMESPACE