Coverage Report

Created: 2026-08-14 08:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rocksdb/db/attribute_group_iterator_impl.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
#include "rocksdb/attribute_groups.h"
10
11
namespace ROCKSDB_NAMESPACE {
12
13
class AttributeGroupIteratorImpl : public AttributeGroupIterator {
14
 public:
15
  AttributeGroupIteratorImpl(
16
      const ReadOptions& read_options, const Comparator* comparator,
17
      std::vector<std::pair<ColumnFamilyHandle*, std::unique_ptr<Iterator>>>&&
18
          cfh_iter_pairs)
19
0
      : impl_(read_options, comparator, std::move(cfh_iter_pairs),
20
0
              ResetFunc(this), PopulateFunc(this)) {}
21
0
  ~AttributeGroupIteratorImpl() override {}
22
23
  // No copy allowed
24
  AttributeGroupIteratorImpl(const AttributeGroupIteratorImpl&) = delete;
25
  AttributeGroupIteratorImpl& operator=(const AttributeGroupIteratorImpl&) =
26
      delete;
27
28
0
  bool Valid() const override { return impl_.Valid(); }
29
0
  void SeekToFirst() override { impl_.SeekToFirst(); }
30
0
  void SeekToLast() override { impl_.SeekToLast(); }
31
0
  void Seek(const Slice& target) override { impl_.Seek(target); }
32
0
  void SeekForPrev(const Slice& target) override { impl_.SeekForPrev(target); }
33
0
  void Next() override { impl_.Next(); }
34
0
  void Prev() override { impl_.Prev(); }
35
0
  Slice key() const override { return impl_.key(); }
36
0
  Status status() const override { return impl_.status(); }
37
38
0
  const IteratorAttributeGroups& attribute_groups() const override {
39
0
    assert(Valid());
40
0
    return attribute_groups_;
41
0
  }
42
43
0
  void Reset() { attribute_groups_.clear(); }
44
45
0
  bool PrepareValue() override { return impl_.PrepareValue(); }
46
47
 private:
48
  class ResetFunc {
49
   public:
50
0
    explicit ResetFunc(AttributeGroupIteratorImpl* iter) : iter_(iter) {}
51
52
0
    void operator()() const {
53
0
      assert(iter_);
54
0
      iter_->Reset();
55
0
    }
56
57
   private:
58
    AttributeGroupIteratorImpl* iter_;
59
  };
60
61
  class PopulateFunc {
62
   public:
63
0
    explicit PopulateFunc(AttributeGroupIteratorImpl* iter) : iter_(iter) {}
64
65
0
    void operator()(const autovector<MultiCfIteratorInfo>& items) const {
66
0
      assert(iter_);
67
0
      iter_->AddToAttributeGroups(items);
68
0
    }
69
70
   private:
71
    AttributeGroupIteratorImpl* iter_;
72
  };
73
74
  MultiCfIteratorImpl<ResetFunc, PopulateFunc> impl_;
75
  IteratorAttributeGroups attribute_groups_;
76
  void AddToAttributeGroups(const autovector<MultiCfIteratorInfo>& items);
77
};
78
79
class EmptyAttributeGroupIterator : public AttributeGroupIterator {
80
 public:
81
0
  explicit EmptyAttributeGroupIterator(const Status& s) : status_(s) {}
82
0
  bool Valid() const override { return false; }
83
0
  void Seek(const Slice& /*target*/) override {}
84
0
  void SeekForPrev(const Slice& /*target*/) override {}
85
0
  void SeekToFirst() override {}
86
0
  void SeekToLast() override {}
87
0
  void Next() override { assert(false); }
88
0
  void Prev() override { assert(false); }
89
0
  Slice key() const override {
90
0
    assert(false);
91
0
    return Slice();
92
0
  }
93
0
  Status status() const override { return status_; }
94
95
0
  const IteratorAttributeGroups& attribute_groups() const override {
96
0
    return kNoIteratorAttributeGroups;
97
0
  }
98
99
 private:
100
  Status status_;
101
};
102
103
inline std::unique_ptr<AttributeGroupIterator> NewAttributeGroupErrorIterator(
104
0
    const Status& status) {
105
0
  return std::make_unique<EmptyAttributeGroupIterator>(status);
106
0
}
107
108
}  // namespace ROCKSDB_NAMESPACE