Coverage Report

Created: 2026-09-28 07:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rocksdb/db/coalescing_iterator.h
Line
Count
Source
1
//  Copyright (c) Meta Platforms, Inc. and affiliates.
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 <string>
9
#include <utility>
10
#include <vector>
11
12
#include "db/multi_cf_iterator_impl.h"
13
14
namespace ROCKSDB_NAMESPACE {
15
16
class CoalescingIterator : public Iterator {
17
 public:
18
  CoalescingIterator(
19
      const ReadOptions& read_options, const Comparator* comparator,
20
      std::vector<std::pair<ColumnFamilyHandle*, std::unique_ptr<Iterator>>>&&
21
          cfh_iter_pairs)
22
0
      : impl_(read_options, comparator, std::move(cfh_iter_pairs),
23
0
              ResetFunc(this), PopulateFunc(this)) {}
24
0
  ~CoalescingIterator() override {}
25
26
  // No copy allowed
27
  CoalescingIterator(const CoalescingIterator&) = delete;
28
  CoalescingIterator& operator=(const CoalescingIterator&) = delete;
29
30
0
  bool Valid() const override { return impl_.Valid(); }
31
0
  void SeekToFirst() override { impl_.SeekToFirst(); }
32
0
  void SeekToLast() override { impl_.SeekToLast(); }
33
0
  void Seek(const Slice& target) override { impl_.Seek(target); }
34
0
  void SeekForPrev(const Slice& target) override { impl_.SeekForPrev(target); }
35
0
  void Next() override { impl_.Next(); }
36
0
  void Prev() override { impl_.Prev(); }
37
0
  Slice key() const override { return impl_.key(); }
38
0
  Status status() const override { return impl_.status(); }
39
40
0
  Slice value() const override {
41
0
    assert(Valid());
42
0
    return value_;
43
0
  }
44
0
  const WideColumns& columns() const override {
45
0
    assert(Valid());
46
0
    return wide_columns_;
47
0
  }
48
49
0
  void Reset() {
50
0
    value_.clear();
51
0
    wide_columns_.clear();
52
0
    owned_columns_.clear();
53
0
  }
54
55
0
  bool PrepareValue() override { return impl_.PrepareValue(); }
56
57
 private:
58
  class ResetFunc {
59
   public:
60
0
    explicit ResetFunc(CoalescingIterator* iter) : iter_(iter) {}
61
62
0
    void operator()() const {
63
0
      assert(iter_);
64
0
      iter_->Reset();
65
0
    }
66
67
   private:
68
    CoalescingIterator* iter_;
69
  };
70
71
  class PopulateFunc {
72
   public:
73
0
    explicit PopulateFunc(CoalescingIterator* iter) : iter_(iter) {}
74
75
0
    void operator()(const autovector<MultiCfIteratorInfo>& items) const {
76
0
      assert(iter_);
77
0
      iter_->Coalesce(items);
78
0
    }
79
80
   private:
81
    CoalescingIterator* iter_;
82
  };
83
84
  MultiCfIteratorImpl<ResetFunc, PopulateFunc> impl_;
85
  Slice value_;
86
  WideColumns wide_columns_;
87
  std::vector<std::pair<std::string, std::string>> owned_columns_;
88
89
  struct WideColumnWithOrder {
90
    const WideColumn* column;
91
    int order;
92
  };
93
94
  class WideColumnWithOrderComparator {
95
   public:
96
0
    explicit WideColumnWithOrderComparator() {}
97
    bool operator()(const WideColumnWithOrder& a,
98
0
                    const WideColumnWithOrder& b) const {
99
0
      int c = a.column->name().compare(b.column->name());
100
0
      return c == 0 ? a.order - b.order > 0 : c > 0;
101
0
    }
102
  };
103
104
  using MinHeap =
105
      BinaryHeap<WideColumnWithOrder, WideColumnWithOrderComparator>;
106
107
  void Coalesce(const autovector<MultiCfIteratorInfo>& items);
108
};
109
110
}  // namespace ROCKSDB_NAMESPACE