/Users/deen/code/yugabyte-db/src/yb/master/master-path-handlers.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_PATH_HANDLERS_H |
33 | | #define YB_MASTER_MASTER_PATH_HANDLERS_H |
34 | | |
35 | | #include <string> |
36 | | #include <sstream> |
37 | | #include <vector> |
38 | | |
39 | | #include "yb/common/wire_protocol.pb.h" |
40 | | #include "yb/gutil/macros.h" |
41 | | |
42 | | #include "yb/master/master_fwd.h" |
43 | | |
44 | | #include "yb/server/webserver.h" |
45 | | #include "yb/util/enums.h" |
46 | | |
47 | | namespace yb { |
48 | | |
49 | | class Schema; |
50 | | |
51 | | namespace master { |
52 | | |
53 | | static constexpr char kTserverAlive[] = "ALIVE"; |
54 | | static constexpr char kTserverDead[] = "DEAD"; |
55 | | |
56 | | class Master; |
57 | | struct TabletReplica; |
58 | | class TSDescriptor; |
59 | | class TSRegistrationPB; |
60 | | |
61 | | YB_DEFINE_ENUM(TServersViewType, (kTServersDefaultView)(kTServersClocksView)); |
62 | | |
63 | | // Web page support for the master. |
64 | | class MasterPathHandlers { |
65 | | public: |
66 | | explicit MasterPathHandlers(Master* master) |
67 | | : master_(master), |
68 | 5.45k | output_precision_(6) { |
69 | 5.45k | } |
70 | | |
71 | | ~MasterPathHandlers(); |
72 | | |
73 | | const std::string kYBOrange = "#f75821"; |
74 | | const std::string kYBDarkBlue = "#202951"; |
75 | | const std::string kYBLightBlue = "#3eb1cc"; |
76 | | const std::string kYBGray = "#5e647a"; |
77 | | |
78 | | const std::vector<std::string> kYBColorList = { |
79 | | "#30307F", "#36B8F5", |
80 | | "#BB43BC", "#43BFC2", "#90948E", |
81 | | "#1C7180", "#EEA95F", "#3590D9", |
82 | | "#F0679E", "#707B8E", "#800000", |
83 | | "#F08080", "#FF8C00", "#7CFC00", |
84 | | "#D2691E", "#696969", "#FFD700", |
85 | | "#B8860B", "#006400", "#FF6347" |
86 | | }; |
87 | | |
88 | | CHECKED_STATUS Register(Webserver* server); |
89 | | |
90 | | std::string BytesToHumanReadable (uint64_t bytes); |
91 | | |
92 | | private: |
93 | | enum TableType { |
94 | | kUserTable, |
95 | | kUserIndex, |
96 | | kColocatedParentTable, |
97 | | kSystemTable, |
98 | | kNumTypes, |
99 | | }; |
100 | | |
101 | | const std::string kSystemPlatformNamespace = "system_platform"; |
102 | | |
103 | | struct TabletCounts { |
104 | | uint32_t user_tablet_leaders = 0; |
105 | | uint32_t user_tablet_followers = 0; |
106 | | uint32_t system_tablet_leaders = 0; |
107 | | uint32_t system_tablet_followers = 0; |
108 | | |
109 | | void operator+=(const TabletCounts& other); |
110 | | }; |
111 | | |
112 | | // Struct used to store the number of nodes and tablets in an availability zone. |
113 | | struct ZoneTabletCounts { |
114 | | TabletCounts tablet_counts; |
115 | | uint32_t node_count = 1; |
116 | | uint32_t active_tablets_count; |
117 | | |
118 | 1 | ZoneTabletCounts() = default; |
119 | | |
120 | | // Create a ZoneTabletCounts object from the TabletCounts of a TServer (one node). |
121 | | ZoneTabletCounts(const TabletCounts& tablet_counts, uint32_t active_tablets_count); |
122 | | |
123 | | void operator+=(const ZoneTabletCounts& other); |
124 | | |
125 | | typedef std::map<std::string, ZoneTabletCounts> ZoneTree; |
126 | | typedef std::map<std::string, ZoneTree> RegionTree; |
127 | | typedef std::map<std::string, RegionTree> CloudTree; |
128 | | }; |
129 | | // Map of tserver UUID -> TabletCounts |
130 | | typedef std::unordered_map<std::string, TabletCounts> TabletCountMap; |
131 | | |
132 | | struct ReplicaInfo { |
133 | | PeerRole role; |
134 | | TabletId tablet_id; |
135 | | |
136 | 0 | ReplicaInfo(const PeerRole& role, const TabletId& tablet_id) { |
137 | 0 | this->role = role; |
138 | 0 | this->tablet_id = tablet_id; |
139 | 0 | } |
140 | | }; |
141 | | |
142 | | // Map of table id -> tablet list for a tserver. |
143 | | typedef std::unordered_map<std::string, std::vector<ReplicaInfo>> PerTServerTableTree; |
144 | | |
145 | | // Map of tserver UUID -> its table tree. |
146 | | typedef std::unordered_map<std::string, PerTServerTableTree> TServerTree; |
147 | | |
148 | | // Map of zone -> its tserver tree. |
149 | | typedef std::unordered_map<std::string, TServerTree> ZoneToTServer; |
150 | | |
151 | | const std::string table_type_[kNumTypes] = {"User", "Index", "Colocated", "System"}; |
152 | | |
153 | | const std::string kNoPlacementUUID = "NONE"; |
154 | | |
155 | | static inline void TServerTable(std::stringstream* output, TServersViewType viewType); |
156 | | |
157 | | void TServerDisplay(const std::string& current_uuid, |
158 | | std::vector<std::shared_ptr<TSDescriptor>>* descs, |
159 | | TabletCountMap* tmap, |
160 | | std::stringstream* output, |
161 | | const int hide_dead_node_threshold_override, |
162 | | TServersViewType viewType); |
163 | | |
164 | | // Outputs a ZoneTabletCounts::CloudTree as an html table with a heading. |
165 | | static void DisplayTabletZonesTable( |
166 | | const ZoneTabletCounts::CloudTree& counts, |
167 | | std::stringstream* output |
168 | | ); |
169 | | |
170 | | // Builds a "cloud -> region -> zone" tree of tablet and node counts. |
171 | | // Each leaf of the tree is a ZoneTabletCounts struct corresponding to the |
172 | | // unique availability zone identified by the path from the root to the leaf. |
173 | | ZoneTabletCounts::CloudTree CalculateTabletCountsTree( |
174 | | const std::vector<std::shared_ptr<TSDescriptor>>& descriptors, |
175 | | const TabletCountMap& tablet_count_map |
176 | | ); |
177 | | |
178 | | void CallIfLeaderOrPrintRedirect(const Webserver::WebRequest& req, Webserver::WebResponse* resp, |
179 | | const Webserver::PathHandlerCallback& callback); |
180 | | void RedirectToLeader(const Webserver::WebRequest& req, Webserver::WebResponse* resp); |
181 | | void RootHandler(const Webserver::WebRequest& req, |
182 | | Webserver::WebResponse* resp); |
183 | | void HandleTabletServers(const Webserver::WebRequest& req, |
184 | | Webserver::WebResponse* resp, |
185 | | TServersViewType viewType); |
186 | | void HandleCatalogManager(const Webserver::WebRequest& req, |
187 | | Webserver::WebResponse* resp, |
188 | | bool only_user_tables = false); |
189 | | void HandleTablePage(const Webserver::WebRequest& req, |
190 | | Webserver::WebResponse* resp); |
191 | | void HandleTasksPage(const Webserver::WebRequest& req, |
192 | | Webserver::WebResponse* resp); |
193 | | void HandleTabletReplicasPage(const Webserver::WebRequest &req, Webserver::WebResponse *resp); |
194 | | void HandleMasters(const Webserver::WebRequest& req, |
195 | | Webserver::WebResponse* resp); |
196 | | void HandleDumpEntities(const Webserver::WebRequest& req, |
197 | | Webserver::WebResponse* resp); |
198 | | void HandleGetTserverStatus(const Webserver::WebRequest& req, |
199 | | Webserver::WebResponse* resp); |
200 | | void HandleGetClusterConfig(const Webserver::WebRequest& req, Webserver::WebResponse* resp); |
201 | | void HandleGetClusterConfigJSON(const Webserver::WebRequest& req, Webserver::WebResponse* resp); |
202 | | void HandleHealthCheck(const Webserver::WebRequest& req, Webserver::WebResponse* resp); |
203 | | void HandleCheckIfLeader(const Webserver::WebRequest& req, Webserver::WebResponse* resp); |
204 | | void HandleGetMastersStatus(const Webserver::WebRequest& req, Webserver::WebResponse* resp); |
205 | | void HandleGetReplicationStatus(const Webserver::WebRequest &req, Webserver::WebResponse *resp); |
206 | | void HandleGetUnderReplicationStatus(const Webserver::WebRequest &req, |
207 | | Webserver::WebResponse *resp); |
208 | | void HandleVersionInfoDump(const Webserver::WebRequest &req, Webserver::WebResponse *resp); |
209 | | void HandlePrettyLB(const Webserver::WebRequest& req, Webserver::WebResponse* resp); |
210 | | |
211 | | // Calcuates number of leaders/followers per table. |
212 | | void CalculateTabletMap(TabletCountMap* tablet_map); |
213 | | |
214 | | CHECKED_STATUS CalculateTServerTree(TServerTree* tserver_tree); |
215 | | |
216 | | std::vector<TabletInfoPtr> GetNonSystemTablets(); |
217 | | |
218 | | std::vector<TabletInfoPtr> GetLeaderlessTablets(); |
219 | | |
220 | | Result<std::vector<TabletInfoPtr>> GetUnderReplicatedTablets(); |
221 | | |
222 | | // Calculates the YSQL OID of a tablegroup / colocated database parent table |
223 | | std::string GetParentTableOid(scoped_refptr<TableInfo> parent_table); |
224 | | |
225 | | // Convert location of peers to HTML, indicating the roles |
226 | | // of each tablet server in a consensus configuration. |
227 | | // This method will display 'locations' in the order given. |
228 | | std::string RaftConfigToHtml(const std::vector<TabletReplica>& locations, |
229 | | const std::string& tablet_id) const; |
230 | | |
231 | | // Convert the specified TSDescriptor to HTML, adding a link to the |
232 | | // tablet server's own webserver if specified in 'desc'. |
233 | | std::string TSDescriptorToHtml(const TSDescriptor& desc, |
234 | | const std::string& tablet_id) const; |
235 | | |
236 | | // Convert the specified server registration to HTML, adding a link |
237 | | // to the server's own web server (if specified in 'reg') with |
238 | | // anchor text 'link_text'. |
239 | | std::string RegistrationToHtml( |
240 | | const ServerRegistrationPB& reg, const std::string& link_text) const; |
241 | | |
242 | | std::string GetHttpHostPortFromServerRegistration(const ServerRegistrationPB& reg) const; |
243 | | |
244 | | Master* master_; |
245 | | |
246 | | const int output_precision_; |
247 | | DISALLOW_COPY_AND_ASSIGN(MasterPathHandlers); |
248 | | }; |
249 | | |
250 | | void HandleTabletServersPage(const Webserver::WebRequest& req, Webserver::WebResponse* resp); |
251 | | |
252 | | } // namespace master |
253 | | } // namespace yb |
254 | | #endif /* YB_MASTER_MASTER_PATH_HANDLERS_H */ |