/Users/deen/code/yugabyte-db/src/yb/master/master_tserver.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include "yb/master/master_tserver.h" |
15 | | |
16 | | #include <map> |
17 | | #include <set> |
18 | | |
19 | | #include <boost/preprocessor/cat.hpp> |
20 | | #include <boost/preprocessor/stringize.hpp> |
21 | | |
22 | | #include "yb/client/async_initializer.h" |
23 | | |
24 | | #include "yb/master/catalog_manager_if.h" |
25 | | #include "yb/master/master.h" |
26 | | #include "yb/master/scoped_leader_shared_lock.h" |
27 | | #include "yb/master/sys_catalog_constants.h" |
28 | | |
29 | | #include "yb/tablet/tablet_peer.h" |
30 | | |
31 | | #include "yb/tserver/tserver.pb.h" |
32 | | |
33 | | #include "yb/util/atomic.h" |
34 | | #include "yb/util/metric_entity.h" |
35 | | #include "yb/util/monotime.h" |
36 | | #include "yb/util/status_format.h" |
37 | | |
38 | | namespace yb { |
39 | | namespace master { |
40 | | |
41 | | using consensus::StartRemoteBootstrapRequestPB; |
42 | | |
43 | | MasterTabletServer::MasterTabletServer(Master* master, scoped_refptr<MetricEntity> metric_entity) |
44 | 8.07k | : master_(master), metric_entity_(metric_entity) { |
45 | 8.07k | } |
46 | | |
47 | 0 | tserver::TSTabletManager* MasterTabletServer::tablet_manager() { |
48 | 0 | return nullptr; |
49 | 0 | } |
50 | | |
51 | 554k | tserver::TabletPeerLookupIf* MasterTabletServer::tablet_peer_lookup() { |
52 | 554k | return this; |
53 | 554k | } |
54 | | |
55 | 6.44M | server::Clock* MasterTabletServer::Clock() { |
56 | 6.44M | return master_->clock(); |
57 | 6.44M | } |
58 | | |
59 | 8.03k | const scoped_refptr<MetricEntity>& MasterTabletServer::MetricEnt() const { |
60 | 8.03k | return metric_entity_; |
61 | 8.03k | } |
62 | | |
63 | | Status MasterTabletServer::GetTabletPeer(const string& tablet_id, |
64 | 554k | std::shared_ptr<tablet::TabletPeer>* tablet_peer) const { |
65 | 554k | if (tablet_id == kSysCatalogTabletId) { |
66 | 554k | *tablet_peer = master_->catalog_manager()->tablet_peer(); |
67 | 554k | return Status::OK(); |
68 | 554k | } |
69 | 133 | return STATUS_FORMAT(NotFound, "tablet $0 not found", tablet_id); |
70 | 554k | } |
71 | | |
72 | | Status MasterTabletServer::GetTabletStatus(const tserver::GetTabletStatusRequestPB* req, |
73 | 0 | tserver::GetTabletStatusResponsePB* resp) const { |
74 | 0 | std::shared_ptr<tablet::TabletPeer> tablet_peer; |
75 | | // Tablets for YCQL virtual tables have no peer and we will return the NotFound status. That is |
76 | | // ok because GetTabletStatus is called for the cases when a tablet is moved or otherwise down |
77 | | // and being boostrapped, which should not happen to those tables. |
78 | 0 | RETURN_NOT_OK(GetTabletPeer(req->tablet_id(), &tablet_peer)); |
79 | 0 | tablet_peer->GetTabletStatusPB(resp->mutable_tablet_status()); |
80 | 0 | return Status::OK(); |
81 | 0 | } |
82 | | |
83 | 0 | bool MasterTabletServer::LeaderAndReady(const TabletId& tablet_id, bool allow_stale) const { |
84 | 0 | std::shared_ptr<tablet::TabletPeer> tablet_peer; |
85 | 0 | if (!GetTabletPeer(tablet_id, &tablet_peer).ok()) { |
86 | 0 | return false; |
87 | 0 | } |
88 | 0 | return tablet_peer->LeaderStatus(allow_stale) == consensus::LeaderStatus::LEADER_AND_READY; |
89 | 0 | } |
90 | | |
91 | 0 | const NodeInstancePB& MasterTabletServer::NodeInstance() const { |
92 | 0 | return master_->catalog_manager()->NodeInstance(); |
93 | 0 | } |
94 | | |
95 | 0 | Status MasterTabletServer::GetRegistration(ServerRegistrationPB* reg) const { |
96 | 0 | return STATUS(NotSupported, "Getting tserver registration not supported by master tserver"); |
97 | 0 | } |
98 | | |
99 | 0 | Status MasterTabletServer::StartRemoteBootstrap(const StartRemoteBootstrapRequestPB& req) { |
100 | 0 | return STATUS(NotSupported, "Remote bootstrap not supported by master tserver"); |
101 | 0 | } |
102 | | |
103 | | void MasterTabletServer::get_ysql_catalog_version(uint64_t* current_version, |
104 | 4.84k | uint64_t* last_breaking_version) const { |
105 | 4.84k | auto fill_vers = [current_version, last_breaking_version](){ |
106 | | /* |
107 | | * This should never happen, but if it does then we cannot guarantee that user requests |
108 | | * received by this master's tserver interface have a compatible version. |
109 | | * Log an error and return the highest possible version to ensure we reject the request if |
110 | | * it needs a catalog version compatibility check. |
111 | | */ |
112 | 1 | if (current_version) { |
113 | 0 | *current_version = UINT64_MAX; |
114 | 0 | } |
115 | 1 | if (last_breaking_version) { |
116 | 1 | *last_breaking_version = UINT64_MAX; |
117 | 1 | } |
118 | 1 | }; |
119 | | // Ensure that we are currently the Leader before handling catalog version. |
120 | 4.84k | { |
121 | 4.84k | SCOPED_LEADER_SHARED_LOCK(l, master_->catalog_manager_impl()); |
122 | 4.84k | if (!l.catalog_status().ok()) { |
123 | 0 | LOG(WARNING) << "Catalog status failure: " << l.catalog_status().ToString(); |
124 | 0 | fill_vers(); |
125 | 0 | return; |
126 | 0 | } |
127 | 4.84k | if (!l.leader_status().ok()) { |
128 | 1 | LOG(WARNING) << "Leader status failure: " << l.leader_status().ToString(); |
129 | 1 | fill_vers(); |
130 | 1 | return; |
131 | 1 | } |
132 | 4.84k | } |
133 | | |
134 | 4.84k | Status s = master_->catalog_manager()->GetYsqlCatalogVersion(current_version, |
135 | 4.84k | last_breaking_version); |
136 | 4.84k | if (!s.ok()) { |
137 | 0 | LOG(ERROR) << "Could not get YSQL catalog version for master's tserver API: " |
138 | 0 | << s.ToUserMessage(); |
139 | 0 | fill_vers(); |
140 | 0 | } |
141 | 4.84k | } |
142 | | |
143 | 0 | tserver::TServerSharedData& MasterTabletServer::SharedObject() { |
144 | 0 | return master_->shared_object(); |
145 | 0 | } |
146 | | |
147 | 0 | const std::shared_future<client::YBClient*>& MasterTabletServer::client_future() const { |
148 | 0 | return master_->async_client_initializer().get_client_future(); |
149 | 0 | } |
150 | | |
151 | | CHECKED_STATUS MasterTabletServer::GetLiveTServers( |
152 | 0 | std::vector<master::TSInformationPB> *live_tservers) const { |
153 | 0 | return Status::OK(); |
154 | 0 | } |
155 | | |
156 | 0 | const std::shared_ptr<MemTracker>& MasterTabletServer::mem_tracker() const { |
157 | 0 | return master_->mem_tracker(); |
158 | 0 | } |
159 | | |
160 | 0 | void MasterTabletServer::SetPublisher(rpc::Publisher service) { |
161 | 0 | } |
162 | | |
163 | | } // namespace master |
164 | | } // namespace yb |