/Users/deen/code/yugabyte-db/src/yb/master/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_MASTER_H | 
| 33 |  | #define YB_MASTER_MASTER_H | 
| 34 |  |  | 
| 35 |  | #include <atomic> | 
| 36 |  | #include <memory> | 
| 37 |  | #include <string> | 
| 38 |  | #include <vector> | 
| 39 |  |  | 
| 40 |  | #include "yb/consensus/consensus.fwd.h" | 
| 41 |  | #include "yb/consensus/metadata.fwd.h" | 
| 42 |  |  | 
| 43 |  | #include "yb/gutil/thread_annotations.h" | 
| 44 |  | #include "yb/gutil/macros.h" | 
| 45 |  |  | 
| 46 |  | #include "yb/master/master_fwd.h" | 
| 47 |  | #include "yb/master/master_defaults.h" | 
| 48 |  | #include "yb/master/master_options.h" | 
| 49 |  | #include "yb/master/master_tserver.h" | 
| 50 |  | #include "yb/server/server_base.h" | 
| 51 |  | #include "yb/tserver/db_server_base.h" | 
| 52 |  | #include "yb/util/status_fwd.h" | 
| 53 |  |  | 
| 54 |  | namespace yb { | 
| 55 |  |  | 
| 56 |  | class MaintenanceManager; | 
| 57 |  | class RpcServer; | 
| 58 |  | class ServerEntryPB; | 
| 59 |  | class ThreadPool; | 
| 60 |  |  | 
| 61 |  | namespace server { | 
| 62 |  |  | 
| 63 |  | struct RpcServerOptions; | 
| 64 |  |  | 
| 65 |  | } | 
| 66 |  |  | 
| 67 |  | namespace master { | 
| 68 |  |  | 
| 69 |  | class Master : public tserver::DbServerBase { | 
| 70 |  |  public: | 
| 71 |  |   explicit Master(const MasterOptions& opts); | 
| 72 |  |   virtual ~Master(); | 
| 73 |  |  | 
| 74 |  |   CHECKED_STATUS Init(); | 
| 75 |  |   CHECKED_STATUS Start(); | 
| 76 |  |  | 
| 77 |  |   CHECKED_STATUS StartAsync(); | 
| 78 |  |   CHECKED_STATUS WaitForCatalogManagerInit(); | 
| 79 |  |  | 
| 80 |  |   // Wait until this Master's catalog manager instance is the leader and is ready. | 
| 81 |  |   // This method is intended for use by unit tests. | 
| 82 |  |   // If 'timeout' time is exceeded, returns Status::TimedOut. | 
| 83 |  |   CHECKED_STATUS WaitUntilCatalogManagerIsLeaderAndReadyForTests( | 
| 84 |  |     const MonoDelta& timeout = MonoDelta::FromSeconds(15)) | 
| 85 |  |       WARN_UNUSED_RESULT; | 
| 86 |  |  | 
| 87 |  |   void Shutdown(); | 
| 88 |  |  | 
| 89 |  |   std::string ToString() const override; | 
| 90 |  |  | 
| 91 | 1.83M |   TSManager* ts_manager() const { return ts_manager_.get(); } | 
| 92 |  |  | 
| 93 |  |   CatalogManagerIf* catalog_manager() const; | 
| 94 |  |  | 
| 95 | 12.4M |   enterprise::CatalogManager* catalog_manager_impl() const { return catalog_manager_.get(); } | 
| 96 |  |  | 
| 97 | 47 |   FlushManager* flush_manager() const { return flush_manager_.get(); } | 
| 98 |  |  | 
| 99 |  |   PermissionsManager& permissions_manager(); | 
| 100 |  |  | 
| 101 |  |   EncryptionManager& encryption_manager(); | 
| 102 |  |  | 
| 103 |  |   scoped_refptr<MetricEntity> metric_entity_cluster(); | 
| 104 |  |  | 
| 105 | 409 |   void SetMasterAddresses(std::shared_ptr<server::MasterAddresses> master_addresses) { | 
| 106 | 409 |     opts_.SetMasterAddresses(std::move(master_addresses)); | 
| 107 | 409 |   } | 
| 108 |  |  | 
| 109 | 5.34M |   const MasterOptions& opts() { return opts_; } | 
| 110 |  |  | 
| 111 |  |   // Get the RPC and HTTP addresses for this master instance. | 
| 112 |  |   CHECKED_STATUS GetMasterRegistration(ServerRegistrationPB* registration) const; | 
| 113 |  |  | 
| 114 |  |   // Get node instance, Raft role, RPC and HTTP addresses for all | 
| 115 |  |   // masters from the in-memory options used at master startup. | 
| 116 |  |   // TODO move this to a separate class to be re-used in TS and | 
| 117 |  |   // client; cache this information with a TTL (possibly in another | 
| 118 |  |   // SysTable), so that we don't have to perform an RPC call on every | 
| 119 |  |   // request. | 
| 120 |  |   CHECKED_STATUS ListMasters(std::vector<ServerEntryPB>* masters) const; | 
| 121 |  |  | 
| 122 |  |   // Get node instance, Raft role, RPC and HTTP addresses for all | 
| 123 |  |   // masters from the Raft config | 
| 124 |  |   CHECKED_STATUS ListRaftConfigMasters(std::vector<consensus::RaftPeerPB>* masters) const; | 
| 125 |  |  | 
| 126 |  |   CHECKED_STATUS InformRemovedMaster(const HostPortPB& hp_pb); | 
| 127 |  |  | 
| 128 | 167k |   bool IsShutdown() const { | 
| 129 | 167k |     return state_ == kStopped; | 
| 130 | 167k |   } | 
| 131 |  |  | 
| 132 | 5.35k |   MaintenanceManager* maintenance_manager() { | 
| 133 | 5.35k |     return maintenance_manager_.get(); | 
| 134 | 5.35k |   } | 
| 135 |  |  | 
| 136 |  |   // Recreates the master list based on the new config peers | 
| 137 |  |   CHECKED_STATUS ResetMemoryState(const consensus::RaftConfigPB& new_config); | 
| 138 |  |  | 
| 139 |  |   void DumpMasterOptionsInfo(std::ostream* out); | 
| 140 |  |  | 
| 141 | 6.15M |   bool IsShellMode() const { return opts_.IsShellMode(); } | 
| 142 |  |  | 
| 143 | 106 |   void SetShellMode(bool mode) { opts_.SetShellMode(mode); } | 
| 144 |  |  | 
| 145 |  |   // Not a full shutdown, but makes this master go into a dormant mode (state_ is still kRunning). | 
| 146 |  |   // Called currently by cluster master leader which is removing this master from the quorum. | 
| 147 |  |   CHECKED_STATUS GoIntoShellMode(); | 
| 148 |  |  | 
| 149 |  |   SysCatalogTable& sys_catalog() const; | 
| 150 |  |  | 
| 151 | 21.3k |   yb::client::AsyncClientInitialiser& async_client_initializer() { | 
| 152 | 21.3k |     return *async_client_init_; | 
| 153 | 21.3k |   } | 
| 154 |  |  | 
| 155 | 0 |   yb::client::AsyncClientInitialiser& cdc_state_client_initializer() { | 
| 156 | 0 |     return *cdc_state_client_init_; | 
| 157 | 0 |   } | 
| 158 |  |  | 
| 159 |  |   enum MasterMetricType { | 
| 160 |  |     TaskMetric, | 
| 161 |  |     AttemptMetric, | 
| 162 |  |   }; | 
| 163 |  |  | 
| 164 |  |   // Functon that returns a object pointer to a RPC's histogram metric. If a histogram | 
| 165 |  |   // metric pointer is not created, it will create a new object pointer and return it. | 
| 166 |  |   scoped_refptr<Histogram> GetMetric(const std::string& metric_identifier, | 
| 167 |  |                                      Master::MasterMetricType type, | 
| 168 |  |                                      const std::string& description); | 
| 169 |  |  | 
| 170 |  |   std::map<std::string, scoped_refptr<Histogram>>* master_metrics() | 
| 171 | 518k |     REQUIRES (master_metrics_mutex_) { | 
| 172 | 518k |       return &master_metrics_; | 
| 173 | 518k |   } | 
| 174 |  |  | 
| 175 |  |  protected: | 
| 176 |  |   virtual CHECKED_STATUS RegisterServices(); | 
| 177 |  |  | 
| 178 |  |   void DisplayGeneralInfoIcons(std::stringstream* output) override; | 
| 179 |  |  | 
| 180 |  |  private: | 
| 181 |  |   friend class MasterTest; | 
| 182 |  |  | 
| 183 |  |   void InitCatalogManagerTask(); | 
| 184 |  |   CHECKED_STATUS InitCatalogManager(); | 
| 185 |  |  | 
| 186 |  |   // Initialize registration_. | 
| 187 |  |   // Requires that the web server and RPC server have been started. | 
| 188 |  |   CHECKED_STATUS InitMasterRegistration(); | 
| 189 |  |  | 
| 190 |  |   const std::shared_future<client::YBClient*>& client_future() const override; | 
| 191 |  |  | 
| 192 |  |   client::LocalTabletFilter CreateLocalTabletFilter() override; | 
| 193 |  |  | 
| 194 |  |   enum MasterState { | 
| 195 |  |     kStopped, | 
| 196 |  |     kInitialized, | 
| 197 |  |     kRunning | 
| 198 |  |   }; | 
| 199 |  |  | 
| 200 |  |   MasterState state_; | 
| 201 |  |  | 
| 202 |  |   std::unique_ptr<TSManager> ts_manager_; | 
| 203 |  |   std::unique_ptr<enterprise::CatalogManager> catalog_manager_; | 
| 204 |  |   std::unique_ptr<MasterPathHandlers> path_handlers_; | 
| 205 |  |   std::unique_ptr<FlushManager> flush_manager_; | 
| 206 |  |  | 
| 207 |  |   // For initializing the catalog manager. | 
| 208 |  |   std::unique_ptr<ThreadPool> init_pool_; | 
| 209 |  |  | 
| 210 |  |   // The status of the master initialization. This is set | 
| 211 |  |   // by the async initialization task. | 
| 212 |  |   std::promise<Status> init_status_; | 
| 213 |  |   std::shared_future<Status> init_future_; | 
| 214 |  |  | 
| 215 |  |   MasterOptions opts_; | 
| 216 |  |  | 
| 217 |  |   AtomicUniquePtr<ServerRegistrationPB> registration_; | 
| 218 |  |  | 
| 219 |  |   // The maintenance manager for this master. | 
| 220 |  |   std::shared_ptr<MaintenanceManager> maintenance_manager_; | 
| 221 |  |  | 
| 222 |  |   // The metric entity for the cluster. | 
| 223 |  |   scoped_refptr<MetricEntity> metric_entity_cluster_; | 
| 224 |  |  | 
| 225 |  |   // Master's tablet server implementation used to host virtual tables like system.peers. | 
| 226 |  |   std::unique_ptr<MasterTabletServer> master_tablet_server_; | 
| 227 |  |  | 
| 228 |  |   std::unique_ptr<yb::client::AsyncClientInitialiser> async_client_init_; | 
| 229 |  |   std::unique_ptr<yb::client::AsyncClientInitialiser> cdc_state_client_init_; | 
| 230 |  |   std::mutex master_metrics_mutex_; | 
| 231 |  |   std::map<std::string, scoped_refptr<Histogram>> master_metrics_ GUARDED_BY(master_metrics_mutex_); | 
| 232 |  |  | 
| 233 |  |   DISALLOW_COPY_AND_ASSIGN(Master); | 
| 234 |  | }; | 
| 235 |  |  | 
| 236 |  | } // namespace master | 
| 237 |  | } // namespace yb | 
| 238 |  | #endif // YB_MASTER_MASTER_H |