]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/table/get_context.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / table / get_context.h
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 #pragma once
7 #include <string>
8 #include "db/merge_context.h"
9 #include "db/range_del_aggregator.h"
10 #include "rocksdb/env.h"
11 #include "rocksdb/types.h"
12 #include "table/block.h"
13
14 namespace rocksdb {
15 class MergeContext;
16 class PinnedIteratorsManager;
17
18 class GetContext {
19 public:
20 enum GetState {
21 kNotFound,
22 kFound,
23 kDeleted,
24 kCorrupt,
25 kMerge // saver contains the current merge result (the operands)
26 };
27
28 GetContext(const Comparator* ucmp, const MergeOperator* merge_operator,
29 Logger* logger, Statistics* statistics, GetState init_state,
30 const Slice& user_key, PinnableSlice* value, bool* value_found,
31 MergeContext* merge_context, RangeDelAggregator* range_del_agg,
32 Env* env, SequenceNumber* seq = nullptr,
33 PinnedIteratorsManager* _pinned_iters_mgr = nullptr);
34
35 void MarkKeyMayExist();
36
37 // Records this key, value, and any meta-data (such as sequence number and
38 // state) into this GetContext.
39 //
40 // Returns True if more keys need to be read (due to merges) or
41 // False if the complete value has been found.
42 bool SaveValue(const ParsedInternalKey& parsed_key, const Slice& value,
43 Cleanable* value_pinner = nullptr);
44
45 // Simplified version of the previous function. Should only be used when we
46 // know that the operation is a Put.
47 void SaveValue(const Slice& value, SequenceNumber seq);
48
49 GetState State() const { return state_; }
50
51 RangeDelAggregator* range_del_agg() { return range_del_agg_; }
52
53 PinnedIteratorsManager* pinned_iters_mgr() { return pinned_iters_mgr_; }
54
55 // If a non-null string is passed, all the SaveValue calls will be
56 // logged into the string. The operations can then be replayed on
57 // another GetContext with replayGetContextLog.
58 void SetReplayLog(std::string* replay_log) { replay_log_ = replay_log; }
59
60 // Do we need to fetch the SequenceNumber for this key?
61 bool NeedToReadSequence() const { return (seq_ != nullptr); }
62
63 private:
64 const Comparator* ucmp_;
65 const MergeOperator* merge_operator_;
66 // the merge operations encountered;
67 Logger* logger_;
68 Statistics* statistics_;
69
70 GetState state_;
71 Slice user_key_;
72 PinnableSlice* pinnable_val_;
73 bool* value_found_; // Is value set correctly? Used by KeyMayExist
74 MergeContext* merge_context_;
75 RangeDelAggregator* range_del_agg_;
76 Env* env_;
77 // If a key is found, seq_ will be set to the SequenceNumber of most recent
78 // write to the key or kMaxSequenceNumber if unknown
79 SequenceNumber* seq_;
80 std::string* replay_log_;
81 // Used to temporarily pin blocks when state_ == GetContext::kMerge
82 PinnedIteratorsManager* pinned_iters_mgr_;
83 };
84
85 void replayGetContextLog(const Slice& replay_log, const Slice& user_key,
86 GetContext* get_context);
87
88 } // namespace rocksdb