Coverage Report

Created: 2025-10-26 07:13

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