YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/tablet/write_query.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_TABLET_WRITE_QUERY_H
15
#define YB_TABLET_WRITE_QUERY_H
16
17
#include "yb/client/client_fwd.h"
18
19
#include "yb/docdb/docdb_fwd.h"
20
#include "yb/docdb/docdb.h"
21
#include "yb/docdb/doc_operation.h"
22
#include "yb/docdb/lock_batch.h"
23
24
#include "yb/tablet/tablet_fwd.h"
25
26
#include "yb/tserver/tserver.fwd.h"
27
28
#include "yb/util/operation_counter.h"
29
30
namespace yb {
31
namespace tablet {
32
33
class WriteQuery {
34
 public:
35
  WriteQuery(int64_t term,
36
             CoarseTimePoint deadline,
37
             WriteQueryContext* context,
38
             Tablet* tablet,
39
             tserver::WriteResponsePB *response = nullptr,
40
             docdb::OperationKind kind = docdb::OperationKind::kWrite);
41
42
  ~WriteQuery();
43
44
3.53M
  WriteOperation& operation() {
45
3.53M
    return *operation_;
46
3.53M
  }
47
48
  WritePB& request();
49
50
  // Returns the prepared response to the client that will be sent when this
51
  // transaction is completed, if this transaction was started by a client.
52
0
  tserver::WriteResponsePB* response() {
53
0
    return response_;
54
0
  }
55
56
  static void Execute(std::unique_ptr<WriteQuery> query);
57
58
  // The QL write operations that return rowblocks that need to be returned as RPC sidecars
59
  // after the transaction completes.
60
1.26M
  std::vector<std::unique_ptr<docdb::QLWriteOperation>>* ql_write_ops() {
61
1.26M
    return &ql_write_ops_;
62
1.26M
  }
63
64
  // Returns PGSQL write operations.
65
  // TODO(neil) These ops must report number of rows that was updated, deleted, or inserted.
66
1.73M
  std::vector<std::unique_ptr<docdb::PgsqlWriteOperation>>* pgsql_write_ops() {
67
1.73M
    return &pgsql_write_ops_;
68
1.73M
  }
69
70
1.73M
  docdb::OperationKind kind() const {
71
1.73M
    return kind_;
72
1.73M
  }
73
74
  void AdjustYsqlQueryTransactionality(size_t ysql_batch_size);
75
76
1.33M
  HybridTime restart_read_ht() const {
77
1.33M
    return restart_read_ht_;
78
1.33M
  }
79
80
5.14M
  CoarseTimePoint deadline() const {
81
5.14M
    return deadline_;
82
5.14M
  }
83
84
0
  docdb::DocOperations& doc_ops() {
85
0
    return doc_ops_;
86
0
  }
87
88
1.75M
  static void StartSynchronization(std::unique_ptr<WriteQuery> query, const Status& status) {
89
    // We release here, because DoStartSynchronization takes ownership on this.
90
1.75M
    query.release()->DoStartSynchronization(status);
91
1.75M
  }
92
93
1.74M
  void UseSubmitToken(ScopedRWOperation&& token) {
94
1.74M
    submit_token_ = std::move(token);
95
1.74M
  }
96
97
  void set_client_request(std::reference_wrapper<const tserver::WriteRequestPB> req);
98
99
  void set_client_request(std::unique_ptr<tserver::WriteRequestPB> req);
100
101
7.77k
  void set_read_time(const ReadHybridTime& read_time) {
102
7.77k
    read_time_ = read_time;
103
7.77k
  }
104
105
  template <class Callback>
106
1.65M
  void set_callback(Callback&& callback) {
107
1.65M
    callback_ = std::forward<Callback>(callback);
108
1.65M
  }
_ZN2yb6tablet10WriteQuery12set_callbackIZNS0_36MakeLatchOperationCompletionCallbackIPNS_14CountDownLatchEPNS_7tserver15WriteResponsePBEEEDaT_T0_EUlRKNS_6StatusEE_EEvOSA_
Line
Count
Source
106
4.01k
  void set_callback(Callback&& callback) {
107
4.01k
    callback_ = std::forward<Callback>(callback);
108
4.01k
  }
Unexecuted instantiation: _ZN2yb6tablet10WriteQuery12set_callbackIZNS_6master25MasterSnapshotCoordinator4Impl13CleanupObjectIN5boost11multi_index21multi_index_containerINSt3__110unique_ptrINS3_13SnapshotStateENSA_14default_deleteISC_EEEENS8_10indexed_byINS8_13hashed_uniqueINS8_13const_mem_funISC_RKNS_17StronglyTypedUuidINS_17TxnSnapshotId_TagEEEXadL_ZNKSC_2idEvEEEEN4mpl_2naESQ_SQ_EENS8_18ordered_non_uniqueINS8_3tagINS5_11ScheduleTagESQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_EENS8_13composite_keyISC_NSI_ISC_RKNSJ_INS_22SnapshotScheduleId_TagEEEXadL_ZNKSC_11schedule_idEvEEEENSI_ISC_NS_10HybridTimeEXadL_ZNKSC_20snapshot_hybrid_timeEvEEEENS7_6tuples9null_typeES15_S15_S15_S15_S15_S15_S15_EESQ_EESQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_EENSA_9allocatorISF_EEEESL_EEvxT0_RKT_RKNS_6ResultINS_5docdb8KeyBytesEEEEUlRKNS_6StatusEE_EEvOS1D_
Unexecuted instantiation: _ZN2yb6tablet10WriteQuery12set_callbackINSt3__18functionIFvRKNS_6StatusEEEEEEvOT_
Unexecuted instantiation: _ZN2yb6tablet10WriteQuery12set_callbackIZNS_6master25MasterSnapshotCoordinator4Impl13CleanupObjectIN5boost11multi_index21multi_index_containerINSt3__110unique_ptrINS3_21SnapshotScheduleStateENSA_14default_deleteISC_EEEENS8_10indexed_byINS8_13hashed_uniqueINS8_13const_mem_funISC_RKNS_17StronglyTypedUuidINS_22SnapshotScheduleId_TagEEEXadL_ZNKSC_2idEvEEEEN4mpl_2naESQ_SQ_EESQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_SQ_EENSA_9allocatorISF_EEEESL_EEvxT0_RKT_RKNS_6ResultINS_5docdb8KeyBytesEEEEUlRKNS_6StatusEE_EEvOSX_
_ZN2yb6tablet10WriteQuery12set_callbackIZNS0_36MakeLatchOperationCompletionCallbackINSt3__110shared_ptrINS_14CountDownLatchEEENS5_INS_7tserver15WriteResponsePBEEEEEDaT_T0_EUlRKNS_6StatusEE_EEvOSC_
Line
Count
Source
106
163k
  void set_callback(Callback&& callback) {
107
163k
    callback_ = std::forward<Callback>(callback);
108
163k
  }
read_query.cc:_ZN2yb6tablet10WriteQuery12set_callbackIZNS_7tserver12_GLOBAL__N_19ReadQuery9DoPerformEvE3$_0EEvOT_
Line
Count
Source
106
140k
  void set_callback(Callback&& callback) {
107
140k
    callback_ = std::forward<Callback>(callback);
108
140k
  }
_ZN2yb6tablet10WriteQuery12set_callbackINS_7tserver28WriteQueryCompletionCallbackEEEvOT_
Line
Count
Source
106
1.34M
  void set_callback(Callback&& callback) {
107
1.34M
    callback_ = std::forward<Callback>(callback);
108
1.34M
  }
109
110
  // Cancel query even before sending underlying operation to the Raft.
111
  void Cancel(const Status& status);
112
113
0
  const ReadHybridTime& read_time() const {
114
0
    return read_time_;
115
0
  }
116
117
1
  const tserver::WriteRequestPB* client_request() {
118
1
    return client_request_;
119
1
  }
120
121
  std::unique_ptr<WriteOperation> PrepareSubmit();
122
123
 private:
124
  enum class ExecuteMode;
125
126
  // Actually starts the Mvcc transaction and assigns a hybrid_time to this transaction.
127
  void DoStartSynchronization(const Status& status);
128
129
  void Release();
130
131
  void Finished(WriteOperation* operation, const Status& status);
132
133
  void Complete(const Status& status);
134
135
  CHECKED_STATUS InitExecute(ExecuteMode mode);
136
137
  void ExecuteDone(const Status& status);
138
139
  Result<bool> PrepareExecute();
140
  CHECKED_STATUS DoExecute();
141
142
  void NonTransactionalConflictsResolved(HybridTime now, HybridTime result);
143
144
  void TransactionalConflictsResolved();
145
146
  CHECKED_STATUS DoTransactionalConflictsResolved();
147
148
  void CompleteExecute();
149
150
  CHECKED_STATUS DoCompleteExecute();
151
152
  Result<bool> SimplePrepareExecute();
153
  Result<bool> RedisPrepareExecute();
154
  Result<bool> CqlPrepareExecute();
155
  Result<bool> PgsqlPrepareExecute();
156
157
  void SimpleExecuteDone(const Status& status);
158
  void RedisExecuteDone(const Status& status);
159
  void CqlExecuteDone(const Status& status);
160
  void PgsqlExecuteDone(const Status& status);
161
162
  using IndexOps = std::vector<std::pair<
163
      std::shared_ptr<client::YBqlWriteOp>, docdb::QLWriteOperation*>>;
164
  void UpdateQLIndexes();
165
  void UpdateQLIndexesFlushed(
166
      const client::YBSessionPtr& session, const client::YBTransactionPtr& txn,
167
      const IndexOps& index_ops, client::FlushStatus* flush_status);
168
169
  void CompleteQLWriteBatch(const Status& status);
170
171
  Tablet& tablet() const;
172
173
  std::unique_ptr<WriteOperation> operation_;
174
175
  // The QL write operations that return rowblocks that need to be returned as RPC sidecars
176
  // after the operation completes.
177
  std::vector<std::unique_ptr<docdb::QLWriteOperation>> ql_write_ops_;
178
179
  // The PGSQL write operations that return rowblocks that need to be returned as RPC sidecars
180
  // after the transaction completes.
181
  std::vector<std::unique_ptr<docdb::PgsqlWriteOperation>> pgsql_write_ops_;
182
183
  // Store the ids that have been locked for DocDB operation. They need to be released on commit
184
  // or if an error happens.
185
  docdb::LockBatch docdb_locks_;
186
187
  // True if we know that this operation is on a transactional table so make sure we go through the
188
  // transactional codepath.
189
  bool force_txn_path_ = false;
190
191
  const int64_t term_;
192
  ScopedRWOperation submit_token_;
193
  const CoarseTimePoint deadline_;
194
  WriteQueryContext* const context_;
195
196
  // Pointers to the rpc context, request and response, lifecycle
197
  // is managed by the rpc subsystem. These pointers maybe nullptr if the
198
  // operation was not initiated by an RPC call.
199
  const tserver::WriteRequestPB* client_request_ = nullptr;
200
  ReadHybridTime read_time_;
201
  bool allow_immediate_read_restart_ = false;
202
  std::unique_ptr<tserver::WriteRequestPB> client_request_holder_;
203
  tserver::WriteResponsePB* response_;
204
205
  docdb::OperationKind kind_;
206
207
  // this transaction's start time
208
  CoarseTimePoint start_time_;
209
210
  HybridTime restart_read_ht_;
211
212
  docdb::DocOperations doc_ops_;
213
214
  std::function<void(const Status&)> callback_;
215
216
  ScopedRWOperation scoped_read_operation_;
217
  ExecuteMode execute_mode_;
218
  IsolationLevel isolation_level_;
219
  docdb::PrepareDocWriteOperationResult prepare_result_;
220
  RequestScope request_scope_;
221
  std::unique_ptr<WriteQuery> self_; // Keep self while Execute is performed.
222
};
223
224
}  // namespace tablet
225
}  // namespace yb
226
227
#endif  // YB_TABLET_WRITE_QUERY_H