YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
5.45k
    : master_(master), metric_entity_(metric_entity) {
45
5.45k
}
46
47
0
tserver::TSTabletManager* MasterTabletServer::tablet_manager() {
48
0
  return nullptr;
49
0
}
50
51
175k
tserver::TabletPeerLookupIf* MasterTabletServer::tablet_peer_lookup() {
52
175k
  return this;
53
175k
}
54
55
2.66M
server::Clock* MasterTabletServer::Clock() {
56
2.66M
  return master_->clock();
57
2.66M
}
58
59
5.42k
const scoped_refptr<MetricEntity>& MasterTabletServer::MetricEnt() const {
60
5.42k
  return metric_entity_;
61
5.42k
}
62
63
Status MasterTabletServer::GetTabletPeer(const string& tablet_id,
64
175k
                                         std::shared_ptr<tablet::TabletPeer>* tablet_peer) const {
65
175k
  if (tablet_id == kSysCatalogTabletId) {
66
175k
    *tablet_peer = master_->catalog_manager()->tablet_peer();
67
175k
    return Status::OK();
68
175k
  }
69
92
  return STATUS_FORMAT(NotFound, "tablet $0 not found", tablet_id);
70
92
}
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
1.38k
                                                  uint64_t* last_breaking_version) const {
105
0
  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
0
    if (current_version) {
113
0
      *current_version = UINT64_MAX;
114
0
    }
115
0
    if (last_breaking_version) {
116
0
      *last_breaking_version = UINT64_MAX;
117
0
    }
118
0
  };
119
  // Ensure that we are currently the Leader before handling catalog version.
120
1.38k
  {
121
1.38k
    SCOPED_LEADER_SHARED_LOCK(l, master_->catalog_manager_impl());
122
1.38k
    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
1.38k
    if (!l.leader_status().ok()) {
128
0
      LOG(WARNING) << "Leader status failure: " << l.leader_status().ToString();
129
0
      fill_vers();
130
0
      return;
131
0
    }
132
1.38k
  }
133
134
1.38k
  Status s = master_->catalog_manager()->GetYsqlCatalogVersion(current_version,
135
1.38k
                                                               last_breaking_version);
136
1.38k
  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
1.38k
}
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