YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/master/mini_master.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_MASTER_MINI_MASTER_H
33
#define YB_MASTER_MINI_MASTER_H
34
35
#include <string>
36
#include <vector>
37
38
#include "yb/gutil/macros.h"
39
#include "yb/gutil/port.h"
40
41
#include "yb/master/master_fwd.h"
42
43
#include "yb/rpc/rpc_fwd.h"
44
45
#include "yb/tablet/tablet_fwd.h"
46
47
#include "yb/util/status_fwd.h"
48
#include "yb/util/env.h"
49
#include "yb/util/net/net_fwd.h"
50
51
namespace yb {
52
53
class FsManager;
54
class HostPort;
55
56
namespace master {
57
58
// An in-process Master meant for use in test cases.
59
//
60
// TODO: Store the distributed cluster configuration in the object, to avoid
61
// having multiple Start methods.
62
class MiniMaster {
63
 public:
64
  MiniMaster(Env* env, std::string fs_root, uint16_t rpc_port, uint16_t web_port, int index);
65
  ~MiniMaster();
66
67
  // Start a master running on the loopback interface and
68
  // an ephemeral port. To determine the address that the server
69
  // bound to, call MiniMaster::bound_addr()
70
  CHECKED_STATUS Start(bool TEST_simulate_fs_create_failure = false);
71
72
0
  void set_pass_master_addresses(bool value) {
73
0
    pass_master_addresses_ = value;
74
0
  }
75
76
  CHECKED_STATUS StartDistributedMaster(const std::vector<uint16_t>& peer_ports);
77
78
  CHECKED_STATUS WaitForCatalogManagerInit();
79
80
  CHECKED_STATUS WaitUntilCatalogManagerIsLeaderAndReadyForTests();
81
82
  void Shutdown();
83
84
  // Restart the master on the same ports as it was previously bound.
85
  // Requires that the master is currently started.
86
  CHECKED_STATUS Restart();
87
88
  HostPort bound_rpc_addr() const;
89
  Endpoint bound_http_addr() const;
90
91
0
  const Master* master() const { return master_.get(); }
92
502k
  Master* master() { return master_.get(); }
93
94
  rpc::Messenger& messenger() const;
95
96
  CatalogManagerIf& catalog_manager() const;
97
98
  CatalogManager& catalog_manager_impl() const;
99
100
  tablet::TabletPeerPtr tablet_peer() const;
101
102
  master::SysCatalogTable& sys_catalog() const;
103
104
  master::TSManager& ts_manager() const;
105
106
  master::FlushManager& flush_manager() const;
107
108
  // Return UUID of this mini master.
109
  std::string permanent_uuid() const;
110
111
  std::string bound_rpc_addr_str() const;
112
113
  FsManager& fs_manager() const;
114
115
 private:
116
  CHECKED_STATUS StartDistributedMasterOnPorts(uint16_t rpc_port, uint16_t web_port,
117
                                       const std::vector<uint16_t>& peer_ports);
118
119
  CHECKED_STATUS StartOnPorts(uint16_t rpc_port, uint16_t web_port);
120
121
  CHECKED_STATUS StartOnPorts(uint16_t rpc_port, uint16_t web_port,
122
                      MasterOptions* options);
123
124
  bool running_;
125
126
  ATTRIBUTE_MEMBER_UNUSED Env* const env_;
127
  const std::string fs_root_;
128
  const uint16_t rpc_port_, web_port_;
129
130
  std::unique_ptr<Master> master_;
131
  int index_;
132
  std::unique_ptr<Tunnel> tunnel_;
133
  bool pass_master_addresses_ = true;
134
};
135
136
} // namespace master
137
} // namespace yb
138
139
#endif /* YB_MASTER_MINI_MASTER_H */