YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/tserver/mini_tablet_server.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_TSERVER_MINI_TABLET_SERVER_H
33
#define YB_TSERVER_MINI_TABLET_SERVER_H
34
35
#include <string>
36
37
#include "yb/common/common_fwd.h"
38
#include "yb/common/common_types.pb.h"
39
40
#include "yb/encryption/encryption_fwd.h"
41
42
#include "yb/gutil/macros.h"
43
#include "yb/tablet/tablet_fwd.h"
44
#include "yb/tserver/tablet_server_options.h"
45
#include "yb/util/net/sockaddr.h"
46
#include "yb/util/status_fwd.h"
47
48
namespace yb {
49
50
class FsManager;
51
52
namespace consensus {
53
class RaftConfigPB;
54
} // namespace consensus
55
56
namespace tserver {
57
58
class TabletServer;
59
60
// An in-process tablet server meant for use in test cases.
61
class MiniTabletServer {
62
 public:
63
  static Result<std::unique_ptr<MiniTabletServer>> CreateMiniTabletServer(
64
      const std::string& fs_root,
65
      uint16_t rpc_port,
66
      int index = 0);
67
68
  MiniTabletServer(const std::vector<std::string>& wal_paths,
69
                   const std::vector<std::string>& data_paths,
70
                   uint16_t rpc_port,
71
                   const TabletServerOptions& extra_opts, int index = 0);
72
  MiniTabletServer(const std::string& fs_root, uint16_t rpc_port,
73
                   const TabletServerOptions& extra_opts, int index = 0);
74
  ~MiniTabletServer();
75
76
  // Return the options which will be used to start the tablet server.
77
  // If you wish to make changes to these options, they need to be made
78
  // before calling Start(), or else they will have no effect.
79
2.02k
  TabletServerOptions* options() { return &opts_; }
80
81
  // Start a tablet server running on the loopback interface and
82
  // an ephemeral port. To determine the address that the server
83
  // bound to, call MiniTabletServer::bound_addr().
84
  // The TS will be initialized asynchronously and then started.
85
  CHECKED_STATUS Start();
86
87
  // Waits for the tablet server to be fully initialized, including
88
  // having all tablets bootstrapped.
89
  CHECKED_STATUS WaitStarted();
90
91
  void Shutdown();
92
  CHECKED_STATUS FlushTablets(
93
      tablet::FlushMode mode = tablet::FlushMode::kSync,
94
      tablet::FlushFlags flags = tablet::FlushFlags::kAll);
95
  CHECKED_STATUS CompactTablets();
96
  CHECKED_STATUS SwitchMemtables();
97
  CHECKED_STATUS CleanTabletLogs();
98
99
  // Stop and start the tablet server on the same RPC and webserver ports. The tserver must be
100
  // running.
101
  CHECKED_STATUS Restart();
102
  CHECKED_STATUS RestartStoppedServer();
103
104
  // Add a new tablet to the test server, use the default consensus configuration.
105
  //
106
  // Requires that the server has already been started with Start().
107
  CHECKED_STATUS AddTestTablet(const std::string& ns_id,
108
                       const std::string& table_id,
109
                       const std::string& tablet_id,
110
                       const Schema& schema,
111
                       TableType table_type);
112
113
  // Add a new tablet to the test server and specify the consensus configuration
114
  // for the tablet.
115
  CHECKED_STATUS AddTestTablet(const std::string& ns_id,
116
                       const std::string& table_id,
117
                       const std::string& tablet_id,
118
                       const Schema& schema,
119
                       const consensus::RaftConfigPB& config,
120
                       TableType table_type);
121
122
  // Create a RaftConfigPB which should be used to create a local-only
123
  // tablet on the given tablet server.
124
  consensus::RaftConfigPB CreateLocalConfig() const;
125
126
  Endpoint bound_rpc_addr() const;
127
  Endpoint bound_http_addr() const;
128
  std::string bound_http_addr_str() const;
129
  std::string bound_rpc_addr_str() const;
130
131
0
  const TabletServer* server() const { return server_.get(); }
132
257
  TabletServer* server() { return server_.get(); }
133
134
0
  bool is_started() const { return started_; }
135
136
  void FailHeartbeats(bool fail_heartbeats_for_tests = true);
137
138
  // Close and disable all connections from this server to any other servers in the cluster.
139
  void Isolate();
140
  // Re-enable connections from this server to other servers in the cluster.
141
  CHECKED_STATUS Reconnect();
142
143
  FsManager& fs_manager() const;
144
145
 private:
146
  bool started_;
147
  TabletServerOptions opts_;
148
  int index_;
149
150
  std::unique_ptr<encryption::UniverseKeyManager> universe_key_manager_;
151
  std::unique_ptr<yb::Env> encrypted_env_;
152
  std::unique_ptr<rocksdb::Env> rocksdb_encrypted_env_;
153
  std::unique_ptr<TabletServer> server_;
154
  std::unique_ptr<Tunnel> tunnel_;
155
};
156
157
} // namespace tserver
158
} // namespace yb
159
160
#endif // YB_TSERVER_MINI_TABLET_SERVER_H