/Users/deen/code/yugabyte-db/src/yb/rocksdb/table/get_context.h
Line | Count | Source |
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 | | |
21 | | #pragma once |
22 | | |
23 | | #include <stddef.h> |
24 | | #include <stdint.h> |
25 | | #include <stdio.h> |
26 | | #include <string.h> |
27 | | |
28 | | #include <limits> |
29 | | #include <memory> |
30 | | #include <stack> |
31 | | #include <string> |
32 | | #include <unordered_map> |
33 | | #include <vector> |
34 | | |
35 | | #include "yb/rocksdb/db/dbformat.h" |
36 | | #include "yb/rocksdb/env.h" |
37 | | #include "yb/rocksdb/listener.h" |
38 | | #include "yb/rocksdb/options.h" |
39 | | #include "yb/rocksdb/status.h" |
40 | | #include "yb/rocksdb/types.h" |
41 | | |
42 | | namespace rocksdb { |
43 | | class MergeContext; |
44 | | |
45 | | class GetContext { |
46 | | public: |
47 | | enum GetState { |
48 | | kNotFound, |
49 | | kFound, |
50 | | kDeleted, |
51 | | kCorrupt, |
52 | | kMerge // saver contains the current merge result (the operands) |
53 | | }; |
54 | | |
55 | | GetContext(const Comparator* ucmp, const MergeOperator* merge_operator, |
56 | | Logger* logger, Statistics* statistics, GetState init_state, |
57 | | const Slice& user_key, std::string* ret_value, bool* value_found, |
58 | | MergeContext* merge_context, Env* env, |
59 | | SequenceNumber* seq = nullptr); |
60 | | |
61 | | void MarkKeyMayExist(); |
62 | | |
63 | | // Records this key, value, and any meta-data (such as sequence number and |
64 | | // state) into this GetContext. |
65 | | // |
66 | | // Returns True if more keys need to be read (due to merges) or |
67 | | // False if the complete value has been found. |
68 | | bool SaveValue(const ParsedInternalKey& parsed_key, const Slice& value); |
69 | | |
70 | | // Simplified version of the previous function. Should only be used when we |
71 | | // know that the operation is a Put. |
72 | | void SaveValue(const Slice& value, SequenceNumber seq); |
73 | | |
74 | 9.08M | GetState State() const { return state_; } |
75 | | |
76 | | // If a non-null string is passed, all the SaveValue calls will be |
77 | | // logged into the string. The operations can then be replayed on |
78 | | // another GetContext with replayGetContextLog. |
79 | 16.5M | void SetReplayLog(std::string* replay_log) { replay_log_ = replay_log; } |
80 | | |
81 | | // Do we need to fetch the SequenceNumber for this key? |
82 | 51.2k | bool NeedToReadSequence() const { return (seq_ != nullptr); } |
83 | | |
84 | | private: |
85 | | const Comparator* ucmp_; |
86 | | const MergeOperator* merge_operator_; |
87 | | // the merge operations encountered; |
88 | | Logger* logger_; |
89 | | Statistics* statistics_; |
90 | | |
91 | | GetState state_; |
92 | | Slice user_key_; |
93 | | std::string* value_; |
94 | | bool* value_found_; // Is value set correctly? Used by KeyMayExist |
95 | | MergeContext* merge_context_; |
96 | | Env* env_; |
97 | | // If a key is found, seq_ will be set to the SequenceNumber of most recent |
98 | | // write to the key or kMaxSequenceNumber if unknown |
99 | | SequenceNumber* seq_; |
100 | | std::string* replay_log_; |
101 | | }; |
102 | | |
103 | | void replayGetContextLog(const Slice& replay_log, const Slice& user_key, |
104 | | GetContext* get_context); |
105 | | |
106 | | } // namespace rocksdb |