/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/merge_context.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 the BSD-style license found in the |
3 | | // LICENSE file in the root directory of this source tree. An additional grant |
4 | | // of patent rights can be found in the PATENTS file in the same directory. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | #pragma once |
21 | | |
22 | | #include <deque> |
23 | | #include <string> |
24 | | |
25 | | #include "yb/util/slice.h" |
26 | | |
27 | | namespace rocksdb { |
28 | | |
29 | | const std::deque<std::string> empty_operand_list; |
30 | | |
31 | | // The merge context for merging a user key. |
32 | | // When doing a Get(), DB will create such a class and pass it when |
33 | | // issuing Get() operation to memtables and version_set. The operands |
34 | | // will be fetched from the context when issuing partial of full merge. |
35 | | class MergeContext { |
36 | | public: |
37 | | // Clear all the operands |
38 | 14.7M | void Clear() { |
39 | 14.7M | if (operand_list) { |
40 | 0 | operand_list->clear(); |
41 | 0 | } |
42 | 14.7M | } |
43 | | // Replace all operands with merge_result, which are expected to be the |
44 | | // merge result of them. |
45 | 0 | void PushPartialMergeResult(std::string&& merge_result) { |
46 | 0 | assert (operand_list); |
47 | 0 | operand_list->clear(); |
48 | 0 | operand_list->push_front(std::move(merge_result)); |
49 | 0 | } |
50 | | // Push a merge operand |
51 | 44.7k | void PushOperand(const Slice& operand_slice) { |
52 | 44.7k | Initialize(); |
53 | 44.7k | operand_list->push_front(operand_slice.ToString()); |
54 | 44.7k | } |
55 | | // return total number of operands in the list |
56 | 80 | size_t GetNumOperands() const { |
57 | 80 | if (!operand_list) { |
58 | 75 | return 0; |
59 | 75 | } |
60 | 5 | return operand_list->size(); |
61 | 5 | } |
62 | | // Get the operand at the index. |
63 | 0 | Slice GetOperand(int index) const { |
64 | 0 | assert (operand_list); |
65 | 0 | return (*operand_list)[index]; |
66 | 0 | } |
67 | | // Return all the operands. |
68 | 1.85k | const std::deque<std::string>& GetOperands() const { |
69 | 1.85k | if (!operand_list) { |
70 | 0 | return empty_operand_list; |
71 | 0 | } |
72 | 1.85k | return *operand_list; |
73 | 1.85k | } |
74 | | private: |
75 | 44.7k | void Initialize() { |
76 | 44.7k | if (!operand_list) { |
77 | 1.87k | operand_list.reset(new std::deque<std::string>()); |
78 | 1.87k | } |
79 | 44.7k | } |
80 | | |
81 | | std::unique_ptr<std::deque<std::string>> operand_list; |
82 | | }; |
83 | | |
84 | | } // namespace rocksdb |