-
Notifications
You must be signed in to change notification settings - Fork 1k
/
tablet_service.h
364 lines (280 loc) · 14.7 KB
/
tablet_service.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
// The following only applies to changes made to this file as part of YugaByte development.
//
// Portions Copyright (c) YugaByte, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations
// under the License.
//
#pragma once
#include <functional>
#include <future>
#include <memory>
#include <set>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include <boost/range/iterator_range.hpp>
#include "yb/common/common_fwd.h"
#include "yb/consensus/consensus.service.h"
#include "yb/gutil/ref_counted.h"
#include "yb/tablet/tablet_fwd.h"
#include "yb/tserver/read_query.h"
#include "yb/tserver/tserver_util_fwd.h"
#include "yb/tserver/tserver_fwd.h"
#include "yb/tserver/tserver_admin.pb.h"
#include "yb/tserver/tserver_admin.service.h"
#include "yb/tserver/tserver_service.service.h"
namespace yb {
class Schema;
class Status;
class HybridTime;
namespace tserver {
class TabletPeerLookupIf;
class TabletServer;
class TabletServiceImpl : public TabletServerServiceIf, public ReadTabletProvider {
public:
typedef std::vector<tablet::TabletPeerPtr> TabletPeers;
explicit TabletServiceImpl(TabletServerIf* server);
void Write(const WriteRequestPB* req, WriteResponsePB* resp, rpc::RpcContext context) override;
void Read(const ReadRequestPB* req, ReadResponsePB* resp, rpc::RpcContext context) override;
void VerifyTableRowRange(
const VerifyTableRowRangeRequestPB* req, VerifyTableRowRangeResponsePB* resp,
rpc::RpcContext context) override;
void NoOp(const NoOpRequestPB* req, NoOpResponsePB* resp, rpc::RpcContext context) override;
void Publish(
const PublishRequestPB* req, PublishResponsePB* resp, rpc::RpcContext context) override;
void ListTablets(const ListTabletsRequestPB* req,
ListTabletsResponsePB* resp,
rpc::RpcContext context) override;
void GetMasterAddresses(const GetMasterAddressesRequestPB* req,
GetMasterAddressesResponsePB* resp,
rpc::RpcContext context) override;
void ListTabletsForTabletServer(const ListTabletsForTabletServerRequestPB* req,
ListTabletsForTabletServerResponsePB* resp,
rpc::RpcContext context) override;
void GetLogLocation(
const GetLogLocationRequestPB* req,
GetLogLocationResponsePB* resp,
rpc::RpcContext context) override;
void Checksum(const ChecksumRequestPB* req,
ChecksumResponsePB* resp,
rpc::RpcContext context) override;
void ImportData(const ImportDataRequestPB* req,
ImportDataResponsePB* resp,
rpc::RpcContext context) override;
void UpdateTransaction(const UpdateTransactionRequestPB* req,
UpdateTransactionResponsePB* resp,
rpc::RpcContext context) override;
void GetTransactionStatus(const GetTransactionStatusRequestPB* req,
GetTransactionStatusResponsePB* resp,
rpc::RpcContext context) override;
void GetOldTransactions(const GetOldTransactionsRequestPB* req,
GetOldTransactionsResponsePB* resp,
rpc::RpcContext context) override;
void GetTransactionStatusAtParticipant(const GetTransactionStatusAtParticipantRequestPB* req,
GetTransactionStatusAtParticipantResponsePB* resp,
rpc::RpcContext context) override;
void AbortTransaction(const AbortTransactionRequestPB* req,
AbortTransactionResponsePB* resp,
rpc::RpcContext context) override;
void UpdateTransactionStatusLocation(const UpdateTransactionStatusLocationRequestPB* req,
UpdateTransactionStatusLocationResponsePB* resp,
rpc::RpcContext context) override;
void UpdateTransactionWaitingForStatus(
const UpdateTransactionWaitingForStatusRequestPB* req,
UpdateTransactionWaitingForStatusResponsePB* resp,
rpc::RpcContext context) override;
void ProbeTransactionDeadlock(
const ProbeTransactionDeadlockRequestPB* req,
ProbeTransactionDeadlockResponsePB* resp,
rpc::RpcContext context) override;
void Truncate(const TruncateRequestPB* req,
TruncateResponsePB* resp,
rpc::RpcContext context) override;
void GetCompatibleSchemaVersion(const GetCompatibleSchemaVersionRequestPB* req,
GetCompatibleSchemaVersionResponsePB* resp,
rpc::RpcContext context) override;
void GetTabletStatus(const GetTabletStatusRequestPB* req,
GetTabletStatusResponsePB* resp,
rpc::RpcContext context) override;
void IsTabletServerReady(const IsTabletServerReadyRequestPB* req,
IsTabletServerReadyResponsePB* resp,
rpc::RpcContext context) override;
void GetSplitKey(
const GetSplitKeyRequestPB* req,
GetSplitKeyResponsePB* resp,
rpc::RpcContext context) override;
void GetSharedData(const GetSharedDataRequestPB* req,
GetSharedDataResponsePB* resp,
rpc::RpcContext context) override;
void GetTserverCatalogVersionInfo(const GetTserverCatalogVersionInfoRequestPB* req,
GetTserverCatalogVersionInfoResponsePB* resp,
rpc::RpcContext context) override;
void ListMasterServers(const ListMasterServersRequestPB* req,
ListMasterServersResponsePB* resp,
rpc::RpcContext context) override;
void ClearUniverseUuid(const ClearUniverseUuidRequestPB* req,
ClearUniverseUuidResponsePB* resp,
rpc::RpcContext context) override;
void GetLockStatus(const GetLockStatusRequestPB* req,
GetLockStatusResponsePB* resp,
rpc::RpcContext context) override;
void Shutdown() override;
private:
Status PerformWrite(const WriteRequestPB* req, WriteResponsePB* resp, rpc::RpcContext* context);
Result<std::shared_ptr<tablet::AbstractTablet>> GetTabletForRead(
const TabletId& tablet_id, tablet::TabletPeerPtr tablet_peer,
YBConsistencyLevel consistency_level, tserver::AllowSplitTablet allow_split_tablet) override;
template<class Resp>
bool CheckWriteThrottlingOrRespond(
double score, tablet::TabletPeer* tablet_peer, Resp* resp, rpc::RpcContext* context);
template <class Req, class Resp, class F>
void PerformAtLeader(const Req& req, Resp* resp, rpc::RpcContext* context, const F& f);
Result<uint64_t> DoChecksum(const ChecksumRequestPB* req, CoarseTimePoint deadline);
Status HandleUpdateTransactionStatusLocation(const UpdateTransactionStatusLocationRequestPB* req,
UpdateTransactionStatusLocationResponsePB* resp,
std::shared_ptr<rpc::RpcContext> context);
TabletServerIf *const server_;
};
class TabletServiceAdminImpl : public TabletServerAdminServiceIf {
public:
typedef std::vector<tablet::TabletPeerPtr> TabletPeers;
explicit TabletServiceAdminImpl(TabletServer* server);
void CreateTablet(const CreateTabletRequestPB* req,
CreateTabletResponsePB* resp,
rpc::RpcContext context) override;
void PrepareDeleteTransactionTablet(const PrepareDeleteTransactionTabletRequestPB* req,
PrepareDeleteTransactionTabletResponsePB* resp,
rpc::RpcContext context) override;
void DeleteTablet(const DeleteTabletRequestPB* req,
DeleteTabletResponsePB* resp,
rpc::RpcContext context) override;
void AlterSchema(const tablet::ChangeMetadataRequestPB* req,
ChangeMetadataResponsePB* resp,
rpc::RpcContext context) override;
void FlushTablets(const FlushTabletsRequestPB* req,
FlushTabletsResponsePB* resp,
rpc::RpcContext context) override;
void CountIntents(const CountIntentsRequestPB* req,
CountIntentsResponsePB* resp,
rpc::RpcContext context) override;
void AddTableToTablet(const AddTableToTabletRequestPB* req,
AddTableToTabletResponsePB* resp,
rpc::RpcContext context) override;
void RemoveTableFromTablet(const RemoveTableFromTabletRequestPB* req,
RemoveTableFromTabletResponsePB* resp,
rpc::RpcContext context) override;
// Called on the Indexed table to choose time to read.
void GetSafeTime(
const GetSafeTimeRequestPB* req, GetSafeTimeResponsePB* resp,
rpc::RpcContext context) override;
// Called on the Indexed table to backfill the index table(s).
void BackfillIndex(
const BackfillIndexRequestPB* req, BackfillIndexResponsePB* resp,
rpc::RpcContext context) override;
// Called on the Index table(s) once the backfill is complete.
void BackfillDone(
const tablet::ChangeMetadataRequestPB* req, ChangeMetadataResponsePB* resp,
rpc::RpcContext context) override;
// Starts tablet splitting by adding split tablet Raft operation into Raft log of the source
// tablet.
void SplitTablet(
const tablet::SplitTabletRequestPB* req,
SplitTabletResponsePB* resp,
rpc::RpcContext context) override;
// Upgrade YSQL cluster (all databases) to the latest version, applying necessary migrations.
void UpgradeYsql(
const UpgradeYsqlRequestPB* req,
UpgradeYsqlResponsePB* resp,
rpc::RpcContext context) override;
void UpdateTransactionTablesVersion(
const UpdateTransactionTablesVersionRequestPB* req,
UpdateTransactionTablesVersionResponsePB* resp,
rpc::RpcContext context) override;
void TestRetry(
const TestRetryRequestPB* req, TestRetryResponsePB* resp, rpc::RpcContext context) override;
private:
TabletServer* server_;
Status DoCreateTablet(const CreateTabletRequestPB* req, CreateTabletResponsePB* resp);
// Used to implement wait/signal mechanism for backfill requests.
// Since the number of concurrently allowed backfill requests is
// limited.
mutable std::mutex backfill_lock_;
std::condition_variable backfill_cond_;
std::atomic<int32_t> num_tablets_backfilling_{0};
std::atomic<int32_t> num_test_retry_calls{0};
scoped_refptr<yb::AtomicGauge<uint64_t>> ts_split_op_added_;
};
class ConsensusServiceImpl : public consensus::ConsensusServiceIf {
public:
ConsensusServiceImpl(const scoped_refptr<MetricEntity>& metric_entity,
TabletPeerLookupIf* tablet_manager_);
virtual ~ConsensusServiceImpl();
void UpdateConsensus(const consensus::LWConsensusRequestPB *req,
consensus::LWConsensusResponsePB *resp,
rpc::RpcContext context) override;
void MultiRaftUpdateConsensus(const consensus::MultiRaftConsensusRequestPB *req,
consensus::MultiRaftConsensusResponsePB *resp,
rpc::RpcContext context) override;
void RequestConsensusVote(const consensus::VoteRequestPB* req,
consensus::VoteResponsePB* resp,
rpc::RpcContext context) override;
void ChangeConfig(const consensus::ChangeConfigRequestPB* req,
consensus::ChangeConfigResponsePB* resp,
rpc::RpcContext context) override;
void UnsafeChangeConfig(const consensus::UnsafeChangeConfigRequestPB* req,
consensus::UnsafeChangeConfigResponsePB* resp,
rpc::RpcContext context) override;
void GetNodeInstance(const consensus::GetNodeInstanceRequestPB* req,
consensus::GetNodeInstanceResponsePB* resp,
rpc::RpcContext context) override;
void RunLeaderElection(const consensus::RunLeaderElectionRequestPB* req,
consensus::RunLeaderElectionResponsePB* resp,
rpc::RpcContext context) override;
void LeaderElectionLost(const consensus::LeaderElectionLostRequestPB *req,
consensus::LeaderElectionLostResponsePB *resp,
rpc::RpcContext context) override;
void LeaderStepDown(const consensus::LeaderStepDownRequestPB* req,
consensus::LeaderStepDownResponsePB* resp,
rpc::RpcContext context) override;
void GetLastOpId(const consensus::GetLastOpIdRequestPB *req,
consensus::GetLastOpIdResponsePB *resp,
rpc::RpcContext context) override;
void GetConsensusState(const consensus::GetConsensusStateRequestPB *req,
consensus::GetConsensusStateResponsePB *resp,
rpc::RpcContext context) override;
void StartRemoteBootstrap(const consensus::StartRemoteBootstrapRequestPB* req,
consensus::StartRemoteBootstrapResponsePB* resp,
rpc::RpcContext context) override;
private:
void CompleteUpdateConsensusResponse(std::shared_ptr<tablet::TabletPeer> tablet_peer,
consensus::LWConsensusResponsePB* resp);
TabletPeerLookupIf* tablet_manager_;
};
} // namespace tserver
} // namespace yb