/src/rocksdb/utilities/merge_operators.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. |
2 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
3 | | // Use of this source code is governed by a BSD-style license that can be |
4 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
5 | | |
6 | | #include "utilities/merge_operators.h" |
7 | | |
8 | | #include <memory> |
9 | | |
10 | | #include "rocksdb/merge_operator.h" |
11 | | #include "rocksdb/options.h" |
12 | | #include "rocksdb/utilities/customizable_util.h" |
13 | | #include "rocksdb/utilities/object_registry.h" |
14 | | #include "utilities/merge_operators/bytesxor.h" |
15 | | #include "utilities/merge_operators/max_operator.h" |
16 | | #include "utilities/merge_operators/put_operator.h" |
17 | | #include "utilities/merge_operators/sortlist.h" |
18 | | #include "utilities/merge_operators/string_append/stringappend.h" |
19 | | #include "utilities/merge_operators/string_append/stringappend2.h" |
20 | | #include "utilities/merge_operators/uint64add.h" |
21 | | |
22 | | namespace ROCKSDB_NAMESPACE { |
23 | | static int RegisterBuiltinMergeOperators(ObjectLibrary& library, |
24 | 2 | const std::string& /*arg*/) { |
25 | 2 | size_t num_types; |
26 | 2 | library.AddFactory<MergeOperator>( |
27 | 2 | ObjectLibrary::PatternEntry(StringAppendOperator::kClassName()) |
28 | 2 | .AnotherName(StringAppendOperator::kNickName()), |
29 | 2 | [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard, |
30 | 2 | std::string* /*errmsg*/) { |
31 | 0 | guard->reset(new StringAppendOperator(",")); |
32 | 0 | return guard->get(); |
33 | 0 | }); |
34 | 2 | library.AddFactory<MergeOperator>( |
35 | 2 | ObjectLibrary::PatternEntry(StringAppendTESTOperator::kClassName()) |
36 | 2 | .AnotherName(StringAppendTESTOperator::kNickName()), |
37 | 2 | [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard, |
38 | 2 | std::string* /*errmsg*/) { |
39 | 0 | guard->reset(new StringAppendTESTOperator(",")); |
40 | 0 | return guard->get(); |
41 | 0 | }); |
42 | 2 | library.AddFactory<MergeOperator>( |
43 | 2 | ObjectLibrary::PatternEntry(SortList::kClassName()) |
44 | 2 | .AnotherName(SortList::kNickName()), |
45 | 2 | [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard, |
46 | 2 | std::string* /*errmsg*/) { |
47 | 0 | guard->reset(new SortList()); |
48 | 0 | return guard->get(); |
49 | 0 | }); |
50 | 2 | library.AddFactory<MergeOperator>( |
51 | 2 | ObjectLibrary::PatternEntry(BytesXOROperator::kClassName()) |
52 | 2 | .AnotherName(BytesXOROperator::kNickName()), |
53 | 2 | [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard, |
54 | 2 | std::string* /*errmsg*/) { |
55 | 0 | guard->reset(new BytesXOROperator()); |
56 | 0 | return guard->get(); |
57 | 0 | }); |
58 | 2 | library.AddFactory<MergeOperator>( |
59 | 2 | ObjectLibrary::PatternEntry(UInt64AddOperator::kClassName()) |
60 | 2 | .AnotherName(UInt64AddOperator::kNickName()), |
61 | 2 | [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard, |
62 | 2 | std::string* /*errmsg*/) { |
63 | 0 | guard->reset(new UInt64AddOperator()); |
64 | 0 | return guard->get(); |
65 | 0 | }); |
66 | 2 | library.AddFactory<MergeOperator>( |
67 | 2 | ObjectLibrary::PatternEntry(MaxOperator::kClassName()) |
68 | 2 | .AnotherName(MaxOperator::kNickName()), |
69 | 2 | [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard, |
70 | 2 | std::string* /*errmsg*/) { |
71 | 0 | guard->reset(new MaxOperator()); |
72 | 0 | return guard->get(); |
73 | 0 | }); |
74 | 2 | library.AddFactory<MergeOperator>( |
75 | 2 | ObjectLibrary::PatternEntry(PutOperatorV2::kClassName()) |
76 | 2 | .AnotherName(PutOperatorV2::kNickName()), |
77 | 2 | [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard, |
78 | 2 | std::string* /*errmsg*/) { |
79 | 0 | guard->reset(new PutOperatorV2()); |
80 | 0 | return guard->get(); |
81 | 0 | }); |
82 | 2 | library.AddFactory<MergeOperator>( |
83 | 2 | ObjectLibrary::PatternEntry(PutOperator::kNickName()), |
84 | 2 | [](const std::string& /*uri*/, std::unique_ptr<MergeOperator>* guard, |
85 | 2 | std::string* /*errmsg*/) { |
86 | 0 | guard->reset(new PutOperator()); |
87 | 0 | return guard->get(); |
88 | 0 | }); |
89 | | |
90 | 2 | return static_cast<int>(library.GetFactoryCount(&num_types)); |
91 | 2 | } |
92 | | |
93 | | Status MergeOperator::CreateFromString(const ConfigOptions& config_options, |
94 | | const std::string& value, |
95 | 12.5k | std::shared_ptr<MergeOperator>* result) { |
96 | 12.5k | static std::once_flag once; |
97 | 12.5k | std::call_once(once, [&]() { |
98 | 2 | RegisterBuiltinMergeOperators(*(ObjectLibrary::Default().get()), ""); |
99 | 2 | }); |
100 | 12.5k | return LoadSharedObject<MergeOperator>(config_options, value, result); |
101 | 12.5k | } |
102 | | |
103 | | std::shared_ptr<MergeOperator> MergeOperators::CreateFromStringId( |
104 | 0 | const std::string& id) { |
105 | 0 | std::shared_ptr<MergeOperator> result; |
106 | 0 | Status s = MergeOperator::CreateFromString(ConfigOptions(), id, &result); |
107 | 0 | if (s.ok()) { |
108 | 0 | return result; |
109 | 0 | } else { |
110 | | // Empty or unknown, just return nullptr |
111 | 0 | return nullptr; |
112 | 0 | } |
113 | 0 | } |
114 | | |
115 | | } // namespace ROCKSDB_NAMESPACE |