YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/tablet/operations/operation.h
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
//
18
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
33
#ifndef YB_TABLET_OPERATIONS_OPERATION_H
34
#define YB_TABLET_OPERATIONS_OPERATION_H
35
36
#include <mutex>
37
#include <string>
38
39
#include <boost/optional/optional.hpp>
40
41
#include "yb/common/hybrid_time.h"
42
43
#include "yb/consensus/consensus_fwd.h"
44
#include "yb/consensus/consensus_round.h"
45
#include "yb/consensus/consensus_types.pb.h"
46
47
#include "yb/tablet/tablet_fwd.h"
48
49
#include "yb/util/status_fwd.h"
50
#include "yb/util/locks.h"
51
#include "yb/util/operation_counter.h"
52
#include "yb/util/opid.h"
53
54
namespace yb {
55
56
class Synchronizer;
57
58
namespace tablet {
59
60
using OperationCompletionCallback = std::function<void(const Status&)>;
61
62
YB_DEFINE_ENUM(
63
    OperationType,
64
    ((kWrite, consensus::WRITE_OP))
65
    ((kChangeMetadata, consensus::CHANGE_METADATA_OP))
66
    ((kUpdateTransaction, consensus::UPDATE_TRANSACTION_OP))
67
    ((kSnapshot, consensus::SNAPSHOT_OP))
68
    ((kTruncate, consensus::TRUNCATE_OP))
69
    ((kEmpty, consensus::UNKNOWN_OP))
70
    ((kHistoryCutoff, consensus::HISTORY_CUTOFF_OP))
71
    ((kSplit, consensus::SPLIT_OP)));
72
73
// Base class for transactions.  There are different implementations for different types (Write,
74
// AlterSchema, etc.) OperationDriver implementations use Operations along with Consensus to execute
75
// and replicate operations in a consensus configuration.
76
class Operation {
77
 public:
78
  enum TraceType {
79
    NO_TRACE_TXNS = 0,
80
    TRACE_TXNS = 1
81
  };
82
83
  explicit Operation(OperationType operation_type, Tablet* tablet);
84
85
  // Returns this transaction's type.
86
26.0M
  OperationType operation_type() const { return operation_type_; }
87
88
  // Builds the ReplicateMsg for this transaction.
89
  virtual consensus::ReplicateMsgPtr NewReplicateMsg() = 0;
90
91
  // Executes the prepare phase of this transaction. The actual actions of this phase depend on the
92
  // transaction type, but usually are limited to what can be done without actually changing shared
93
  // data structures (such as the RocksDB memtable) and without side-effects.
94
  virtual CHECKED_STATUS Prepare() = 0;
95
96
  // Applies replicated operation, the actual actions of this phase depend on the
97
  // operation type, but usually this is the method where data-structures are changed.
98
  // Also it should notify callback if necessary.
99
  CHECKED_STATUS Replicated(int64_t leader_term);
100
101
  // Abort operation. Release resources and notify callbacks.
102
  void Aborted(const Status& status, bool was_pending);
103
104
  // Each implementation should have its own ToString() method.
105
  virtual std::string ToString() const;
106
107
  std::string LogPrefix() const;
108
109
1.64M
  void set_preparing_token(ScopedOperation&& preparing_token) {
110
1.64M
    preparing_token_ = std::move(preparing_token);
111
1.64M
  }
112
113
7.79M
  void SubmittedToPreparer() {
114
7.79M
    preparing_token_ = ScopedOperation();
115
7.79M
  }
116
117
  // Returns the request PB associated with this transaction. May be NULL if the transaction's state
118
  // has been reset.
119
0
  virtual const google::protobuf::Message* request() const { return nullptr; }
120
121
  // Sets the ConsensusRound for this transaction, if this transaction is being executed through the
122
  // consensus system.
123
  void set_consensus_round(const scoped_refptr<consensus::ConsensusRound>& consensus_round);
124
125
  // Each subclass should provide a way to update the internal reference to the Message* request, so
126
  // we can avoid copying the request object all the time.
127
  virtual void UpdateRequestFromConsensusRound() = 0;
128
129
  // Returns the ConsensusRound being used, if this transaction is being executed through the
130
  // consensus system or NULL if it's not.
131
42.9M
  consensus::ConsensusRound* consensus_round() {
132
42.9M
    return consensus_round_.get();
133
42.9M
  }
134
135
4
  const consensus::ConsensusRound* consensus_round() const {
136
4
    return consensus_round_.get();
137
4
  }
138
139
57.9M
  Tablet* tablet() const {
140
57.9M
    return tablet_;
141
57.9M
  }
142
143
  virtual void Release();
144
145
0
  void SetTablet(Tablet* tablet) {
146
0
    tablet_ = tablet;
147
0
  }
148
149
  template <class F>
150
  void set_completion_callback(const F& completion_clbk) {
151
    completion_clbk_ = completion_clbk;
152
  }
153
154
  template <class F>
155
3.40M
  void set_completion_callback(F&& completion_clbk) {
156
3.40M
    completion_clbk_ = std::move(completion_clbk);
157
3.40M
  }
Unexecuted instantiation: _ZN2yb6tablet9Operation23set_completion_callbackIZNS_6master25MasterSnapshotCoordinator4Impl12SubmitDeleteERKNS_17StronglyTypedUuidINS_17TxnSnapshotId_TagEEExRKNSt3__110shared_ptrINS_12SynchronizerEEEEUlRKNS_6StatusEE_EEvOT_
_ZN2yb6tablet9Operation23set_completion_callbackINSt3__18functionIFvRKNS_6StatusEEEEEEvOT_
Line
Count
Source
155
204k
  void set_completion_callback(F&& completion_clbk) {
156
204k
    completion_clbk_ = std::move(completion_clbk);
157
204k
  }
_ZN2yb6tablet9Operation23set_completion_callbackIZNS0_36MakeLatchOperationCompletionCallbackIPNS_14CountDownLatchEPNS_7tserver26TabletSnapshotOpResponsePBEEEDaT_T0_EUlRKNS_6StatusEE_EEvOSA_
Line
Count
Source
155
361
  void set_completion_callback(F&& completion_clbk) {
156
361
    completion_clbk_ = std::move(completion_clbk);
157
361
  }
write_query.cc:_ZN2yb6tablet9Operation23set_completion_callbackIZNS0_10WriteQuery13PrepareSubmitEvE3$_0EEvOT_
Line
Count
Source
155
1.64M
  void set_completion_callback(F&& completion_clbk) {
156
1.64M
    completion_clbk_ = std::move(completion_clbk);
157
1.64M
  }
_ZN2yb6tablet9Operation23set_completion_callbackIZNS_7tserver34MakeRpcOperationCompletionCallbackINS3_24ChangeMetadataResponsePBEEEDaNS_3rpc10RpcContextEPT_RK13scoped_refptrINS_6server5ClockEEEUlRKNS_6StatusEE_EEvOS9_
Line
Count
Source
155
20.5k
  void set_completion_callback(F&& completion_clbk) {
156
20.5k
    completion_clbk_ = std::move(completion_clbk);
157
20.5k
  }
_ZN2yb6tablet9Operation23set_completion_callbackIZNS_7tserver34MakeRpcOperationCompletionCallbackINS3_27UpdateTransactionResponsePBEEEDaNS_3rpc10RpcContextEPT_RK13scoped_refptrINS_6server5ClockEEEUlRKNS_6StatusEE_EEvOS9_
Line
Count
Source
155
1.48M
  void set_completion_callback(F&& completion_clbk) {
156
1.48M
    completion_clbk_ = std::move(completion_clbk);
157
1.48M
  }
_ZN2yb6tablet9Operation23set_completion_callbackIZNS_7tserver34MakeRpcOperationCompletionCallbackINS3_18TruncateResponsePBEEEDaNS_3rpc10RpcContextEPT_RK13scoped_refptrINS_6server5ClockEEEUlRKNS_6StatusEE_EEvOS9_
Line
Count
Source
155
53.6k
  void set_completion_callback(F&& completion_clbk) {
156
53.6k
    completion_clbk_ = std::move(completion_clbk);
157
53.6k
  }
_ZN2yb6tablet9Operation23set_completion_callbackIZNS_7tserver34MakeRpcOperationCompletionCallbackINS3_21SplitTabletResponsePBEEEDaNS_3rpc10RpcContextEPT_RK13scoped_refptrINS_6server5ClockEEEUlRKNS_6StatusEE_EEvOS9_
Line
Count
Source
155
19
  void set_completion_callback(F&& completion_clbk) {
156
19
    completion_clbk_ = std::move(completion_clbk);
157
19
  }
_ZN2yb6tablet9Operation23set_completion_callbackIZNS_7tserver34MakeRpcOperationCompletionCallbackINS3_26TabletSnapshotOpResponsePBEEEDaNS_3rpc10RpcContextEPT_RK13scoped_refptrINS_6server5ClockEEEUlRKNS_6StatusEE_EEvOS9_
Line
Count
Source
155
3
  void set_completion_callback(F&& completion_clbk) {
156
3
    completion_clbk_ = std::move(completion_clbk);
157
3
  }
158
159
  // Sets the hybrid_time for the transaction
160
  void set_hybrid_time(const HybridTime& hybrid_time);
161
162
28.8M
  HybridTime hybrid_time() const {
163
28.8M
    std::lock_guard<simple_spinlock> l(mutex_);
164
28.8M
    DCHECK(hybrid_time_.is_valid());
165
28.8M
    return hybrid_time_;
166
28.8M
  }
167
168
48.3k
  HybridTime hybrid_time_even_if_unset() const {
169
48.3k
    std::lock_guard<simple_spinlock> l(mutex_);
170
48.3k
    return hybrid_time_;
171
48.3k
  }
172
173
4
  bool has_hybrid_time() const {
174
4
    std::lock_guard<simple_spinlock> l(mutex_);
175
4
    return hybrid_time_.is_valid();
176
4
  }
177
178
  // Returns hybrid time that should be used for storing this operation result in RocksDB.
179
  // For instance it could be different from hybrid_time() for CDC.
180
  virtual HybridTime WriteHybridTime() const;
181
182
8.17M
  void set_op_id(const OpId& op_id) {
183
8.17M
    std::lock_guard<simple_spinlock> l(mutex_);
184
8.17M
    op_id_ = op_id;
185
8.17M
  }
186
187
24.6M
  const OpId& op_id() const {
188
24.6M
    return op_id_;
189
24.6M
  }
190
191
0
  bool has_completion_callback() const {
192
0
    return completion_clbk_ != nullptr;
193
0
  }
194
195
  void CompleteWithStatus(const Status& status) const;
196
197
  // Whether we should use MVCC Manager to track this operation.
198
1.41M
  virtual bool use_mvcc() const {
199
1.41M
    return false;
200
1.41M
  }
201
202
  // Initialize operation at leader side.
203
  // op_id - operation id.
204
  // committed_op_id - current committed operation id.
205
  void AddedToLeader(const OpId& op_id, const OpId& committed_op_id);
206
  void AddedToFollower();
207
208
  void Aborted(bool was_pending);
209
  void Replicated();
210
211
  virtual ~Operation();
212
213
 private:
214
  // Actual implementation of Replicated.
215
  // complete_status could be used to change completion status, i.e. callback will be invoked
216
  // with this status.
217
  virtual CHECKED_STATUS DoReplicated(int64_t leader_term, Status* complete_status) = 0;
218
219
  // Actual implementation of Aborted, should return status that should be passed to callback.
220
  virtual CHECKED_STATUS DoAborted(const Status& status) = 0;
221
222
  // A private version of this transaction's transaction state so that we can use base
223
  // Operation methods on destructors.
224
  const OperationType operation_type_;
225
226
7.79M
  virtual void AddedAsPending() {}
227
7.79M
  virtual void RemovedFromPending() {}
228
229
  // The tablet peer that is coordinating this transaction.
230
  Tablet* tablet_;
231
232
  // Optional callback to be called once the transaction completes.
233
  OperationCompletionCallback completion_clbk_;
234
235
  mutable std::atomic<bool> complete_{false};
236
237
  mutable simple_spinlock mutex_;
238
239
  // This transaction's hybrid_time. Protected by mutex_.
240
  HybridTime hybrid_time_ GUARDED_BY(mutex_);
241
242
  // This OpId stores the canonical "anchor" OpId for this transaction.
243
  OpId op_id_ GUARDED_BY(mutex_);
244
245
  scoped_refptr<consensus::ConsensusRound> consensus_round_;
246
247
  ScopedOperation preparing_token_;
248
};
249
250
template <class Request>
251
struct RequestTraits {
252
  static void SetAllocatedRequest(
253
      consensus::ReplicateMsg* replicate, Request* request);
254
255
  static Request* MutableRequest(consensus::ReplicateMsg* replicate);
256
};
257
258
consensus::ReplicateMsgPtr CreateReplicateMsg(OperationType op_type);
259
260
template <OperationType op_type, class Request, class Base = Operation>
261
class OperationBase : public Base {
262
 public:
263
  explicit OperationBase(Tablet* tablet, const Request* request = nullptr)
264
9.12M
      : Base(op_type, tablet), request_(request) {}
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBENS0_28ExclusiveSchemaOperationBaseEEC2EPNS0_6TabletEPKS4_
Line
Count
Source
264
876
      : Base(op_type, tablet), request_(request) {}
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE3ENS0_7WritePBENS0_9OperationEEC2EPNS0_6TabletEPKS3_
Line
Count
Source
264
4.92M
      : Base(op_type, tablet), request_(request) {}
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE8ENS0_10TruncatePBENS0_9OperationEEC2EPNS0_6TabletEPKS3_
Line
Count
Source
264
158k
      : Base(op_type, tablet), request_(request) {}
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE6ENS0_18TransactionStatePBENS0_9OperationEEC2EPNS0_6TabletEPKS3_
Line
Count
Source
264
3.49M
      : Base(op_type, tablet), request_(request) {}
Unexecuted instantiation: _ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE9ENS_9consensus15HistoryCutoffPBENS0_9OperationEEC2EPNS0_6TabletEPKS4_
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE10ENS0_20SplitTabletRequestPBENS0_9OperationEEC2EPNS0_6TabletEPKS3_
Line
Count
Source
264
51
      : Base(op_type, tablet), request_(request) {}
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE4ENS0_23ChangeMetadataRequestPBENS0_28ExclusiveSchemaOperationBaseEEC2EPNS0_6TabletEPKS3_
Line
Count
Source
264
547k
      : Base(op_type, tablet), request_(request) {}
265
266
17.2M
  const Request* request() const override {
267
17.2M
    return request_.load(std::memory_order_acquire);
268
17.2M
  }
_ZNK2yb6tablet13OperationBaseILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBENS0_28ExclusiveSchemaOperationBaseEE7requestEv
Line
Count
Source
266
4.37k
  const Request* request() const override {
267
4.37k
    return request_.load(std::memory_order_acquire);
268
4.37k
  }
_ZNK2yb6tablet13OperationBaseILNS0_13OperationTypeE4ENS0_23ChangeMetadataRequestPBENS0_28ExclusiveSchemaOperationBaseEE7requestEv
Line
Count
Source
266
5.00M
  const Request* request() const override {
267
5.00M
    return request_.load(std::memory_order_acquire);
268
5.00M
  }
_ZNK2yb6tablet13OperationBaseILNS0_13OperationTypeE3ENS0_7WritePBENS0_9OperationEE7requestEv
Line
Count
Source
266
5.19M
  const Request* request() const override {
267
5.19M
    return request_.load(std::memory_order_acquire);
268
5.19M
  }
_ZNK2yb6tablet13OperationBaseILNS0_13OperationTypeE10ENS0_20SplitTabletRequestPBENS0_9OperationEE7requestEv
Line
Count
Source
266
47
  const Request* request() const override {
267
47
    return request_.load(std::memory_order_acquire);
268
47
  }
_ZNK2yb6tablet13OperationBaseILNS0_13OperationTypeE8ENS0_10TruncatePBENS0_9OperationEE7requestEv
Line
Count
Source
266
1
  const Request* request() const override {
267
1
    return request_.load(std::memory_order_acquire);
268
1
  }
_ZNK2yb6tablet13OperationBaseILNS0_13OperationTypeE6ENS0_18TransactionStatePBENS0_9OperationEE7requestEv
Line
Count
Source
266
7.07M
  const Request* request() const override {
267
7.07M
    return request_.load(std::memory_order_acquire);
268
7.07M
  }
Unexecuted instantiation: _ZNK2yb6tablet13OperationBaseILNS0_13OperationTypeE9ENS_9consensus15HistoryCutoffPBENS0_9OperationEE7requestEv
269
270
1.74M
  Request* AllocateRequest() {
271
1.74M
    request_holder_ = std::make_unique<Request>();
272
1.74M
    request_.store(request_holder_.get(), std::memory_order_release);
273
1.74M
    return request_holder_.get();
274
1.74M
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE3ENS0_7WritePBENS0_9OperationEE15AllocateRequestEv
Line
Count
Source
270
1.74M
  Request* AllocateRequest() {
271
1.74M
    request_holder_ = std::make_unique<Request>();
272
1.74M
    request_.store(request_holder_.get(), std::memory_order_release);
273
1.74M
    return request_holder_.get();
274
1.74M
  }
Unexecuted instantiation: _ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBENS0_28ExclusiveSchemaOperationBaseEE15AllocateRequestEv
Unexecuted instantiation: _ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE9ENS_9consensus15HistoryCutoffPBENS0_9OperationEE15AllocateRequestEv
275
276
6.45M
  Request* mutable_request() {
277
6.45M
    return request_holder_.get();
278
6.45M
  }
279
280
  Request* ReleaseRequest() {
281
    return request_holder_.release();
282
  }
283
284
239k
  void TakeRequest(Request* request) {
285
239k
    request_holder_.reset(new Request);
286
239k
    request_.store(request_holder_.get(), std::memory_order_release);
287
239k
    request_holder_->Swap(request);
288
239k
  }
289
290
2.69M
  consensus::ReplicateMsgPtr NewReplicateMsg() override {
291
2.69M
    auto result = CreateReplicateMsg(op_type);
292
2.69M
    auto* request = request_holder_.release();
293
2.69M
    if (request) {
294
1.78M
      RequestTraits<Request>::SetAllocatedRequest(result.get(), request);
295
916k
    } else {
296
916k
      *RequestTraits<Request>::MutableRequest(result.get()) = *request_;
297
916k
    }
298
2.69M
    return result;
299
2.69M
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBENS0_28ExclusiveSchemaOperationBaseEE15NewReplicateMsgEv
Line
Count
Source
290
364
  consensus::ReplicateMsgPtr NewReplicateMsg() override {
291
364
    auto result = CreateReplicateMsg(op_type);
292
364
    auto* request = request_holder_.release();
293
364
    if (request) {
294
0
      RequestTraits<Request>::SetAllocatedRequest(result.get(), request);
295
364
    } else {
296
364
      *RequestTraits<Request>::MutableRequest(result.get()) = *request_;
297
364
    }
298
364
    return result;
299
364
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE10ENS0_20SplitTabletRequestPBENS0_9OperationEE15NewReplicateMsgEv
Line
Count
Source
290
19
  consensus::ReplicateMsgPtr NewReplicateMsg() override {
291
19
    auto result = CreateReplicateMsg(op_type);
292
19
    auto* request = request_holder_.release();
293
19
    if (request) {
294
0
      RequestTraits<Request>::SetAllocatedRequest(result.get(), request);
295
19
    } else {
296
19
      *RequestTraits<Request>::MutableRequest(result.get()) = *request_;
297
19
    }
298
19
    return result;
299
19
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE3ENS0_7WritePBENS0_9OperationEE15NewReplicateMsgEv
Line
Count
Source
290
1.54M
  consensus::ReplicateMsgPtr NewReplicateMsg() override {
291
1.54M
    auto result = CreateReplicateMsg(op_type);
292
1.54M
    auto* request = request_holder_.release();
293
1.54M
    if (request) {
294
1.54M
      RequestTraits<Request>::SetAllocatedRequest(result.get(), request);
295
3.99k
    } else {
296
3.99k
      *RequestTraits<Request>::MutableRequest(result.get()) = *request_;
297
3.99k
    }
298
1.54M
    return result;
299
1.54M
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE8ENS0_10TruncatePBENS0_9OperationEE15NewReplicateMsgEv
Line
Count
Source
290
53.5k
  consensus::ReplicateMsgPtr NewReplicateMsg() override {
291
53.5k
    auto result = CreateReplicateMsg(op_type);
292
53.5k
    auto* request = request_holder_.release();
293
53.5k
    if (request) {
294
0
      RequestTraits<Request>::SetAllocatedRequest(result.get(), request);
295
53.5k
    } else {
296
53.5k
      *RequestTraits<Request>::MutableRequest(result.get()) = *request_;
297
53.5k
    }
298
53.5k
    return result;
299
53.5k
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE6ENS0_18TransactionStatePBENS0_9OperationEE15NewReplicateMsgEv
Line
Count
Source
290
873k
  consensus::ReplicateMsgPtr NewReplicateMsg() override {
291
873k
    auto result = CreateReplicateMsg(op_type);
292
873k
    auto* request = request_holder_.release();
293
873k
    if (request) {
294
239k
      RequestTraits<Request>::SetAllocatedRequest(result.get(), request);
295
633k
    } else {
296
633k
      *RequestTraits<Request>::MutableRequest(result.get()) = *request_;
297
633k
    }
298
873k
    return result;
299
873k
  }
Unexecuted instantiation: _ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE9ENS_9consensus15HistoryCutoffPBENS0_9OperationEE15NewReplicateMsgEv
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE4ENS0_23ChangeMetadataRequestPBENS0_28ExclusiveSchemaOperationBaseEE15NewReplicateMsgEv
Line
Count
Source
290
225k
  consensus::ReplicateMsgPtr NewReplicateMsg() override {
291
225k
    auto result = CreateReplicateMsg(op_type);
292
225k
    auto* request = request_holder_.release();
293
225k
    if (request) {
294
0
      RequestTraits<Request>::SetAllocatedRequest(result.get(), request);
295
225k
    } else {
296
225k
      *RequestTraits<Request>::MutableRequest(result.get()) = *request_;
297
225k
    }
298
225k
    return result;
299
225k
  }
300
301
7.79M
  void UpdateRequestFromConsensusRound() override {
302
7.79M
    UseRequest(RequestTraits<Request>::MutableRequest(
303
7.79M
        Base::consensus_round()->replicate_msg().get()));
304
7.79M
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBENS0_28ExclusiveSchemaOperationBaseEE31UpdateRequestFromConsensusRoundEv
Line
Count
Source
301
864
  void UpdateRequestFromConsensusRound() override {
302
864
    UseRequest(RequestTraits<Request>::MutableRequest(
303
864
        Base::consensus_round()->replicate_msg().get()));
304
864
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE10ENS0_20SplitTabletRequestPBENS0_9OperationEE31UpdateRequestFromConsensusRoundEv
Line
Count
Source
301
50
  void UpdateRequestFromConsensusRound() override {
302
50
    UseRequest(RequestTraits<Request>::MutableRequest(
303
50
        Base::consensus_round()->replicate_msg().get()));
304
50
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE3ENS0_7WritePBENS0_9OperationEE31UpdateRequestFromConsensusRoundEv
Line
Count
Source
301
4.47M
  void UpdateRequestFromConsensusRound() override {
302
4.47M
    UseRequest(RequestTraits<Request>::MutableRequest(
303
4.47M
        Base::consensus_round()->replicate_msg().get()));
304
4.47M
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE8ENS0_10TruncatePBENS0_9OperationEE31UpdateRequestFromConsensusRoundEv
Line
Count
Source
301
159k
  void UpdateRequestFromConsensusRound() override {
302
159k
    UseRequest(RequestTraits<Request>::MutableRequest(
303
159k
        Base::consensus_round()->replicate_msg().get()));
304
159k
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE6ENS0_18TransactionStatePBENS0_9OperationEE31UpdateRequestFromConsensusRoundEv
Line
Count
Source
301
2.61M
  void UpdateRequestFromConsensusRound() override {
302
2.61M
    UseRequest(RequestTraits<Request>::MutableRequest(
303
2.61M
        Base::consensus_round()->replicate_msg().get()));
304
2.61M
  }
Unexecuted instantiation: _ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE9ENS_9consensus15HistoryCutoffPBENS0_9OperationEE31UpdateRequestFromConsensusRoundEv
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE4ENS0_23ChangeMetadataRequestPBENS0_28ExclusiveSchemaOperationBaseEE31UpdateRequestFromConsensusRoundEv
Line
Count
Source
301
545k
  void UpdateRequestFromConsensusRound() override {
302
545k
    UseRequest(RequestTraits<Request>::MutableRequest(
303
545k
        Base::consensus_round()->replicate_msg().get()));
304
545k
  }
305
306
 protected:
307
8.33M
  void UseRequest(const Request* request) {
308
8.33M
    request_.store(request, std::memory_order_release);
309
8.33M
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBENS0_28ExclusiveSchemaOperationBaseEE10UseRequestEPKS4_
Line
Count
Source
307
1.72k
  void UseRequest(const Request* request) {
308
1.72k
    request_.store(request, std::memory_order_release);
309
1.72k
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE10ENS0_20SplitTabletRequestPBENS0_9OperationEE10UseRequestEPKS3_
Line
Count
Source
307
50
  void UseRequest(const Request* request) {
308
50
    request_.store(request, std::memory_order_release);
309
50
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE3ENS0_7WritePBENS0_9OperationEE10UseRequestEPKS3_
Line
Count
Source
307
4.47M
  void UseRequest(const Request* request) {
308
4.47M
    request_.store(request, std::memory_order_release);
309
4.47M
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE8ENS0_10TruncatePBENS0_9OperationEE10UseRequestEPKS3_
Line
Count
Source
307
159k
  void UseRequest(const Request* request) {
308
159k
    request_.store(request, std::memory_order_release);
309
159k
  }
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE6ENS0_18TransactionStatePBENS0_9OperationEE10UseRequestEPKS3_
Line
Count
Source
307
2.61M
  void UseRequest(const Request* request) {
308
2.61M
    request_.store(request, std::memory_order_release);
309
2.61M
  }
Unexecuted instantiation: _ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE9ENS_9consensus15HistoryCutoffPBENS0_9OperationEE10UseRequestEPKS4_
_ZN2yb6tablet13OperationBaseILNS0_13OperationTypeE4ENS0_23ChangeMetadataRequestPBENS0_28ExclusiveSchemaOperationBaseEE10UseRequestEPKS3_
Line
Count
Source
307
1.09M
  void UseRequest(const Request* request) {
308
1.09M
    request_.store(request, std::memory_order_release);
309
1.09M
  }
310
311
 private:
312
  std::unique_ptr<Request> request_holder_;
313
  std::atomic<const Request*> request_;
314
};
315
316
class ExclusiveSchemaOperationBase : public Operation {
317
 public:
318
  template <class... Args>
319
  explicit ExclusiveSchemaOperationBase(Args&&... args)
320
547k
      : Operation(std::forward<Args>(args)...) {}
321
322
  // Release the acquired schema lock.
323
  void ReleasePermitToken();
324
325
18.0k
  void UsePermitToken(ScopedRWOperationPause&& token) {
326
18.0k
    permit_token_ = std::move(token);
327
18.0k
  }
328
329
 private:
330
  // Used to pause write operations from being accepted while alter is in progress.
331
  ScopedRWOperationPause permit_token_;
332
};
333
334
template <OperationType operation_type, class Request>
335
class ExclusiveSchemaOperation
336
    : public OperationBase<operation_type, Request, ExclusiveSchemaOperationBase> {
337
 public:
338
  template <class... Args>
339
  explicit ExclusiveSchemaOperation(Args&&... args)
340
      : OperationBase<operation_type, Request, ExclusiveSchemaOperationBase>(
341
547k
            std::forward<Args>(args)...) {}
_ZN2yb6tablet24ExclusiveSchemaOperationILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBEEC2IJPNS0_6TabletEPS4_EEEDpOT_
Line
Count
Source
341
373
            std::forward<Args>(args)...) {}
Unexecuted instantiation: _ZN2yb6tablet24ExclusiveSchemaOperationILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBEEC2IJDnEEEDpOT_
Unexecuted instantiation: _ZN2yb6tablet24ExclusiveSchemaOperationILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBEEC2IJPNS0_6TabletERKPS4_EEEDpOT_
_ZN2yb6tablet24ExclusiveSchemaOperationILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBEEC2IJPNS0_6TabletEEEEDpOT_
Line
Count
Source
341
500
            std::forward<Args>(args)...) {}
_ZN2yb6tablet24ExclusiveSchemaOperationILNS0_13OperationTypeE4ENS0_23ChangeMetadataRequestPBEEC2IJRPNS0_6TabletERPKS3_EEEDpOT_
Line
Count
Source
341
546k
            std::forward<Args>(args)...) {}
_ZN2yb6tablet24ExclusiveSchemaOperationILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBEEC2IJPNS0_6TabletERPKS4_EEEDpOT_
Line
Count
Source
341
3
            std::forward<Args>(args)...) {}
342
343
546k
  void Release() override {
344
546k
    ExclusiveSchemaOperationBase::ReleasePermitToken();
345
346
    // Make the request NULL since after this operation commits
347
    // the request may be deleted at any moment.
348
546k
    OperationBase<operation_type, Request, ExclusiveSchemaOperationBase>::UseRequest(nullptr);
349
546k
  }
_ZN2yb6tablet24ExclusiveSchemaOperationILNS0_13OperationTypeE7ENS_7tserver25TabletSnapshotOpRequestPBEE7ReleaseEv
Line
Count
Source
343
864
  void Release() override {
344
864
    ExclusiveSchemaOperationBase::ReleasePermitToken();
345
346
    // Make the request NULL since after this operation commits
347
    // the request may be deleted at any moment.
348
864
    OperationBase<operation_type, Request, ExclusiveSchemaOperationBase>::UseRequest(nullptr);
349
864
  }
_ZN2yb6tablet24ExclusiveSchemaOperationILNS0_13OperationTypeE4ENS0_23ChangeMetadataRequestPBEE7ReleaseEv
Line
Count
Source
343
545k
  void Release() override {
344
545k
    ExclusiveSchemaOperationBase::ReleasePermitToken();
345
346
    // Make the request NULL since after this operation commits
347
    // the request may be deleted at any moment.
348
545k
    OperationBase<operation_type, Request, ExclusiveSchemaOperationBase>::UseRequest(nullptr);
349
545k
  }
350
};
351
352
template<class LatchPtr, class ResponsePBPtr>
353
168k
auto MakeLatchOperationCompletionCallback(LatchPtr latch, ResponsePBPtr response) {
354
168k
  return [latch, response](const Status& status) {
355
168k
    if (!status.ok()) {
356
3
      StatusToPB(status, response->mutable_error()->mutable_status());
357
3
    }
358
168k
    latch->CountDown();
359
168k
  };
_ZZN2yb6tablet36MakeLatchOperationCompletionCallbackIPNS_14CountDownLatchEPNS_7tserver15WriteResponsePBEEEDaT_T0_ENKUlRKNS_6StatusEE_clESC_
Line
Count
Source
354
4.01k
  return [latch, response](const Status& status) {
355
4.01k
    if (!status.ok()) {
356
0
      StatusToPB(status, response->mutable_error()->mutable_status());
357
0
    }
358
4.01k
    latch->CountDown();
359
4.01k
  };
_ZZN2yb6tablet36MakeLatchOperationCompletionCallbackINSt3__110shared_ptrINS_14CountDownLatchEEENS3_INS_7tserver15WriteResponsePBEEEEEDaT_T0_ENKUlRKNS_6StatusEE_clESE_
Line
Count
Source
354
164k
  return [latch, response](const Status& status) {
355
164k
    if (!status.ok()) {
356
3
      StatusToPB(status, response->mutable_error()->mutable_status());
357
3
    }
358
164k
    latch->CountDown();
359
164k
  };
_ZZN2yb6tablet36MakeLatchOperationCompletionCallbackIPNS_14CountDownLatchEPNS_7tserver26TabletSnapshotOpResponsePBEEEDaT_T0_ENKUlRKNS_6StatusEE_clESC_
Line
Count
Source
354
361
  return [latch, response](const Status& status) {
355
361
    if (!status.ok()) {
356
0
      StatusToPB(status, response->mutable_error()->mutable_status());
357
0
    }
358
361
    latch->CountDown();
359
361
  };
360
168k
}
_ZN2yb6tablet36MakeLatchOperationCompletionCallbackIPNS_14CountDownLatchEPNS_7tserver15WriteResponsePBEEEDaT_T0_
Line
Count
Source
353
4.01k
auto MakeLatchOperationCompletionCallback(LatchPtr latch, ResponsePBPtr response) {
354
4.01k
  return [latch, response](const Status& status) {
355
4.01k
    if (!status.ok()) {
356
4.01k
      StatusToPB(status, response->mutable_error()->mutable_status());
357
4.01k
    }
358
4.01k
    latch->CountDown();
359
4.01k
  };
360
4.01k
}
_ZN2yb6tablet36MakeLatchOperationCompletionCallbackINSt3__110shared_ptrINS_14CountDownLatchEEENS3_INS_7tserver15WriteResponsePBEEEEEDaT_T0_
Line
Count
Source
353
163k
auto MakeLatchOperationCompletionCallback(LatchPtr latch, ResponsePBPtr response) {
354
163k
  return [latch, response](const Status& status) {
355
163k
    if (!status.ok()) {
356
163k
      StatusToPB(status, response->mutable_error()->mutable_status());
357
163k
    }
358
163k
    latch->CountDown();
359
163k
  };
360
163k
}
_ZN2yb6tablet36MakeLatchOperationCompletionCallbackIPNS_14CountDownLatchEPNS_7tserver26TabletSnapshotOpResponsePBEEEDaT_T0_
Line
Count
Source
353
361
auto MakeLatchOperationCompletionCallback(LatchPtr latch, ResponsePBPtr response) {
354
361
  return [latch, response](const Status& status) {
355
361
    if (!status.ok()) {
356
361
      StatusToPB(status, response->mutable_error()->mutable_status());
357
361
    }
358
361
    latch->CountDown();
359
361
  };
360
361
}
361
362
OperationCompletionCallback MakeWeakSynchronizerOperationCompletionCallback(
363
    std::weak_ptr<Synchronizer> synchronizer);
364
365
}  // namespace tablet
366
}  // namespace yb
367
368
#endif  // YB_TABLET_OPERATIONS_OPERATION_H