/Users/deen/code/yugabyte-db/src/yb/common/wire_protocol.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 | | // Helpers for dealing with the protobufs defined in wire_protocol.proto. |
33 | | #ifndef YB_COMMON_WIRE_PROTOCOL_H |
34 | | #define YB_COMMON_WIRE_PROTOCOL_H |
35 | | |
36 | | #include <vector> |
37 | | |
38 | | #include "yb/common/common_fwd.h" |
39 | | |
40 | | #include <google/protobuf/repeated_field.h> |
41 | | |
42 | | #include "yb/gutil/endian.h" |
43 | | |
44 | | #include "yb/util/status_fwd.h" |
45 | | #include "yb/util/cast.h" |
46 | | #include "yb/util/enums.h" |
47 | | #include "yb/util/math_util.h" |
48 | | #include "yb/util/net/net_fwd.h" |
49 | | #include "yb/util/status_ec.h" |
50 | | #include "yb/util/type_traits.h" |
51 | | #include "yb/util/result.h" |
52 | | |
53 | | namespace yb { |
54 | | |
55 | | class ConstContiguousRow; |
56 | | class ColumnId; |
57 | | class ColumnSchema; |
58 | | class faststring; |
59 | | class HostPort; |
60 | | class RowChangeList; |
61 | | class Schema; |
62 | | class Slice; |
63 | | |
64 | | // Convert the given C++ Status object into the equivalent Protobuf. |
65 | | void StatusToPB(const Status& status, AppStatusPB* pb); |
66 | | |
67 | | // Convert the given protobuf into the equivalent C++ Status object. |
68 | | Status StatusFromPB(const AppStatusPB& pb); |
69 | | |
70 | | // Convert the specified HostPort to protobuf. |
71 | | void HostPortToPB(const HostPort& host_port, HostPortPB* host_port_pb); |
72 | | |
73 | | // Returns the HostPort created from the specified protobuf. |
74 | | HostPort HostPortFromPB(const HostPortPB& host_port_pb); |
75 | | |
76 | | bool HasHostPortPB( |
77 | | const google::protobuf::RepeatedPtrField<HostPortPB>& list, const HostPortPB& hp); |
78 | | |
79 | | // Returns an Endpoint from HostPortPB. |
80 | | CHECKED_STATUS EndpointFromHostPortPB(const HostPortPB& host_portpb, Endpoint* endpoint); |
81 | | |
82 | | // Adds addresses in 'addrs' to 'pbs'. If an address is a wildcard (e.g., "0.0.0.0"), |
83 | | // then the local machine's FQDN or its network interface address is used in its place. |
84 | | CHECKED_STATUS AddHostPortPBs(const std::vector<Endpoint>& addrs, |
85 | | google::protobuf::RepeatedPtrField<HostPortPB>* pbs); |
86 | | |
87 | | // Simply convert the list of host ports into a repeated list of corresponding PB's. |
88 | | void HostPortsToPBs(const std::vector<HostPort>& addrs, |
89 | | google::protobuf::RepeatedPtrField<HostPortPB>* pbs); |
90 | | |
91 | | // Convert list of HostPortPBs into host ports. |
92 | | void HostPortsFromPBs(const google::protobuf::RepeatedPtrField<HostPortPB>& pbs, |
93 | | std::vector<HostPort>* addrs); |
94 | | |
95 | | enum SchemaPBConversionFlags { |
96 | | SCHEMA_PB_WITHOUT_IDS = 1 << 0, |
97 | | }; |
98 | | |
99 | | // Convert the specified schema to protobuf. |
100 | | // 'flags' is a bitfield of SchemaPBConversionFlags values. |
101 | | void SchemaToPB(const Schema& schema, SchemaPB* pb, int flags = 0); |
102 | | |
103 | | // Convert the specified schema to protobuf without column IDs. |
104 | | void SchemaToPBWithoutIds(const Schema& schema, SchemaPB *pb); |
105 | | |
106 | | // Returns the Schema created from the specified protobuf. |
107 | | // If the schema is invalid, return a non-OK status. |
108 | | Status SchemaFromPB(const SchemaPB& pb, Schema *schema); |
109 | | |
110 | | // Convert the specified column schema to protobuf. |
111 | | // 'flags' is a bitfield of SchemaPBConversionFlags values. |
112 | | void ColumnSchemaToPB(const ColumnSchema& schema, ColumnSchemaPB *pb, int flags = 0); |
113 | | |
114 | | // Return the ColumnSchema created from the specified protobuf. |
115 | | ColumnSchema ColumnSchemaFromPB(const ColumnSchemaPB& pb); |
116 | | |
117 | | // Convert the given list of ColumnSchemaPB objects into a Schema object. |
118 | | // |
119 | | // Returns InvalidArgument if the provided columns don't make a valid Schema |
120 | | // (eg if the keys are non-contiguous or nullable). |
121 | | Status ColumnPBsToSchema( |
122 | | const google::protobuf::RepeatedPtrField<ColumnSchemaPB>& column_pbs, |
123 | | Schema* schema); |
124 | | |
125 | | // Returns the required information from column pbs to build the column part of SchemaPB. |
126 | | CHECKED_STATUS ColumnPBsToColumnTuple( |
127 | | const google::protobuf::RepeatedPtrField<ColumnSchemaPB>& column_pbs, |
128 | | std::vector<ColumnSchema>* columns , std::vector<ColumnId>* column_ids, int* num_key_columns); |
129 | | |
130 | | // Extract the columns of the given Schema into protobuf objects. |
131 | | // |
132 | | // The 'cols' list is replaced by this method. |
133 | | // 'flags' is a bitfield of SchemaPBConversionFlags values. |
134 | | void SchemaToColumnPBs( |
135 | | const Schema& schema, |
136 | | google::protobuf::RepeatedPtrField<ColumnSchemaPB>* cols, |
137 | | int flags = 0); |
138 | | |
139 | | // Extract the colocated table information of the given schema into a protobuf object. |
140 | | void SchemaToColocatedTableIdentifierPB( |
141 | | const Schema& schema, ColocatedTableIdentifierPB* colocated_pb); |
142 | | |
143 | | YB_DEFINE_ENUM(UsePrivateIpMode, (cloud)(region)(zone)(never)); |
144 | | |
145 | | // Returns mode for selecting between private and public IP. |
146 | | Result<UsePrivateIpMode> GetPrivateIpMode(); |
147 | | |
148 | | // Pick node's public host and port |
149 | | // registration - node registration information |
150 | | const HostPortPB& PublicHostPort(const ServerRegistrationPB& registration); |
151 | | |
152 | | // Pick host and port that should be used to connect node |
153 | | // broadcast_addresses - node public host ports |
154 | | // private_host_ports - node private host ports |
155 | | // connect_to - node placement information |
156 | | // connect_from - placement information of connect originator |
157 | | const HostPortPB& DesiredHostPort( |
158 | | const google::protobuf::RepeatedPtrField<HostPortPB>& broadcast_addresses, |
159 | | const google::protobuf::RepeatedPtrField<HostPortPB>& private_host_ports, |
160 | | const CloudInfoPB& connect_to, |
161 | | const CloudInfoPB& connect_from); |
162 | | |
163 | | // Pick host and port that should be used to connect node |
164 | | // registration - node registration information |
165 | | // connect_from - placement information of connect originator |
166 | | const HostPortPB& DesiredHostPort( |
167 | | const ServerRegistrationPB& registration, const CloudInfoPB& connect_from); |
168 | | |
169 | | HAS_MEMBER_FUNCTION(error); |
170 | | HAS_MEMBER_FUNCTION(status); |
171 | | |
172 | | template<class Response> |
173 | | CHECKED_STATUS ResponseStatus( |
174 | | const Response& response, |
175 | 10.3M | typename std::enable_if<HasMemberFunction_error<Response>::value, void*>::type = nullptr) { |
176 | | // Response has has_error method, use status from it. |
177 | 10.3M | if (response.has_error()) { |
178 | 12.0k | return StatusFromPB(response.error().status()); |
179 | 12.0k | } |
180 | 10.2M | return Status::OK(); |
181 | 10.2M | } |
182 | | |
183 | | template<class Response> |
184 | | CHECKED_STATUS ResponseStatus( |
185 | | const Response& response, |
186 | | typename std::enable_if<HasMemberFunction_status<Response>::value && |
187 | 1.00M | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { |
188 | 1.00M | if (response.has_status()) { |
189 | 53.6k | return StatusFromPB(response.status()); |
190 | 53.6k | } |
191 | 948k | return Status::OK(); |
192 | 948k | } _ZN2yb14ResponseStatusINS_7tserver21PgHeartbeatResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 2.74k | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 2.74k | if (response.has_status()) { | 189 | 0 | return StatusFromPB(response.status()); | 190 | 0 | } | 191 | 2.74k | return Status::OK(); | 192 | 2.74k | } |
_ZN2yb14ResponseStatusINS_7tserver21PgOpenTableResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 64.6k | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 64.6k | if (response.has_status()) { | 189 | 37 | return StatusFromPB(response.status()); | 190 | 37 | } | 191 | 64.5k | return Status::OK(); | 192 | 64.5k | } |
_ZN2yb14ResponseStatusINS_7tserver29PgFinishTransactionResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 82.4k | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 82.4k | if (response.has_status()) { | 189 | 6.77k | return StatusFromPB(response.status()); | 190 | 6.77k | } | 191 | 75.6k | return Status::OK(); | 192 | 75.6k | } |
_ZN2yb14ResponseStatusINS_7tserver27PgGetDatabaseInfoResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 1.61k | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 1.61k | if (response.has_status()) { | 189 | 0 | return StatusFromPB(response.status()); | 190 | 0 | } | 191 | 1.61k | return Status::OK(); | 192 | 1.61k | } |
_ZN2yb14ResponseStatusINS_7tserver23PgReserveOidsResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 380 | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 380 | if (response.has_status()) { | 189 | 0 | return StatusFromPB(response.status()); | 190 | 0 | } | 191 | 380 | return Status::OK(); | 192 | 380 | } |
Unexecuted instantiation: _ZN2yb14ResponseStatusINS_7tserver24PgIsInitDbDoneResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Unexecuted instantiation: _ZN2yb14ResponseStatusINS_7tserver35PgGetCatalogMasterVersionResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE _ZN2yb14ResponseStatusINS_7tserver36PgCreateSequencesDataTableResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 21 | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 21 | if (response.has_status()) { | 189 | 0 | return StatusFromPB(response.status()); | 190 | 0 | } | 191 | 21 | return Status::OK(); | 192 | 21 | } |
_ZN2yb14ResponseStatusINS_7tserver21PgDropTableResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 1.17k | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 1.17k | if (response.has_status()) { | 189 | 2 | return StatusFromPB(response.status()); | 190 | 2 | } | 191 | 1.17k | return Status::OK(); | 192 | 1.17k | } |
_ZN2yb14ResponseStatusINS_7tserver25PgBackfillIndexResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 89 | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 89 | if (response.has_status()) { | 189 | 1 | return StatusFromPB(response.status()); | 190 | 1 | } | 191 | 88 | return Status::OK(); | 192 | 88 | } |
_ZN2yb14ResponseStatusINS_7tserver29PgTabletServerCountResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 57 | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 57 | if (response.has_status()) { | 189 | 0 | return StatusFromPB(response.status()); | 190 | 0 | } | 191 | 57 | return Status::OK(); | 192 | 57 | } |
_ZN2yb14ResponseStatusINS_7tserver33PgListLiveTabletServersResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 2 | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 2 | if (response.has_status()) { | 189 | 0 | return StatusFromPB(response.status()); | 190 | 0 | } | 191 | 2 | return Status::OK(); | 192 | 2 | } |
_ZN2yb14ResponseStatusINS_7tserver35PgSetActiveSubTransactionResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 48.8k | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 48.8k | if (response.has_status()) { | 189 | 0 | return StatusFromPB(response.status()); | 190 | 0 | } | 191 | 48.8k | return Status::OK(); | 192 | 48.8k | } |
_ZN2yb14ResponseStatusINS_7tserver34PgRollbackSubTransactionResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 23.5k | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 23.5k | if (response.has_status()) { | 189 | 0 | return StatusFromPB(response.status()); | 190 | 0 | } | 191 | 23.5k | return Status::OK(); | 192 | 23.5k | } |
Unexecuted instantiation: _ZN2yb14ResponseStatusINS_7tserver29PgValidatePlacementResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE _ZN2yb14ResponseStatusINS_7tserver19PgPerformResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 775k | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 775k | if (response.has_status()) { | 189 | 46.7k | return StatusFromPB(response.status()); | 190 | 46.7k | } | 191 | 728k | return Status::OK(); | 192 | 728k | } |
Unexecuted instantiation: _ZN2yb14ResponseStatusINS_7tserver25PgAlterDatabaseResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE _ZN2yb14ResponseStatusINS_7tserver22PgAlterTableResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 155 | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 155 | if (response.has_status()) { | 189 | 1 | return StatusFromPB(response.status()); | 190 | 1 | } | 191 | 154 | return Status::OK(); | 192 | 154 | } |
_ZN2yb14ResponseStatusINS_7tserver26PgCreateDatabaseResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 22 | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 22 | if (response.has_status()) { | 189 | 1 | return StatusFromPB(response.status()); | 190 | 1 | } | 191 | 21 | return Status::OK(); | 192 | 21 | } |
_ZN2yb14ResponseStatusINS_7tserver23PgCreateTableResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 1.41k | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 1.41k | if (response.has_status()) { | 189 | 4 | return StatusFromPB(response.status()); | 190 | 4 | } | 191 | 1.41k | return Status::OK(); | 192 | 1.41k | } |
_ZN2yb14ResponseStatusINS_7tserver28PgCreateTablegroupResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 1 | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 1 | if (response.has_status()) { | 189 | 0 | return StatusFromPB(response.status()); | 190 | 0 | } | 191 | 1 | return Status::OK(); | 192 | 1 | } |
_ZN2yb14ResponseStatusINS_7tserver24PgDropDatabaseResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 21 | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 21 | if (response.has_status()) { | 189 | 1 | return StatusFromPB(response.status()); | 190 | 1 | } | 191 | 20 | return Status::OK(); | 192 | 20 | } |
_ZN2yb14ResponseStatusINS_7tserver26PgDropTablegroupResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 1 | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 1 | if (response.has_status()) { | 189 | 0 | return StatusFromPB(response.status()); | 190 | 0 | } | 191 | 1 | return Status::OK(); | 192 | 1 | } |
_ZN2yb14ResponseStatusINS_7tserver25PgTruncateTableResponsePBEEENS_6StatusERKT_NSt3__19enable_ifIXaasr24HasMemberFunction_statusIS4_EE5valuentsr23HasMemberFunction_errorIS4_EE5valueEPvE4typeE Line | Count | Source | 187 | 31 | !HasMemberFunction_error<Response>::value, void*>::type = nullptr) { | 188 | 31 | if (response.has_status()) { | 189 | 0 | return StatusFromPB(response.status()); | 190 | 0 | } | 191 | 31 | return Status::OK(); | 192 | 31 | } |
|
193 | | |
194 | | struct SplitChildTabletIdsTag : yb::StringVectorBackedErrorTag { |
195 | | // It is part of the wire protocol and should not be changed once released. |
196 | | static constexpr uint8_t kCategory = 14; |
197 | | |
198 | | static std::string ToMessage(Value value); |
199 | | }; |
200 | | |
201 | | typedef yb::StatusErrorCodeImpl<SplitChildTabletIdsTag> SplitChildTabletIdsData; |
202 | | |
203 | | } // namespace yb |
204 | | |
205 | | #endif // YB_COMMON_WIRE_PROTOCOL_H |