YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/tools/yb-admin_client.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
#ifndef YB_TOOLS_YB_ADMIN_CLIENT_H
33
#define YB_TOOLS_YB_ADMIN_CLIENT_H
34
35
#include <string>
36
#include <vector>
37
38
#include <boost/optional.hpp>
39
40
#include "yb/client/yb_table_name.h"
41
42
#include "yb/rpc/rpc_controller.h"
43
44
#include "yb/util/status_fwd.h"
45
#include "yb/util/monotime.h"
46
#include "yb/util/net/net_util.h"
47
#include "yb/util/net/sockaddr.h"
48
#include "yb/util/status.h"
49
#include "yb/util/type_traits.h"
50
#include "yb/common/entity_ids.h"
51
#include "yb/consensus/consensus_types.pb.h"
52
53
#include "yb/master/master_client.pb.h"
54
#include "yb/master/master_cluster.pb.h"
55
#include "yb/master/master_fwd.h"
56
57
#include "yb/tools/yb-admin_cli.h"
58
#include "yb/rpc/rpc_fwd.h"
59
60
namespace yb {
61
62
class HybridTime;
63
64
namespace consensus {
65
class ConsensusServiceProxy;
66
}
67
68
namespace client {
69
class YBClient;
70
}
71
72
namespace tools {
73
74
struct TypedNamespaceName {
75
  YQLDatabase db_type = YQL_DATABASE_UNKNOWN;
76
  std::string name;
77
};
78
79
class TableNameResolver {
80
 public:
81
  TableNameResolver(std::vector<client::YBTableName> tables,
82
                    std::vector<master::NamespaceIdentifierPB> namespaces);
83
  TableNameResolver(TableNameResolver&&);
84
  ~TableNameResolver();
85
86
  Result<bool> Feed(const std::string& value);
87
  std::vector<client::YBTableName>& values();
88
  master::NamespaceIdentifierPB last_namespace();
89
90
 private:
91
  class Impl;
92
  std::unique_ptr<Impl> impl_;
93
};
94
95
HAS_MEMBER_FUNCTION(error);
96
HAS_MEMBER_FUNCTION(status);
97
98
template<class Response>
99
CHECKED_STATUS ResponseStatus(
100
    const Response& response,
101
19
    typename std::enable_if<HasMemberFunction_error<Response>::value, void*>::type = nullptr) {
102
  // Response has has_error method, use status from it.
103
19
  if (response.has_error()) {
104
0
    return StatusFromPB(response.error().status());
105
0
  }
106
19
  return Status::OK();
107
19
}
yb::Status yb::tools::ResponseStatus<yb::master::ListSnapshotsResponsePB>(yb::master::ListSnapshotsResponsePB const&, std::__1::enable_if<HasMemberFunction_error<yb::master::ListSnapshotsResponsePB>::value, void*>::type)
Line
Count
Source
101
1
    typename std::enable_if<HasMemberFunction_error<Response>::value, void*>::type = nullptr) {
102
  // Response has has_error method, use status from it.
103
1
  if (response.has_error()) {
104
0
    return StatusFromPB(response.error().status());
105
0
  }
106
1
  return Status::OK();
107
1
}
yb::Status yb::tools::ResponseStatus<yb::master::CreateSnapshotResponsePB>(yb::master::CreateSnapshotResponsePB const&, std::__1::enable_if<HasMemberFunction_error<yb::master::CreateSnapshotResponsePB>::value, void*>::type)
Line
Count
Source
101
2
    typename std::enable_if<HasMemberFunction_error<Response>::value, void*>::type = nullptr) {
102
  // Response has has_error method, use status from it.
103
2
  if (response.has_error()) {
104
0
    return StatusFromPB(response.error().status());
105
0
  }
106
2
  return Status::OK();
107
2
}
Unexecuted instantiation: yb::Status yb::tools::ResponseStatus<yb::master::ListTablesResponsePB>(yb::master::ListTablesResponsePB const&, std::__1::enable_if<HasMemberFunction_error<yb::master::ListTablesResponsePB>::value, void*>::type)
yb::Status yb::tools::ResponseStatus<yb::master::CreateSnapshotScheduleResponsePB>(yb::master::CreateSnapshotScheduleResponsePB const&, std::__1::enable_if<HasMemberFunction_error<yb::master::CreateSnapshotScheduleResponsePB>::value, void*>::type)
Line
Count
Source
101
8
    typename std::enable_if<HasMemberFunction_error<Response>::value, void*>::type = nullptr) {
102
  // Response has has_error method, use status from it.
103
8
  if (response.has_error()) {
104
0
    return StatusFromPB(response.error().status());
105
0
  }
106
8
  return Status::OK();
107
8
}
yb::Status yb::tools::ResponseStatus<yb::master::ListSnapshotSchedulesResponsePB>(yb::master::ListSnapshotSchedulesResponsePB const&, std::__1::enable_if<HasMemberFunction_error<yb::master::ListSnapshotSchedulesResponsePB>::value, void*>::type)
Line
Count
Source
101
8
    typename std::enable_if<HasMemberFunction_error<Response>::value, void*>::type = nullptr) {
102
  // Response has has_error method, use status from it.
103
8
  if (response.has_error()) {
104
0
    return StatusFromPB(response.error().status());
105
0
  }
106
8
  return Status::OK();
107
8
}
Unexecuted instantiation: yb::Status yb::tools::ResponseStatus<yb::master::DeleteSnapshotScheduleResponsePB>(yb::master::DeleteSnapshotScheduleResponsePB const&, std::__1::enable_if<HasMemberFunction_error<yb::master::DeleteSnapshotScheduleResponsePB>::value, void*>::type)
Unexecuted instantiation: yb::Status yb::tools::ResponseStatus<yb::master::RestoreSnapshotResponsePB>(yb::master::RestoreSnapshotResponsePB const&, std::__1::enable_if<HasMemberFunction_error<yb::master::RestoreSnapshotResponsePB>::value, void*>::type)
Unexecuted instantiation: yb::Status yb::tools::ResponseStatus<yb::master::DeleteSnapshotResponsePB>(yb::master::DeleteSnapshotResponsePB const&, std::__1::enable_if<HasMemberFunction_error<yb::master::DeleteSnapshotResponsePB>::value, void*>::type)
Unexecuted instantiation: yb::Status yb::tools::ResponseStatus<yb::master::ImportSnapshotMetaResponsePB>(yb::master::ImportSnapshotMetaResponsePB const&, std::__1::enable_if<HasMemberFunction_error<yb::master::ImportSnapshotMetaResponsePB>::value, void*>::type)
Unexecuted instantiation: yb::Status yb::tools::ResponseStatus<yb::master::GetTabletLocationsResponsePB>(yb::master::GetTabletLocationsResponsePB const&, std::__1::enable_if<HasMemberFunction_error<yb::master::GetTabletLocationsResponsePB>::value, void*>::type)
108
109
template<class Response>
110
CHECKED_STATUS ResponseStatus(
111
    const Response& response,
112
6
    typename std::enable_if<HasMemberFunction_status<Response>::value, void*>::type = nullptr) {
113
6
  if (response.has_status()) {
114
0
    return StatusFromPB(response.status());
115
0
  }
116
6
  return Status::OK();
117
6
}
118
119
class ClusterAdminClient {
120
 public:
121
  enum PeerMode {
122
    LEADER = 1,
123
    FOLLOWER
124
  };
125
126
  // Creates an admin client for host/port combination e.g.,
127
  // "localhost" or "127.0.0.1:7050" with the given timeout.
128
  // If certs_dir is non-empty, caller will init the yb_client_.
129
  ClusterAdminClient(std::string addrs, MonoDelta timeout);
130
131
  ClusterAdminClient(const HostPort& init_master_addr, MonoDelta timeout);
132
133
  virtual ~ClusterAdminClient();
134
135
  // Initialized the client and connects to the specified tablet server.
136
  CHECKED_STATUS Init();
137
138
  // Parse the user-specified change type to consensus change type
139
  CHECKED_STATUS ParseChangeType(
140
      const std::string& change_type,
141
      consensus::ChangeConfigType* cc_type);
142
143
  // Change the configuration of the specified tablet.
144
  CHECKED_STATUS ChangeConfig(
145
      const TabletId& tablet_id,
146
      const std::string& change_type,
147
      const PeerId& peer_uuid,
148
      const boost::optional<std::string>& member_type);
149
150
  // Change the configuration of the master tablet.
151
  CHECKED_STATUS ChangeMasterConfig(
152
      const std::string& change_type,
153
      const std::string& peer_host,
154
      uint16_t peer_port,
155
      const std::string& peer_uuid = "");
156
157
  CHECKED_STATUS DumpMasterState(bool to_console);
158
159
  // List all the tables.
160
  CHECKED_STATUS ListTables(bool include_db_type,
161
                            bool include_table_id,
162
                            bool include_table_type);
163
164
  // List all tablets of this table
165
  CHECKED_STATUS ListTablets(const client::YBTableName& table_name,
166
                             int max_tablets,
167
                             bool json,
168
                             bool followers);
169
170
  // Per Tablet list of all tablet servers
171
  CHECKED_STATUS ListPerTabletTabletServers(const PeerId& tablet_id);
172
173
  // Delete a single table by name.
174
  CHECKED_STATUS DeleteTable(const client::YBTableName& table_name);
175
176
  // Delete a single table by ID.
177
  CHECKED_STATUS DeleteTableById(const TableId& table_id);
178
179
  // Delete a single index by name.
180
  CHECKED_STATUS DeleteIndex(const client::YBTableName& table_name);
181
182
  // Delete a single index by ID.
183
  CHECKED_STATUS DeleteIndexById(const TableId& table_id);
184
185
  // Delete a single namespace by name.
186
  CHECKED_STATUS DeleteNamespace(const TypedNamespaceName& name);
187
188
  // Delete a single namespace by ID.
189
  CHECKED_STATUS DeleteNamespaceById(const NamespaceId& namespace_id);
190
191
  // Launch backfill for (deferred) indexes on the specified table.
192
  CHECKED_STATUS LaunchBackfillIndexForTable(const client::YBTableName& table_name);
193
194
  // List all tablet servers known to master
195
  CHECKED_STATUS ListAllTabletServers(bool exclude_dead = false);
196
197
  // List all masters
198
  CHECKED_STATUS ListAllMasters();
199
200
  // List the log locations of all tablet servers, by uuid
201
  CHECKED_STATUS ListTabletServersLogLocations();
202
203
  // List all the tablets a certain tablet server is serving
204
  CHECKED_STATUS ListTabletsForTabletServer(const PeerId& ts_uuid);
205
206
  CHECKED_STATUS SetLoadBalancerEnabled(bool is_enabled);
207
208
  CHECKED_STATUS GetLoadBalancerState();
209
210
  CHECKED_STATUS GetLoadMoveCompletion();
211
212
  CHECKED_STATUS GetLeaderBlacklistCompletion();
213
214
  CHECKED_STATUS GetIsLoadBalancerIdle();
215
216
  CHECKED_STATUS ListLeaderCounts(const client::YBTableName& table_name);
217
218
  Result<std::unordered_map<std::string, int>> GetLeaderCounts(
219
      const client::YBTableName& table_name);
220
221
  CHECKED_STATUS SetupRedisTable();
222
223
  CHECKED_STATUS DropRedisTable();
224
225
  CHECKED_STATUS FlushTables(const std::vector<client::YBTableName>& table_names,
226
                             bool add_indexes,
227
                             int timeout_secs,
228
                             bool is_compaction);
229
230
  CHECKED_STATUS FlushTablesById(const std::vector<TableId>& table_id,
231
                                 bool add_indexes,
232
                                 int timeout_secs,
233
                                 bool is_compaction);
234
235
  CHECKED_STATUS FlushSysCatalog();
236
237
  CHECKED_STATUS CompactSysCatalog();
238
239
  CHECKED_STATUS ModifyTablePlacementInfo(const client::YBTableName& table_name,
240
                                          const std::string& placement_info,
241
                                          int replication_factor,
242
                                          const std::string& optional_uuid);
243
244
  CHECKED_STATUS ModifyPlacementInfo(std::string placement_infos,
245
                                     int replication_factor,
246
                                     const std::string& optional_uuid);
247
248
  CHECKED_STATUS ClearPlacementInfo();
249
250
  CHECKED_STATUS AddReadReplicaPlacementInfo(const std::string& placement_info,
251
                                             int replication_factor,
252
                                             const std::string& optional_uuid);
253
254
  CHECKED_STATUS ModifyReadReplicaPlacementInfo(const std::string& placement_uuid,
255
                                                const std::string& placement_info,
256
                                                int replication_factor);
257
258
  CHECKED_STATUS DeleteReadReplicaPlacementInfo();
259
260
  CHECKED_STATUS GetUniverseConfig();
261
262
  CHECKED_STATUS ChangeBlacklist(const std::vector<HostPort>& servers, bool add,
263
      bool blacklist_leader);
264
265
  Result<const master::NamespaceIdentifierPB&> GetNamespaceInfo(YQLDatabase db_type,
266
                                                                const std::string& namespace_name);
267
268
  CHECKED_STATUS LeaderStepDownWithNewLeader(
269
      const std::string& tablet_id,
270
      const std::string& dest_ts_uuid);
271
272
  CHECKED_STATUS MasterLeaderStepDown(
273
      const std::string& leader_uuid,
274
      const std::string& new_leader_uuid = std::string());
275
276
  CHECKED_STATUS SplitTablet(const std::string& tablet_id);
277
278
  CHECKED_STATUS DisableTabletSplitting(int64_t disable_duration_ms);
279
280
  CHECKED_STATUS IsTabletSplittingComplete();
281
282
  CHECKED_STATUS CreateTransactionsStatusTable(const std::string& table_name);
283
284
  Result<TableNameResolver> BuildTableNameResolver();
285
286
  Result<std::string> GetMasterLeaderUuid();
287
288
  CHECKED_STATUS GetYsqlCatalogVersion();
289
290
  Result<rapidjson::Document> DdlLog();
291
292
  // Upgrade YSQL cluster (all databases) to the latest version, applying necessary migrations.
293
  // Note: Works with a tserver but is placed here (and not in yb-ts-cli) because it doesn't
294
  //       look like this workflow is a good fit there.
295
  CHECKED_STATUS UpgradeYsql();
296
297
  // Set WAL retention time in secs for a table name.
298
  CHECKED_STATUS SetWalRetentionSecs(
299
    const client::YBTableName& table_name, const uint32_t wal_ret_secs);
300
301
  CHECKED_STATUS GetWalRetentionSecs(const client::YBTableName& table_name);
302
303
 protected:
304
  // Fetch the locations of the replicas for a given tablet from the Master.
305
  CHECKED_STATUS GetTabletLocations(const TabletId& tablet_id,
306
                                    master::TabletLocationsPB* locations);
307
308
  // Fetch information about the location of a tablet peer from the leader master.
309
  CHECKED_STATUS GetTabletPeer(
310
      const TabletId& tablet_id,
311
      PeerMode mode,
312
      master::TSInfoPB* ts_info);
313
314
  // Set the uuid and the socket information for a peer of this tablet.
315
  CHECKED_STATUS SetTabletPeerInfo(
316
      const TabletId& tablet_id,
317
      PeerMode mode,
318
      PeerId* peer_uuid,
319
      HostPort* peer_addr);
320
321
  // Fetch the latest list of tablet servers from the Master.
322
  CHECKED_STATUS ListTabletServers(
323
      google::protobuf::RepeatedPtrField<master::ListTabletServersResponsePB_Entry>* servers);
324
325
  // Look up the RPC address of the server with the specified UUID from the Master.
326
  Result<HostPort> GetFirstRpcAddressForTS(const std::string& uuid);
327
328
  // Step down the leader of this tablet.
329
  // If leader_uuid is empty, look it up with the master.
330
  // If leader_uuid is not empty, must provide a leader_proxy.
331
  // If new_leader_uuid is not empty, it is used as a suggestion for the StepDown operation.
332
  CHECKED_STATUS LeaderStepDown(
333
      const PeerId& leader_uuid,
334
      const TabletId& tablet_id,
335
      const PeerId& new_leader_uuid,
336
      std::unique_ptr<consensus::ConsensusServiceProxy>* leader_proxy);
337
338
  CHECKED_STATUS StartElection(const std::string& tablet_id);
339
340
  CHECKED_STATUS WaitUntilMasterLeaderReady();
341
342
  template <class Resp, class F>
343
25
  CHECKED_STATUS RequestMasterLeader(Resp* resp, const F& f) {
344
25
    auto deadline = CoarseMonoClock::now() + timeout_;
345
25
    rpc::RpcController rpc;
346
25
    rpc.set_timeout(timeout_);
347
25
    for (;;) {
348
25
      resp->Clear();
349
25
      RETURN_NOT_OK(f(&rpc));
350
351
25
      auto status = ResponseStatus(*resp);
352
25
      if (status.ok()) {
353
25
        return Status::OK();
354
25
      }
355
356
0
      if (!status.IsLeaderHasNoLease() && !status.IsLeaderNotReadyToServe() &&
357
0
          !status.IsServiceUnavailable()) {
358
0
        return status;
359
0
      }
360
361
0
      auto timeout = deadline - CoarseMonoClock::now();
362
0
      if (timeout <= MonoDelta::kZero) {
363
0
        return status;
364
0
      }
365
366
0
      rpc.Reset();
367
0
      rpc.set_timeout(timeout);
368
0
      ResetMasterProxy();
369
0
    }
370
25
  }
yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::ListSnapshotsResponsePB, yb::tools::enterprise::ClusterAdminClient::ListSnapshots(yb::EnumBitSet<yb::tools::enterprise::ListSnapshotsFlag> const&)::$_0>(yb::master::ListSnapshotsResponsePB*, yb::tools::enterprise::ClusterAdminClient::ListSnapshots(yb::EnumBitSet<yb::tools::enterprise::ListSnapshotsFlag> const&)::$_0 const&)
Line
Count
Source
343
1
  CHECKED_STATUS RequestMasterLeader(Resp* resp, const F& f) {
344
1
    auto deadline = CoarseMonoClock::now() + timeout_;
345
1
    rpc::RpcController rpc;
346
1
    rpc.set_timeout(timeout_);
347
1
    for (;;) {
348
1
      resp->Clear();
349
1
      RETURN_NOT_OK(f(&rpc));
350
351
1
      auto status = ResponseStatus(*resp);
352
1
      if (status.ok()) {
353
1
        return Status::OK();
354
1
      }
355
356
0
      if (!status.IsLeaderHasNoLease() && !status.IsLeaderNotReadyToServe() &&
357
0
          !status.IsServiceUnavailable()) {
358
0
        return status;
359
0
      }
360
361
0
      auto timeout = deadline - CoarseMonoClock::now();
362
0
      if (timeout <= MonoDelta::kZero) {
363
0
        return status;
364
0
      }
365
366
0
      rpc.Reset();
367
0
      rpc.set_timeout(timeout);
368
0
      ResetMasterProxy();
369
0
    }
370
1
  }
yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::ListSnapshotRestorationsResponsePB, yb::tools::enterprise::ClusterAdminClient::ListSnapshots(yb::EnumBitSet<yb::tools::enterprise::ListSnapshotsFlag> const&)::$_1>(yb::master::ListSnapshotRestorationsResponsePB*, yb::tools::enterprise::ClusterAdminClient::ListSnapshots(yb::EnumBitSet<yb::tools::enterprise::ListSnapshotsFlag> const&)::$_1 const&)
Line
Count
Source
343
1
  CHECKED_STATUS RequestMasterLeader(Resp* resp, const F& f) {
344
1
    auto deadline = CoarseMonoClock::now() + timeout_;
345
1
    rpc::RpcController rpc;
346
1
    rpc.set_timeout(timeout_);
347
1
    for (;;) {
348
1
      resp->Clear();
349
1
      RETURN_NOT_OK(f(&rpc));
350
351
1
      auto status = ResponseStatus(*resp);
352
1
      if (status.ok()) {
353
1
        return Status::OK();
354
1
      }
355
356
0
      if (!status.IsLeaderHasNoLease() && !status.IsLeaderNotReadyToServe() &&
357
0
          !status.IsServiceUnavailable()) {
358
0
        return status;
359
0
      }
360
361
0
      auto timeout = deadline - CoarseMonoClock::now();
362
0
      if (timeout <= MonoDelta::kZero) {
363
0
        return status;
364
0
      }
365
366
0
      rpc.Reset();
367
0
      rpc.set_timeout(timeout);
368
0
      ResetMasterProxy();
369
0
    }
370
1
  }
yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::CreateSnapshotResponsePB, yb::tools::enterprise::ClusterAdminClient::CreateSnapshot(std::__1::vector<yb::client::YBTableName, std::__1::allocator<yb::client::YBTableName> > const&, bool, int)::$_2>(yb::master::CreateSnapshotResponsePB*, yb::tools::enterprise::ClusterAdminClient::CreateSnapshot(std::__1::vector<yb::client::YBTableName, std::__1::allocator<yb::client::YBTableName> > const&, bool, int)::$_2 const&)
Line
Count
Source
343
2
  CHECKED_STATUS RequestMasterLeader(Resp* resp, const F& f) {
344
2
    auto deadline = CoarseMonoClock::now() + timeout_;
345
2
    rpc::RpcController rpc;
346
2
    rpc.set_timeout(timeout_);
347
2
    for (;;) {
348
2
      resp->Clear();
349
2
      RETURN_NOT_OK(f(&rpc));
350
351
2
      auto status = ResponseStatus(*resp);
352
2
      if (status.ok()) {
353
2
        return Status::OK();
354
2
      }
355
356
0
      if (!status.IsLeaderHasNoLease() && !status.IsLeaderNotReadyToServe() &&
357
0
          !status.IsServiceUnavailable()) {
358
0
        return status;
359
0
      }
360
361
0
      auto timeout = deadline - CoarseMonoClock::now();
362
0
      if (timeout <= MonoDelta::kZero) {
363
0
        return status;
364
0
      }
365
366
0
      rpc.Reset();
367
0
      rpc.set_timeout(timeout);
368
0
      ResetMasterProxy();
369
0
    }
370
2
  }
Unexecuted instantiation: yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::ListTablesResponsePB, yb::tools::enterprise::ClusterAdminClient::CreateNamespaceSnapshot(yb::tools::TypedNamespaceName const&)::$_3>(yb::master::ListTablesResponsePB*, yb::tools::enterprise::ClusterAdminClient::CreateNamespaceSnapshot(yb::tools::TypedNamespaceName const&)::$_3 const&)
yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::ListSnapshotRestorationsResponsePB, yb::tools::enterprise::ClusterAdminClient::ListSnapshotRestorations(yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag> const&)::$_4>(yb::master::ListSnapshotRestorationsResponsePB*, yb::tools::enterprise::ClusterAdminClient::ListSnapshotRestorations(yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag> const&)::$_4 const&)
Line
Count
Source
343
5
  CHECKED_STATUS RequestMasterLeader(Resp* resp, const F& f) {
344
5
    auto deadline = CoarseMonoClock::now() + timeout_;
345
5
    rpc::RpcController rpc;
346
5
    rpc.set_timeout(timeout_);
347
5
    for (;;) {
348
5
      resp->Clear();
349
5
      RETURN_NOT_OK(f(&rpc));
350
351
5
      auto status = ResponseStatus(*resp);
352
5
      if (status.ok()) {
353
5
        return Status::OK();
354
5
      }
355
356
0
      if (!status.IsLeaderHasNoLease() && !status.IsLeaderNotReadyToServe() &&
357
0
          !status.IsServiceUnavailable()) {
358
0
        return status;
359
0
      }
360
361
0
      auto timeout = deadline - CoarseMonoClock::now();
362
0
      if (timeout <= MonoDelta::kZero) {
363
0
        return status;
364
0
      }
365
366
0
      rpc.Reset();
367
0
      rpc.set_timeout(timeout);
368
0
      ResetMasterProxy();
369
0
    }
370
5
  }
yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::CreateSnapshotScheduleResponsePB, yb::tools::enterprise::ClusterAdminClient::CreateSnapshotSchedule(yb::client::YBTableName const&, yb::MonoDelta, yb::MonoDelta)::$_5>(yb::master::CreateSnapshotScheduleResponsePB*, yb::tools::enterprise::ClusterAdminClient::CreateSnapshotSchedule(yb::client::YBTableName const&, yb::MonoDelta, yb::MonoDelta)::$_5 const&)
Line
Count
Source
343
8
  CHECKED_STATUS RequestMasterLeader(Resp* resp, const F& f) {
344
8
    auto deadline = CoarseMonoClock::now() + timeout_;
345
8
    rpc::RpcController rpc;
346
8
    rpc.set_timeout(timeout_);
347
8
    for (;;) {
348
8
      resp->Clear();
349
8
      RETURN_NOT_OK(f(&rpc));
350
351
8
      auto status = ResponseStatus(*resp);
352
8
      if (status.ok()) {
353
8
        return Status::OK();
354
8
      }
355
356
0
      if (!status.IsLeaderHasNoLease() && !status.IsLeaderNotReadyToServe() &&
357
0
          !status.IsServiceUnavailable()) {
358
0
        return status;
359
0
      }
360
361
0
      auto timeout = deadline - CoarseMonoClock::now();
362
0
      if (timeout <= MonoDelta::kZero) {
363
0
        return status;
364
0
      }
365
366
0
      rpc.Reset();
367
0
      rpc.set_timeout(timeout);
368
0
      ResetMasterProxy();
369
0
    }
370
8
  }
yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::ListSnapshotSchedulesResponsePB, yb::tools::enterprise::ClusterAdminClient::ListSnapshotSchedules(yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag> const&)::$_6>(yb::master::ListSnapshotSchedulesResponsePB*, yb::tools::enterprise::ClusterAdminClient::ListSnapshotSchedules(yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag> const&)::$_6 const&)
Line
Count
Source
343
8
  CHECKED_STATUS RequestMasterLeader(Resp* resp, const F& f) {
344
8
    auto deadline = CoarseMonoClock::now() + timeout_;
345
8
    rpc::RpcController rpc;
346
8
    rpc.set_timeout(timeout_);
347
8
    for (;;) {
348
8
      resp->Clear();
349
8
      RETURN_NOT_OK(f(&rpc));
350
351
8
      auto status = ResponseStatus(*resp);
352
8
      if (status.ok()) {
353
8
        return Status::OK();
354
8
      }
355
356
0
      if (!status.IsLeaderHasNoLease() && !status.IsLeaderNotReadyToServe() &&
357
0
          !status.IsServiceUnavailable()) {
358
0
        return status;
359
0
      }
360
361
0
      auto timeout = deadline - CoarseMonoClock::now();
362
0
      if (timeout <= MonoDelta::kZero) {
363
0
        return status;
364
0
      }
365
366
0
      rpc.Reset();
367
0
      rpc.set_timeout(timeout);
368
0
      ResetMasterProxy();
369
0
    }
370
8
  }
Unexecuted instantiation: yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::DeleteSnapshotScheduleResponsePB, yb::tools::enterprise::ClusterAdminClient::DeleteSnapshotSchedule(yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag> const&)::$_7>(yb::master::DeleteSnapshotScheduleResponsePB*, yb::tools::enterprise::ClusterAdminClient::DeleteSnapshotSchedule(yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag> const&)::$_7 const&)
Unexecuted instantiation: yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::RestoreSnapshotResponsePB, yb::tools::enterprise::ClusterAdminClient::RestoreSnapshot(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, yb::HybridTime)::$_8>(yb::master::RestoreSnapshotResponsePB*, yb::tools::enterprise::ClusterAdminClient::RestoreSnapshot(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, yb::HybridTime)::$_8 const&)
Unexecuted instantiation: yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::DeleteSnapshotResponsePB, yb::tools::enterprise::ClusterAdminClient::DeleteSnapshot(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_9>(yb::master::DeleteSnapshotResponsePB*, yb::tools::enterprise::ClusterAdminClient::DeleteSnapshot(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_9 const&)
Unexecuted instantiation: yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::ListSnapshotsResponsePB, yb::tools::enterprise::ClusterAdminClient::CreateSnapshotMetaFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_10>(yb::master::ListSnapshotsResponsePB*, yb::tools::enterprise::ClusterAdminClient::CreateSnapshotMetaFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_10 const&)
Unexecuted instantiation: yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::ImportSnapshotMetaResponsePB, yb::tools::enterprise::ClusterAdminClient::ImportSnapshotMetaFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, yb::tools::TypedNamespaceName const&, std::__1::vector<yb::client::YBTableName, std::__1::allocator<yb::client::YBTableName> > const&)::$_11>(yb::master::ImportSnapshotMetaResponsePB*, yb::tools::enterprise::ClusterAdminClient::ImportSnapshotMetaFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, yb::tools::TypedNamespaceName const&, std::__1::vector<yb::client::YBTableName, std::__1::allocator<yb::client::YBTableName> > const&)::$_11 const&)
Unexecuted instantiation: yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::CreateSnapshotResponsePB, yb::tools::enterprise::ClusterAdminClient::ImportSnapshotMetaFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, yb::tools::TypedNamespaceName const&, std::__1::vector<yb::client::YBTableName, std::__1::allocator<yb::client::YBTableName> > const&)::$_13>(yb::master::CreateSnapshotResponsePB*, yb::tools::enterprise::ClusterAdminClient::ImportSnapshotMetaFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, yb::tools::TypedNamespaceName const&, std::__1::vector<yb::client::YBTableName, std::__1::allocator<yb::client::YBTableName> > const&)::$_13 const&)
Unexecuted instantiation: yb-admin_client_ent.cc:yb::Status yb::tools::ClusterAdminClient::RequestMasterLeader<yb::master::GetTabletLocationsResponsePB, yb::tools::enterprise::ClusterAdminClient::ListReplicaTypeCounts(yb::client::YBTableName const&)::$_14>(yb::master::GetTabletLocationsResponsePB*, yb::tools::enterprise::ClusterAdminClient::ListReplicaTypeCounts(yb::client::YBTableName const&)::$_14 const&)
371
372
  void ResetMasterProxy(const HostPort& leader_addr = HostPort());
