]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/util/user_comparator_wrapper.h
bump version to 18.2.2-pve1
[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.
1e59de90 18class UserComparatorWrapper {
494da23a 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)
1e59de90 25 : user_comparator_(user_cmp) {}
20effc67 26
494da23a
TL
27 ~UserComparatorWrapper() = default;
28
29 const Comparator* user_comparator() const { return user_comparator_; }
30
1e59de90 31 int Compare(const Slice& a, const Slice& b) const {
494da23a
TL
32 PERF_COUNTER_ADD(user_key_comparison_count, 1);
33 return user_comparator_->Compare(a, b);
34 }
35
1e59de90 36 bool Equal(const Slice& a, const Slice& b) const {
494da23a
TL
37 PERF_COUNTER_ADD(user_key_comparison_count, 1);
38 return user_comparator_->Equal(a, b);
39 }
40
1e59de90
TL
41 int CompareTimestamp(const Slice& ts1, const Slice& ts2) const {
42 return user_comparator_->CompareTimestamp(ts1, ts2);
494da23a
TL
43 }
44
1e59de90
TL
45 int CompareWithoutTimestamp(const Slice& a, const Slice& b) const {
46 PERF_COUNTER_ADD(user_key_comparison_count, 1);
47 return user_comparator_->CompareWithoutTimestamp(a, b);
20effc67
TL
48 }
49
20effc67 50 int CompareWithoutTimestamp(const Slice& a, bool a_has_ts, const Slice& b,
1e59de90 51 bool b_has_ts) const {
20effc67
TL
52 PERF_COUNTER_ADD(user_key_comparison_count, 1);
53 return user_comparator_->CompareWithoutTimestamp(a, a_has_ts, b, b_has_ts);
54 }
55
1e59de90
TL
56 bool EqualWithoutTimestamp(const Slice& a, const Slice& b) const {
57 return user_comparator_->EqualWithoutTimestamp(a, b);
58 }
59
494da23a
TL
60 private:
61 const Comparator* user_comparator_;
62};
63
f67539c2 64} // namespace ROCKSDB_NAMESPACE