YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/client/tablet_server.h
Line
Count
Source
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 <string>
15
#ifndef YB_CLIENT_TABLET_SERVER_H
16
#define YB_CLIENT_TABLET_SERVER_H
17
18
namespace yb {
19
namespace client {
20
21
// In-memory representation of a remote tablet server.
22
struct YBTabletServer {
23
  std::string uuid;
24
  std::string hostname;
25
  std::string placement_uuid;
26
27
  template <class PB, class CloudInfo>
28
18
  static YBTabletServer FromPB(const PB& pb, const CloudInfo& cloud_info) {
29
18
    return YBTabletServer {
30
18
      .uuid = pb.instance_id().permanent_uuid(),
31
18
      .hostname = DesiredHostPort(pb.registration().common(), cloud_info).host(),
32
18
      .placement_uuid = pb.registration().common().placement_uuid(),
33
18
    };
34
18
  }
yb::client::YBTabletServer yb::client::YBTabletServer::FromPB<yb::master::ListTabletServersResponsePB_Entry, yb::CloudInfoPB>(yb::master::ListTabletServersResponsePB_Entry const&, yb::CloudInfoPB const&)
Line
Count
Source
28
6
  static YBTabletServer FromPB(const PB& pb, const CloudInfo& cloud_info) {
29
6
    return YBTabletServer {
30
6
      .uuid = pb.instance_id().permanent_uuid(),
31
6
      .hostname = DesiredHostPort(pb.registration().common(), cloud_info).host(),
32
6
      .placement_uuid = pb.registration().common().placement_uuid(),
33
6
    };
34
6
  }
yb::client::YBTabletServer yb::client::YBTabletServer::FromPB<yb::master::ListLiveTabletServersResponsePB_Entry, yb::CloudInfoPB>(yb::master::ListLiveTabletServersResponsePB_Entry const&, yb::CloudInfoPB const&)
Line
Count
Source
28
12
  static YBTabletServer FromPB(const PB& pb, const CloudInfo& cloud_info) {
29
12
    return YBTabletServer {
30
12
      .uuid = pb.instance_id().permanent_uuid(),
31
12
      .hostname = DesiredHostPort(pb.registration().common(), cloud_info).host(),
32
12
      .placement_uuid = pb.registration().common().placement_uuid(),
33
12
    };
34
12
  }
35
36
  template <class PB>
37
12
  static YBTabletServer FromPB(const PB& pb) {
38
12
    return YBTabletServer {
39
12
      .uuid = pb.uuid(),
40
12
      .hostname = pb.hostname(),
41
12
      .placement_uuid = pb.placement_uuid(),
42
12
    };
43
12
  }
44
45
  template <class PB>
46
12
  void ToPB(PB* pb) const {
47
12
    pb->set_uuid(uuid);
48
12
    pb->set_hostname(hostname);
49
12
    pb->set_placement_uuid(placement_uuid);
50
12
  }
51
};
52
53
struct YBTabletServerPlacementInfo {
54
  YBTabletServer server;
55
  std::string cloud;
56
  std::string region;
57
  std::string zone;
58
  bool is_primary;
59
  std::string public_ip;
60
  uint16_t pg_port;
61
62
  template <class PB>
63
12
  static YBTabletServerPlacementInfo FromPB(const PB& pb) {
64
12
    return YBTabletServerPlacementInfo {
65
12
      .server = YBTabletServer::FromPB(pb),
66
12
      .cloud = pb.cloud(),
67
12
      .region = pb.region(),
68
12
      .zone = pb.zone(),
69
12
      .is_primary = pb.is_primary(),
70
12
      .public_ip = pb.public_ip(),
71
12
      .pg_port = static_cast<uint16_t>(pb.pg_port()),
72
12
    };
73
12
  }
74
75
  template <class PB>
76
12
  void ToPB(PB* pb) const {
77
12
    server.ToPB(pb);
78
12
    pb->set_cloud(cloud);
79
12
    pb->set_region(region);
80
12
    pb->set_zone(zone);
81
12
    pb->set_is_primary(is_primary);
82
12
    pb->set_public_ip(public_ip);
83
12
    pb->set_pg_port(pg_port);
84
12
  }
85
};
86
87
} // namespace client
88
} // namespace yb
89
90
#endif // YB_CLIENT_TABLET_SERVER_H