373
374
  std::string master_addr_list_;
375
  HostPort init_master_addr_;
376
  const MonoDelta timeout_;
377
  HostPort leader_addr_;
378
  std::unique_ptr<rpc::SecureContext> secure_context_;
379
  std::unique_ptr<rpc::Messenger> messenger_;
380
  std::unique_ptr<rpc::ProxyCache> proxy_cache_;
381
  std::unique_ptr<master::MasterAdminProxy> master_admin_proxy_;
382
  std::unique_ptr<master::MasterBackupProxy> master_backup_proxy_;
383
  std::unique_ptr<master::MasterClientProxy> master_client_proxy_;
384
  std::unique_ptr<master::MasterClusterProxy> master_cluster_proxy_;
385
  std::unique_ptr<master::MasterDdlProxy> master_ddl_proxy_;
386
  std::unique_ptr<master::MasterEncryptionProxy> master_encryption_proxy_;
387
  std::unique_ptr<master::MasterReplicationProxy> master_replication_proxy_;
388
389
  // Skip yb_client_ and related fields' initialization.
390
  std::unique_ptr<client::YBClient> yb_client_;
391
  bool initted_ = false;
392
393
 private:
394
395
  CHECKED_STATUS DiscoverAllMasters(
396
    const HostPort& init_master_addr, std::string* all_master_addrs);
