YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/integration-tests/ts_itest-base.h
Line
Count
Source
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_INTEGRATION_TESTS_TS_ITEST_BASE_H
33
#define YB_INTEGRATION_TESTS_TS_ITEST_BASE_H
34
35
#include "yb/integration-tests/cluster_itest_util.h"
36
37
#include "yb/tserver/tablet_server-test-base.h"
38
39
#include "yb/client/table_handle.h"
40
41
#include "yb/util/random.h"
42
43
DECLARE_double(leader_failure_max_missed_heartbeat_periods);
44
DECLARE_int32(consensus_rpc_timeout_ms);
45
DECLARE_int32(num_tablet_servers);
46
DECLARE_int32(num_replicas);
47
48
#define ASSERT_ALL_REPLICAS_AGREE(count) \
49
11
  ASSERT_NO_FATALS(AssertAllReplicasAgree(count))
50
51
namespace yb {
52
53
class ExternalMiniCluster;
54
struct ExternalMiniClusterOptions;
55
56
namespace itest {
57
58
class ExternalMiniClusterFsInspector;
59
60
}
61
62
namespace tserver {
63
64
static const int kMaxRetries = 20;
65
66
// A base for tablet server integration tests.
67
class TabletServerIntegrationTestBase : public TabletServerTestBase {
68
 public:
69
  TabletServerIntegrationTestBase();
70
  ~TabletServerIntegrationTestBase();
71
72
  void AddExtraFlags(const std::string& flags_str, std::vector<std::string>* flags);
73
74
  void CreateCluster(const std::string& data_root_path,
75
                     const std::vector<std::string>& non_default_ts_flags = {},
76
                     const std::vector<std::string>& non_default_master_flags = {});
77
78
47
  virtual void UpdateMiniClusterOptions(ExternalMiniClusterOptions* options) {}
79
80
  // Creates TSServerDetails instance for each TabletServer and stores them
81
  // in 'tablet_servers_'.
82
  void CreateTSProxies();
83
84
  // Waits that all replicas for a all tablets of 'kTableName' table are online
85
  // and creates the tablet_replicas_ map.
86
  void WaitForReplicasAndUpdateLocations();
87
88
  // Returns the last committed leader of the consensus configuration. Tries to get it from master
89
  // but then actually tries to the get the committed consensus configuration to make sure.
90
  itest::TServerDetails* GetLeaderReplicaOrNull(const std::string& tablet_id);
91
92
  CHECKED_STATUS GetLeaderReplicaWithRetries(const std::string& tablet_id,
93
                                             itest::TServerDetails** leader,
94
                                             int max_attempts = 100);
95
96
  CHECKED_STATUS GetTabletLeaderUUIDFromMaster(const std::string& tablet_id,
97
                                               std::string* leader_uuid);
98
99
  itest::TServerDetails* GetReplicaWithUuidOrNull(const std::string& tablet_id,
100
                                                  const std::string& uuid);
101
102
  // Gets the locations of the consensus configuration and waits until all replicas
103
  // are available for all tablets.
104
  void WaitForTSAndReplicas();
105
106
  // Removes a set of servers from the replicas_ list.
107
  // Handy for controlling who to validate against after killing servers.
108
  void PruneFromReplicas(const std::unordered_set<std::string>& uuids);
109
110
  void GetOnlyLiveFollowerReplicas(const std::string& tablet_id,
111
                                   std::vector<itest::TServerDetails*>* followers);
112
113
  // Return the index within 'replicas' for the replica which is farthest ahead.
114
  int64_t GetFurthestAheadReplicaIdx(const std::string& tablet_id,
115
                                     const std::vector<itest::TServerDetails*>& replicas);
116
117
  CHECKED_STATUS ShutdownServerWithUUID(const std::string& uuid);
118
119
  CHECKED_STATUS RestartServerWithUUID(const std::string& uuid);
120
121
  // Since we're fault-tolerant we might mask when a tablet server is
122
  // dead. This returns Status::IllegalState() if fewer than 'num_tablet_servers'
123
  // are alive.
124
  CHECKED_STATUS CheckTabletServersAreAlive(size_t num_tablet_servers);
125
126
  void TearDown() override;
127
128
  Result<std::unique_ptr<client::YBClient>> CreateClient();
129
130
  // Create a table with a single tablet.
131
  void CreateTable();
132
133
  // Starts an external cluster with a single tablet and a number of replicas equal
134
  // to 'FLAGS_num_replicas'. The caller can pass 'ts_flags' to specify non-default
135
  // flags to pass to the tablet servers.
136
  void BuildAndStart(const std::vector<std::string>& ts_flags = std::vector<std::string>(),
137
                     const std::vector<std::string>& master_flags = std::vector<std::string>());
138
139
  void AssertAllReplicasAgree(size_t expected_result_count);
140
141
  client::YBTableType table_type();
142
143
 protected:
144
  std::unique_ptr<ExternalMiniCluster> cluster_;
145
  std::unique_ptr<itest::ExternalMiniClusterFsInspector> inspect_;
146
147
  // Maps server uuid to TServerDetails
148
  itest::TabletServerMap tablet_servers_;
149
  // Maps tablet to all replicas.
150
  itest::TabletReplicaMap tablet_replicas_;
151
152
  std::unique_ptr<client::YBClient> client_;
153
  client::TableHandle table_;
154
  std::string tablet_id_;
155
156
  ThreadSafeRandom random_;
157
};
158
159
}  // namespace tserver
160
}  // namespace yb
161
162
#endif /* YB_INTEGRATION_TESTS_TS_ITEST_BASE_H */