/Users/deen/code/yugabyte-db/src/yb/server/server_base_options.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_SERVER_SERVER_BASE_OPTIONS_H |
33 | | #define YB_SERVER_SERVER_BASE_OPTIONS_H |
34 | | |
35 | | #include <string> |
36 | | #include <vector> |
37 | | #include <mutex> |
38 | | |
39 | | #include "yb/common/common_fwd.h" |
40 | | #include "yb/fs/fs_manager.h" |
41 | | #include "yb/server/webserver_options.h" |
42 | | #include "yb/server/rpc_server.h" |
43 | | #include "yb/util/net/net_util.h" |
44 | | |
45 | | namespace yb { |
46 | | |
47 | | class Env; |
48 | | |
49 | | namespace server { |
50 | | |
51 | | typedef std::vector<std::vector<HostPort>> MasterAddresses; |
52 | | typedef std::shared_ptr<const MasterAddresses> MasterAddressesPtr; |
53 | | |
54 | | // Options common to both types of servers. |
55 | | // The subclass constructor should fill these in with defaults from |
56 | | // server-specific flags. |
57 | | class ServerBaseOptions { |
58 | | public: |
59 | | Env* env; |
60 | | |
61 | | // This field is to be used as a path component for all the fs roots by FsManager. For now, we |
62 | | // expect it to be either master or tserver and passed in from the respective Server object. |
63 | | std::string server_type; |
64 | | |
65 | | FsManagerOpts fs_opts; |
66 | | RpcServerOptions rpc_opts; |
67 | | WebserverOptions webserver_opts; |
68 | | |
69 | | std::string dump_info_path; |
70 | | std::string dump_info_format; |
71 | | |
72 | | int32_t metrics_log_interval_ms; |
73 | | |
74 | | const std::string& placement_cloud() const; |
75 | | const std::string& placement_region() const; |
76 | | const std::string& placement_zone() const; |
77 | | |
78 | | bool has_placement_cloud() const; |
79 | | void SetPlacement(std::string cloud, std::string region, std::string zone); |
80 | | |
81 | | std::string placement_uuid; |
82 | | |
83 | | std::string master_addresses_flag; |
84 | | |
85 | | // The full unparsed string from FLAGS_server_broadcast_addresses. |
86 | | std::string server_broadcast_addresses; |
87 | | |
88 | | // The parsed version of server_broadcast_addresses. |
89 | | std::vector<HostPort> broadcast_addresses; |
90 | | |
91 | | // This can crash the process if you pass in an invalid list of master addresses! |
92 | 20.4k | void SetMasterAddresses(MasterAddressesPtr master_addresses) { |
93 | 20.4k | CHECK_NOTNULL(master_addresses.get()); |
94 | | |
95 | 20.4k | SetMasterAddressesNoValidation(std::move(master_addresses)); |
96 | 20.4k | } |
97 | | |
98 | | MasterAddressesPtr GetMasterAddresses() const; |
99 | | |
100 | | CloudInfoPB MakeCloudInfoPB() const; |
101 | | |
102 | | ServerBaseOptions(const ServerBaseOptions& options); |
103 | | |
104 | | WebserverOptions& CompleteWebserverOptions(); |
105 | | |
106 | | protected: |
107 | | explicit ServerBaseOptions(int default_port); |
108 | | |
109 | | private: |
110 | | void SetMasterAddressesNoValidation(MasterAddressesPtr master_addresses); |
111 | | |
112 | | // List of masters this server is aware of. This will get recreated on a master config change. |
113 | | // We should ensure that the vector elements are not individually updated. And the shared pointer |
114 | | // will guarantee inconsistent in-transit views of the vector are never seen during/across |
115 | | // config changes. |
116 | | MasterAddressesPtr master_addresses_; |
117 | | |
118 | | std::string placement_cloud_; |
119 | | std::string placement_region_; |
120 | | std::string placement_zone_; |
121 | | |
122 | | // Mutex to avoid concurrent access to the variable above. |
123 | | mutable std::mutex master_addresses_mtx_; |
124 | | }; |
125 | | |
126 | | CHECKED_STATUS DetermineMasterAddresses( |
127 | | const std::string& master_addresses_flag_name, const std::string& master_addresses_flag, |
128 | | uint64_t master_replication_factor, MasterAddresses* master_addresses, |
129 | | std::string* master_addresses_resolved_str); |
130 | | |
131 | | std::string MasterAddressesToString(const MasterAddresses& addresses); |
132 | | |
133 | | Result<std::vector<Endpoint>> ResolveMasterAddresses(const MasterAddresses& master_addresses); |
134 | | |
135 | | CloudInfoPB GetPlacementFromGFlags(); |
136 | | |
137 | | } // namespace server |
138 | | } // namespace yb |
139 | | |
140 | | #endif /* YB_SERVER_SERVER_BASE_OPTIONS_H */ |