Coverage Report

Created: 2024-09-08 07:17

/src/rocksdb/db/history_trimming_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
#pragma once
6
7
#include <string>
8
#include <vector>
9
10
#include "db/dbformat.h"
11
#include "rocksdb/iterator.h"
12
#include "rocksdb/slice.h"
13
#include "table/internal_iterator.h"
14
15
namespace ROCKSDB_NAMESPACE {
16
17
class HistoryTrimmingIterator : public InternalIterator {
18
 public:
19
  explicit HistoryTrimmingIterator(InternalIterator* input,
20
                                   const Comparator* cmp, const std::string& ts)
21
0
      : input_(input), filter_ts_(ts), cmp_(cmp) {
22
0
    assert(cmp_->timestamp_size() > 0 && !ts.empty());
23
0
  }
24
25
0
  bool filter() const {
26
0
    if (!input_->Valid()) {
27
0
      return true;
28
0
    }
29
0
    Slice current_ts = ExtractTimestampFromKey(key(), cmp_->timestamp_size());
30
0
    return cmp_->CompareTimestamp(current_ts, Slice(filter_ts_)) <= 0;
31
0
  }
32
33
0
  bool Valid() const override { return input_->Valid(); }
34
35
0
  void SeekToFirst() override {
36
0
    input_->SeekToFirst();
37
0
    while (!filter()) {
38
0
      input_->Next();
39
0
    }
40
0
  }
41
42
0
  void SeekToLast() override {
43
0
    input_->SeekToLast();
44
0
    while (!filter()) {
45
0
      input_->Prev();
46
0
    }
47
0
  }
48
49
0
  void Seek(const Slice& target) override {
50
0
    input_->Seek(target);
51
0
    while (!filter()) {
52
0
      input_->Next();
53
0
    }
54
0
  }
55
56
0
  void SeekForPrev(const Slice& target) override {
57
0
    input_->SeekForPrev(target);
58
0
    while (!filter()) {
59
0
      input_->Prev();
60
0
    }
61
0
  }
62
63
0
  void Next() override {
64
0
    do {
65
0
      input_->Next();
66
0
    } while (!filter());
67
0
  }
68
69
0
  void Prev() override {
70
0
    do {
71
0
      input_->Prev();
72
0
    } while (!filter());
73
0
  }
74
75
0
  Slice key() const override { return input_->key(); }
76
77
0
  Slice value() const override { return input_->value(); }
78
79
0
  Status status() const override { return input_->status(); }
80
81
0
  bool IsKeyPinned() const override { return input_->IsKeyPinned(); }
82
83
0
  bool IsValuePinned() const override { return input_->IsValuePinned(); }
84
85
0
  bool IsDeleteRangeSentinelKey() const override {
86
0
    return input_->IsDeleteRangeSentinelKey();
87
0
  }
88
89
 private:
90
  InternalIterator* input_;
91
  const std::string filter_ts_;
92
  const Comparator* const cmp_;
93
};
94
95
}  // namespace ROCKSDB_NAMESPACE