/src/rocksdb/util/user_comparator_wrapper.h
Line | Count | Source |
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 | | |
14 | | namespace ROCKSDB_NAMESPACE { |
15 | | |
16 | | // Wrapper of user comparator, with auto increment to |
17 | | // perf_context.user_key_comparison_count. |
18 | | class UserComparatorWrapper { |
19 | | public: |
20 | | // `UserComparatorWrapper`s constructed with the default constructor are not |
21 | | // usable and will segfault on any attempt to use them for comparisons. |
22 | 388k | UserComparatorWrapper() : user_comparator_(nullptr) {} |
23 | | |
24 | | explicit UserComparatorWrapper(const Comparator* const user_cmp) |
25 | 1.41M | : user_comparator_(user_cmp) {} |
26 | | |
27 | | ~UserComparatorWrapper() = default; |
28 | | |
29 | 55.5M | const Comparator* user_comparator() const { return user_comparator_; } |
30 | | |
31 | 825M | int Compare(const Slice& a, const Slice& b) const { |
32 | 825M | PERF_COUNTER_ADD(user_key_comparison_count, 1); |
33 | 825M | return user_comparator_->Compare(a, b); |
34 | 825M | } |
35 | | |
36 | 0 | bool Equal(const Slice& a, const Slice& b) const { |
37 | 0 | PERF_COUNTER_ADD(user_key_comparison_count, 1); |
38 | 0 | return user_comparator_->Equal(a, b); |
39 | 0 | } |
40 | | |
41 | 0 | int CompareTimestamp(const Slice& ts1, const Slice& ts2) const { |
42 | 0 | return user_comparator_->CompareTimestamp(ts1, ts2); |
43 | 0 | } |
44 | | |
45 | 46.5k | int CompareWithoutTimestamp(const Slice& a, const Slice& b) const { |
46 | 46.5k | PERF_COUNTER_ADD(user_key_comparison_count, 1); |
47 | 46.5k | return user_comparator_->CompareWithoutTimestamp(a, b); |
48 | 46.5k | } |
49 | | |
50 | | int CompareWithoutTimestamp(const Slice& a, bool a_has_ts, const Slice& b, |
51 | 0 | bool b_has_ts) const { |
52 | 0 | PERF_COUNTER_ADD(user_key_comparison_count, 1); |
53 | 0 | return user_comparator_->CompareWithoutTimestamp(a, a_has_ts, b, b_has_ts); |
54 | 0 | } |
55 | | |
56 | 13.1k | bool EqualWithoutTimestamp(const Slice& a, const Slice& b) const { |
57 | 13.1k | return user_comparator_->EqualWithoutTimestamp(a, b); |
58 | 13.1k | } |
59 | | |
60 | | private: |
61 | | const Comparator* user_comparator_; |
62 | | }; |
63 | | |
64 | | } // namespace ROCKSDB_NAMESPACE |