]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/util/user_comparator_wrapper.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / util / user_comparator_wrapper.h
CommitLineData
494da23a
TL
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// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
6// Use of this source code is governed by a BSD-style license that can be
7// found in the LICENSE file. See the AUTHORS file for names of contributors.
8
9#pragma once
10
11#include "monitoring/perf_context_imp.h"
12#include "rocksdb/comparator.h"
13
f67539c2 14namespace ROCKSDB_NAMESPACE {
494da23a
TL
15
16// Wrapper of user comparator, with auto increment to
17// perf_context.user_key_comparison_count.
18class UserComparatorWrapper final : public Comparator {
19 public:
20effc67
TL
20 // `UserComparatorWrapper`s constructed with the default constructor are not
21 // usable and will segfault on any attempt to use them for comparisons.
22 UserComparatorWrapper() : user_comparator_(nullptr) {}
23
494da23a 24 explicit UserComparatorWrapper(const Comparator* const user_cmp)
20effc67
TL
25 : Comparator(user_cmp->timestamp_size()), user_comparator_(user_cmp) {}
26
494da23a
TL
27 ~UserComparatorWrapper() = default;
28
29 const Comparator* user_comparator() const { return user_comparator_; }
30
31 int Compare(const Slice& a, const Slice& b) const override {
32 PERF_COUNTER_ADD(user_key_comparison_count, 1);
33 return user_comparator_->Compare(a, b);
34 }
35
36 bool Equal(const Slice& a, const Slice& b) const override {
37 PERF_COUNTER_ADD(user_key_comparison_count, 1);
38 return user_comparator_->Equal(a, b);
39 }
40
41 const char* Name() const override { return user_comparator_->Name(); }
42
43 void FindShortestSeparator(std::string* start,
44 const Slice& limit) const override {
45 return user_comparator_->FindShortestSeparator(start, limit);
46 }
47
48 void FindShortSuccessor(std::string* key) const override {
49 return user_comparator_->FindShortSuccessor(key);
50 }
51
52 const Comparator* GetRootComparator() const override {
53 return user_comparator_->GetRootComparator();
54 }
55
56 bool IsSameLengthImmediateSuccessor(const Slice& s,
57 const Slice& t) const override {
58 return user_comparator_->IsSameLengthImmediateSuccessor(s, t);
59 }
60
61 bool CanKeysWithDifferentByteContentsBeEqual() const override {
62 return user_comparator_->CanKeysWithDifferentByteContentsBeEqual();
63 }
64
20effc67
TL
65 int CompareTimestamp(const Slice& ts1, const Slice& ts2) const override {
66 return user_comparator_->CompareTimestamp(ts1, ts2);
67 }
68
69 using Comparator::CompareWithoutTimestamp;
70 int CompareWithoutTimestamp(const Slice& a, bool a_has_ts, const Slice& b,
71 bool b_has_ts) const override {
72 PERF_COUNTER_ADD(user_key_comparison_count, 1);
73 return user_comparator_->CompareWithoutTimestamp(a, a_has_ts, b, b_has_ts);
74 }
75
494da23a
TL
76 private:
77 const Comparator* user_comparator_;
78};
79
f67539c2 80} // namespace ROCKSDB_NAMESPACE