397
398
  CHECKED_STATUS FillPlacementInfo(
399
      master::PlacementInfoPB* placement_info_pb, const std::string& placement_str);
400
401
  Result<int> GetReadReplicaConfigFromPlacementUuid(
402
      master::ReplicationInfoPB* replication_info, const std::string& placement_uuid);
403
404
405
  Result<master::GetMasterClusterConfigResponsePB> GetMasterClusterConfig();
406
407
  // Perform RPC call without checking Response structure for error
408
  template<class Response, class Request, class Object>
409
  Result<Response> InvokeRpcNoResponseCheck(
410
      Status (Object::*func)(const Request&, Response*, rpc::RpcController*) const,
411
      const Object& obj, const Request& req, const char* error_message = nullptr);
412
413
  // Perform RPC call by calling InvokeRpcNoResponseCheck
414
  // and check Response structure for error by using its has_error method (if any)
415
  template<class Response, class Request, class Object>
416
  Result<Response> InvokeRpc(
417
      Status (Object::*func)(const Request&, Response*, rpc::RpcController*) const,
418
      const Object& obj, const Request& req, const char* error_message = nullptr);
419
420
 private:
421
  using NamespaceMap = std::unordered_map<NamespaceId, master::NamespaceIdentifierPB>;
422
  Result<const NamespaceMap&> GetNamespaceMap();
423
424
  NamespaceMap namespace_map_;
425
426
  DISALLOW_COPY_AND_ASSIGN(ClusterAdminClient);
427
};
428
429
static constexpr const char* kColumnSep = " \t";
430
431
std::string RightPadToUuidWidth(const std::string &s);
432
433
Result<TypedNamespaceName> ParseNamespaceName(
434
    const std::string& full_namespace_name,
435
    const YQLDatabase default_if_no_prefix = YQL_DATABASE_CQL);
436
437
void AddStringField(
438
    const char* name, const std::string& value, rapidjson::Value* out,
439
    rapidjson::Value::AllocatorType* allocator);
440
441
// Renders hybrid time to string for user, time is rendered in local TZ.
442
std::string HybridTimeToString(HybridTime ht);
443
444
}  // namespace tools
445
}  // namespace yb
446
447
#endif // YB_TOOLS_YB_ADMIN_CLIENT_H