/Users/deen/code/yugabyte-db/src/yb/docdb/doc_operation.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #ifndef YB_DOCDB_DOC_OPERATION_H_ |
15 | | #define YB_DOCDB_DOC_OPERATION_H_ |
16 | | |
17 | | #include <boost/container/small_vector.hpp> |
18 | | |
19 | | #include "yb/common/read_hybrid_time.h" |
20 | | #include "yb/common/transaction.pb.h" |
21 | | |
22 | | #include "yb/docdb/docdb_fwd.h" |
23 | | |
24 | | #include "yb/util/monotime.h" |
25 | | #include "yb/util/ref_cnt_buffer.h" |
26 | | |
27 | | namespace yb { |
28 | | namespace docdb { |
29 | | |
30 | | struct DocOperationApplyData { |
31 | | DocWriteBatch* doc_write_batch; |
32 | | CoarseTimePoint deadline; |
33 | | ReadHybridTime read_time; |
34 | | HybridTime* restart_read_ht; |
35 | | |
36 | 0 | std::string ToString() const { |
37 | 0 | return YB_STRUCT_TO_STRING(deadline, read_time, restart_read_ht); |
38 | 0 | } |
39 | | }; |
40 | | |
41 | | // When specifiying the parent key, the constant -1 is used for the subkey index. |
42 | | const int kNilSubkeyIndex = -1; |
43 | | |
44 | | typedef boost::container::small_vector_base<RefCntPrefix> DocPathsToLock; |
45 | | |
46 | | YB_DEFINE_ENUM(GetDocPathsMode, (kLock)(kIntents)); |
47 | | YB_DEFINE_ENUM(DocOperationType, |
48 | | (PGSQL_WRITE_OPERATION)(QL_WRITE_OPERATION)(REDIS_WRITE_OPERATION)); |
49 | | |
50 | | class DocOperation { |
51 | | public: |
52 | | typedef DocOperationType Type; |
53 | | |
54 | 6.56M | virtual ~DocOperation() {} |
55 | | |
56 | | // Does the operation require a read snapshot to be taken before being applied? If so, a |
57 | | // clean snapshot hybrid_time will be supplied when Apply() is called. For example, |
58 | | // QLWriteOperation for a DML with a "... IF <condition> ..." clause needs to read the row to |
59 | | // evaluate the condition before the write and needs a read snapshot for a consistent read. |
60 | | virtual bool RequireReadSnapshot() const = 0; |
61 | | |
62 | | // Returns doc paths for this operation and isolation level this operation. |
63 | | // Doc paths are added to the end of paths, i.e. paths content is not cleared before it. |
64 | | // |
65 | | // Returned doc paths are controlled by mode argument: |
66 | | // kLock - paths should be locked for this operation. |
67 | | // kIntents - paths that should be used when writing intents, i.e. for conflict resolution. |
68 | | virtual CHECKED_STATUS GetDocPaths( |
69 | | GetDocPathsMode mode, DocPathsToLock *paths, IsolationLevel *level) const = 0; |
70 | | |
71 | | virtual CHECKED_STATUS Apply(const DocOperationApplyData& data) = 0; |
72 | | virtual Type OpType() = 0; |
73 | | virtual void ClearResponse() = 0; |
74 | | |
75 | | virtual std::string ToString() const = 0; |
76 | | }; |
77 | | |
78 | | template <DocOperationType OperationType, class RequestPB> |
79 | | class DocOperationBase : public DocOperation { |
80 | | public: |
81 | 6.55M | explicit DocOperationBase(std::reference_wrapper<const RequestPB> request) : request_(request) {} _ZN2yb5docdb16DocOperationBaseILNS0_16DocOperationTypeE2ENS_19RedisWriteRequestPBEEC2ENSt3__117reference_wrapperIKS3_EE Line | Count | Source | 81 | 61.5k | explicit DocOperationBase(std::reference_wrapper<const RequestPB> request) : request_(request) {} |
_ZN2yb5docdb16DocOperationBaseILNS0_16DocOperationTypeE0ENS_19PgsqlWriteRequestPBEEC2ENSt3__117reference_wrapperIKS3_EE Line | Count | Source | 81 | 3.10M | explicit DocOperationBase(std::reference_wrapper<const RequestPB> request) : request_(request) {} |
_ZN2yb5docdb16DocOperationBaseILNS0_16DocOperationTypeE1ENS_16QLWriteRequestPBEEC2ENSt3__117reference_wrapperIKS3_EE Line | Count | Source | 81 | 3.38M | explicit DocOperationBase(std::reference_wrapper<const RequestPB> request) : request_(request) {} |
|
82 | | |
83 | 30 | Type OpType() override { |
84 | 30 | return OperationType; |
85 | 30 | } Unexecuted instantiation: _ZN2yb5docdb16DocOperationBaseILNS0_16DocOperationTypeE2ENS_19RedisWriteRequestPBEE6OpTypeEv Unexecuted instantiation: _ZN2yb5docdb16DocOperationBaseILNS0_16DocOperationTypeE0ENS_19PgsqlWriteRequestPBEE6OpTypeEv _ZN2yb5docdb16DocOperationBaseILNS0_16DocOperationTypeE1ENS_16QLWriteRequestPBEE6OpTypeEv Line | Count | Source | 83 | 30 | Type OpType() override { | 84 | 30 | return OperationType; | 85 | 30 | } |
|
86 | | |
87 | 0 | std::string ToString() const override { |
88 | 0 | return Format("$0 { request: $1 }", OperationType, request_); |
89 | 0 | } Unexecuted instantiation: _ZNK2yb5docdb16DocOperationBaseILNS0_16DocOperationTypeE2ENS_19RedisWriteRequestPBEE8ToStringEv Unexecuted instantiation: _ZNK2yb5docdb16DocOperationBaseILNS0_16DocOperationTypeE0ENS_19PgsqlWriteRequestPBEE8ToStringEv Unexecuted instantiation: _ZNK2yb5docdb16DocOperationBaseILNS0_16DocOperationTypeE1ENS_16QLWriteRequestPBEE8ToStringEv |
90 | | |
91 | | protected: |
92 | | const RequestPB& request_; |
93 | | }; |
94 | | |
95 | | typedef std::vector<std::unique_ptr<DocOperation>> DocOperations; |
96 | | |
97 | | } // namespace docdb |
98 | | } // namespace yb |
99 | | |
100 | | #endif // YB_DOCDB_DOC_OPERATION_H_ |