YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/common/wire_protocol.cc
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
#include "yb/common/wire_protocol.h"
33
34
#include <string>
35
#include <vector>
36
37
#include "yb/common/common.pb.h"
38
#include "yb/common/ql_type.h"
39
#include "yb/common/schema.h"
40
#include "yb/common/wire_protocol.pb.h"
41
42
#include "yb/gutil/port.h"
43
#include "yb/gutil/stl_util.h"
44
#include "yb/gutil/strings/fastmem.h"
45
#include "yb/gutil/strings/substitute.h"
46
#include "yb/util/enums.h"
47
#include "yb/util/errno.h"
48
#include "yb/util/faststring.h"
49
#include "yb/util/logging.h"
50
#include "yb/util/net/net_util.h"
51
#include "yb/util/net/sockaddr.h"
52
#include "yb/util/result.h"
53
#include "yb/util/slice.h"
54
#include "yb/util/status_format.h"
55
#include "yb/yql/cql/ql/util/errcodes.h"
56
57
using google::protobuf::RepeatedPtrField;
58
using std::vector;
59
60
DEFINE_string(use_private_ip, "never",
61
              "When to use private IP for connection. "
62
              "cloud - would use private IP if destination node is located in the same cloud. "
63
              "region - would use private IP if destination node is located in the same cloud and "
64
                  "region. "
65
              "zone - would use private IP if destination node is located in the same cloud, "
66
                  "region and zone."
67
              "never - would never use private IP if broadcast address is specified.");
68
namespace yb {
69
70
namespace {
71
72
YB_STRONGLY_TYPED_BOOL(PublicAddressAllowed);
73
74
template <class Index, class Value>
75
void SetAt(
76
531k
    Index index, const Value& value, const Value& default_value, std::vector<Value>* vector) {
77
531k
  size_t int_index = static_cast<size_t>(index);
78
531k
  size_t new_size = vector->size();
79
633k
  while (new_size <= int_index) {
80
102k
    new_size = std::max<size_t>(1, new_size * 2);
81
102k
  }
82
531k
  vector->resize(new_size, default_value);
83
531k
  (*vector)[int_index] = value;
84
531k
}
85
86
17.1k
std::vector<AppStatusPB::ErrorCode> CreateStatusToErrorCode() {
87
17.1k
  std::vector<AppStatusPB::ErrorCode> result;
88
17.1k
  const auto default_value = AppStatusPB::UNKNOWN_ERROR;
89
17.1k
  #define YB_STATUS_CODE(name, pb_name, value, message) \
90
531k
    SetAt(Status::BOOST_PP_CAT(k, name), AppStatusPB::pb_name, default_value, &result); \
91
531k
    static_assert( \
92
531k
        static_cast<int32_t>(to_underlying(AppStatusPB::pb_name)) == \
93
531k
            to_underlying(Status::BOOST_PP_CAT(k, name)), \
94
531k
        "The numeric value of AppStatusPB::" BOOST_PP_STRINGIZE(pb_name) " defined in" \
95
531k
            " wire_protocol.proto does not match the value of Status::k" BOOST_PP_STRINGIZE(name) \
96
531k
            " defined in status.h.");
97
17.1k
  #include "yb/util/status_codes.h"
98
17.1k
  #undef YB_STATUS_CODE
99
17.1k
  return result;
100
17.1k
}
101
102
const std::vector<AppStatusPB::ErrorCode> kStatusToErrorCode = CreateStatusToErrorCode();
103
104
17.1k
std::vector<Status::Code> CreateErrorCodeToStatus() {
105
17.1k
  size_t max_index = 0;
106
548k
  for (const auto error_code : kStatusToErrorCode) {
107
548k
    if (error_code == AppStatusPB::UNKNOWN_ERROR) {
108
17.1k
      continue;
109
17.1k
    }
110
531k
    max_index = std::max(max_index, static_cast<size_t>(error_code));
111
531k
  }
112
113
17.1k
  std::vector<Status::Code> result(max_index + 1);
114
565k
  for (size_t int_code = 0; int_code != kStatusToErrorCode.size(); ++int_code) {
115
548k
    if (kStatusToErrorCode[int_code] == AppStatusPB::UNKNOWN_ERROR) {
116
17.1k
      continue;
117
17.1k
    }
118
531k
    result[static_cast<size_t>(kStatusToErrorCode[int_code])] = static_cast<Status::Code>(int_code);
119
531k
  }
120
121
17.1k
  return result;
122
17.1k
}
123
124
const std::vector<Status::Code> kErrorCodeToStatus = CreateErrorCodeToStatus();
125
126
const HostPortPB& GetHostPort(
127
    const google::protobuf::RepeatedPtrField<HostPortPB>& broadcast_addresses,
128
    const google::protobuf::RepeatedPtrField<HostPortPB>& private_host_ports,
129
586k
    PublicAddressAllowed public_address_allowed) {
130
586k
  if (!broadcast_addresses.empty() && public_address_allowed) {
131
4.54k
    return broadcast_addresses[0];
132
4.54k
  }
133
581k
  if (!private_host_ports.empty()) {
134
581k
    return private_host_ports[0];
135
581k
  }
136
83
  static const HostPortPB empty_host_port;
137
83
  return empty_host_port;
138
83
}
139
140
} // namespace
141
142
863k
void StatusToPB(const Status& status, AppStatusPB* pb) {
143
863k
  pb->Clear();
144
145
863k
  if (status.ok()) {
146
1
    pb->set_code(AppStatusPB::OK);
147
    // OK statuses don't have any message or posix code.
148
1
    return;
149
1
  }
150
151
863k
  auto code = static_cast<size_t>(status.code()) < kStatusToErrorCode.size()
152
862k
      ? kStatusToErrorCode[status.code()] : AppStatusPB::UNKNOWN_ERROR;
153
863k
  pb->set_code(code);
154
863k
  if (code == AppStatusPB::UNKNOWN_ERROR) {
155
0
    LOG(WARNING) << "Unknown error code translation connect_from internal error "
156
0
                 << status << ": sending UNKNOWN_ERROR";
157
    // For unknown status codes, include the original stringified error
158
    // code.
159
0
    pb->set_message(status.CodeAsString() + ": " + status.message().ToBuffer());
160
863k
  } else {
161
    // Otherwise, just encode the message itself, since the other end
162
    // will reconstruct the other parts of the ToString() response.
163
863k
    pb->set_message(status.message().cdata(), status.message().size());
164
863k
  }
165
166
863k
  auto error_codes = status.ErrorCodesSlice();
167
863k
  pb->set_errors(error_codes.data(), error_codes.size());
168
  // We always has 0 as terminating byte for error codes, so non empty error codes would have
169
  // more than one bytes.
170
863k
  if (error_codes.size() > 1) {
171
    // Set old protobuf fields for backward compatibility.
172
355k
    Errno err(status);
173
355k
    if (err != 0) {
174
8
      pb->set_posix_code(err.value());
175
8
    }
176
355k
    const auto* ql_error_data = status.ErrorData(ql::QLError::kCategory);
177
355k
    if (ql_error_data) {
178
0
      pb->set_ql_error_code(static_cast<int64_t>(ql::QLErrorTag::Decode(ql_error_data)));
179
0
    }
180
355k
  }
181
182
863k
  pb->set_source_file(status.file_name());
183
863k
  pb->set_source_line(status.line_number());
184
863k
}
185
186
struct WireProtocolTabletServerErrorTag {
187
  static constexpr uint8_t kCategory = 5;
188
189
  enum Value {};
190
191
0
  static size_t EncodedSize(Value value) {
192
0
    return sizeof(Value);
193
0
  }
194
195
0
  static uint8_t* Encode(Value value, uint8_t* out) {
196
0
    Store<Value, LittleEndian>(out, value);
197
0
    return out + sizeof(Value);
198
0
  }
199
};
200
201
// Backward compatibility.
202
0
Status StatusFromOldPB(const AppStatusPB& pb) {
203
0
  auto code = kErrorCodeToStatus[pb.code()];
204
205
0
  auto status_factory = [code, &pb](const Slice& errors) {
206
0
    return Status(
207
0
        code, pb.source_file().c_str(), pb.source_line(), pb.message(), errors, DupFileName::kTrue);
208
0
  };
209
210
0
  #define ENCODE_ERROR_AND_RETURN_STATUS(Tag, value) \
211
0
    auto error_code = static_cast<Tag::Value>((value)); \
212
0
    auto size = 2 + Tag::EncodedSize(error_code); \
213
0
    uint8_t* buffer = static_cast<uint8_t*>(alloca(size)); \
214
0
    buffer[0] = Tag::kCategory; \
215
0
    Tag::Encode(error_code, buffer + 1); \
216
0
    buffer[size - 1] = 0; \
217
0
    return status_factory(Slice(buffer, size)); \
218
    /**/
219
220
0
  if (code == Status::kQLError) {
221
0
    if (!pb.has_ql_error_code()) {
222
0
      return STATUS(InternalError, "Query error code missing");
223
0
    }
224
225
0
    ENCODE_ERROR_AND_RETURN_STATUS(ql::QLErrorTag, pb.ql_error_code())
226
0
  } else if (pb.has_posix_code()) {
227
0
    if (code == Status::kIllegalState || code == Status::kLeaderNotReadyToServe ||
228
0
        code == Status::kLeaderHasNoLease) {
229
230
0
      ENCODE_ERROR_AND_RETURN_STATUS(WireProtocolTabletServerErrorTag, pb.posix_code())
231
0
    } else {
232
0
      ENCODE_ERROR_AND_RETURN_STATUS(ErrnoTag, pb.posix_code())
233
0
    }
234
0
  }
235
236
0
  return Status(code, pb.source_file().c_str(), pb.source_line(), pb.message(), "",
237
0
                nullptr /* error */, DupFileName::kTrue);
238
0
  #undef ENCODE_ERROR_AND_RETURN_STATUS
239
0
}
240
241
343k
Status StatusFromPB(const AppStatusPB& pb) {
242
343k
  if (pb.code() == AppStatusPB::OK) {
243
1
    return Status::OK();
244
343k
  } else if (pb.code() == AppStatusPB::UNKNOWN_ERROR ||
245
342k
             static_cast<size_t>(pb.code()) >= kErrorCodeToStatus.size()) {
246
0
    LOG(WARNING) << "Unknown error code in status: " << pb.ShortDebugString();
247
0
    return STATUS_FORMAT(
248
0
        RuntimeError, "($0 unknown): $1", pb.code(), pb.message());
249
0
  }
250
251
343k
  if (pb.has_errors()) {
252
342k
    return Status(kErrorCodeToStatus[pb.code()], pb.source_file().c_str(), pb.source_line(),
253
342k
                  pb.message(), pb.errors(), DupFileName::kTrue);
254
342k
  }
255
256
252
  return StatusFromOldPB(pb);
257
252
}
258
259
62.8k
void HostPortToPB(const HostPort& host_port, HostPortPB* host_port_pb) {
260
62.8k
  host_port_pb->set_host(host_port.host());
261
62.8k
  host_port_pb->set_port(host_port.port());
262
62.8k
}
263
264
761k
HostPort HostPortFromPB(const HostPortPB& host_port_pb) {
265
761k
  HostPort host_port;
266
761k
  host_port.set_host(host_port_pb.host());
267
761k
  host_port.set_port(host_port_pb.port());
268
761k
  return host_port;
269
761k
}
270
271
bool HasHostPortPB(
272
20
    const google::protobuf::RepeatedPtrField<HostPortPB>& list, const HostPortPB& hp) {
273
12
  for (const auto& i : list) {
274
12
    if (i.host() == hp.host() && i.port() == hp.port()) {
275
4
      return true;
276
4
    }
277
12
  }
278
16
  return false;
279
20
}
280
281
0
Status EndpointFromHostPortPB(const HostPortPB& host_portpb, Endpoint* endpoint) {
282
0
  HostPort host_port = HostPortFromPB(host_portpb);
283
0
  return EndpointFromHostPort(host_port, endpoint);
284
0
}
285
286
107k
void HostPortsToPBs(const std::vector<HostPort>& addrs, RepeatedPtrField<HostPortPB>* pbs) {
287
62.7k
  for (const auto& addr : addrs) {
288
62.7k
    HostPortToPB(addr, pbs->Add());
289
62.7k
  }
290
107k
}
291
292
2
void HostPortsFromPBs(const RepeatedPtrField<HostPortPB>& pbs, std::vector<HostPort>* addrs) {
293
2
  addrs->reserve(pbs.size());
294
2
  for (const auto& pb : pbs) {
295
2
    addrs->push_back(HostPortFromPB(pb));
296
2
  }
297
2
}
298
299
Status AddHostPortPBs(const std::vector<Endpoint>& addrs,
300
107
                      RepeatedPtrField<HostPortPB>* pbs) {
301
108
  for (const auto& addr : addrs) {
302
108
    HostPortPB* pb = pbs->Add();
303
108
    pb->set_port(addr.port());
304
108
    if (addr.address().is_unspecified()) {
305
0
      VLOG(4) << " Asked to add unspecified address: " << addr.address();
306
2
      auto status = GetFQDN(pb->mutable_host());
307
2
      if (!status.ok()) {
308
0
        std::vector<IpAddress> locals;
309
0
        if (!GetLocalAddresses(FLAGS_net_address_filter, &locals).ok() ||
310
0
            locals.empty()) {
311
0
          return status;
312
0
        }
313
0
        for (auto& address : locals) {
314
0
          if (pb == nullptr) {
315
0
            pb = pbs->Add();
316
0
            pb->set_port(addr.port());
317
0
          }
318
0
          pb->set_host(address.to_string());
319
0
          VLOG(4) << "Adding local address: " << pb->host();
320
0
          pb = nullptr;
321
0
        }
322
2
      } else {
323
0
        VLOG(4) << "Adding FQDN " << pb->host();
324
2
      }
325
106
    } else {
326
106
      pb->set_host(addr.address().to_string());
327
0
      VLOG(4) << "Adding specific address: " << pb->host();
328
106
    }
329
108
  }
330
107
  return Status::OK();
331
107
}
332
333
void SchemaToColocatedTableIdentifierPB(
334
140M
    const Schema& schema, ColocatedTableIdentifierPB* colocated_pb) {
335
140M
  if (schema.has_pgtable_id()) {
336
1.30k
    colocated_pb->set_pgtable_id(schema.pgtable_id());
337
140M
  } else if (schema.has_cotable_id()) {
338
139M
    colocated_pb->set_cotable_id(schema.cotable_id().ToString());
339
139M
  }
340
341
140M
}
342
343
140M
void SchemaToPB(const Schema& schema, SchemaPB *pb, int flags) {
344
140M
  pb->Clear();
345
140M
  SchemaToColocatedTableIdentifierPB(schema, pb->mutable_colocated_table_id());
346
140M
  SchemaToColumnPBs(schema, pb->mutable_columns(), flags);
347
140M
  schema.table_properties().ToTablePropertiesPB(pb->mutable_table_properties());
348
140M
  pb->set_pgschema_name(schema.SchemaName());
349
140M
}
350
351
0
void SchemaToPBWithoutIds(const Schema& schema, SchemaPB *pb) {
352
0
  pb->Clear();
353
0
  SchemaToColumnPBs(schema, pb->mutable_columns(), SCHEMA_PB_WITHOUT_IDS);
354
0
}
355
356
1.30M
Status SchemaFromPB(const SchemaPB& pb, Schema *schema) {
357
  // Conver the columns.
358
1.30M
  vector<ColumnSchema> columns;
359
1.30M
  vector<ColumnId> column_ids;
360
1.30M
  int num_key_columns = 0;
361
1.30M
  RETURN_NOT_OK(ColumnPBsToColumnTuple(pb.columns(), &columns, &column_ids, &num_key_columns));
362
363
  // Convert the table properties.
364
1.30M
  TableProperties table_properties = TableProperties::FromTablePropertiesPB(pb.table_properties());
365
1.30M
  RETURN_NOT_OK(schema->Reset(columns, column_ids, num_key_columns, table_properties));
366
367
1.30M
  if(pb.has_pgschema_name()) {
368
1.30M
    schema->SetSchemaName(pb.pgschema_name());
369
1.30M
  }
370
371
1.30M
  if (pb.has_colocated_table_id()) {
372
1.30M
    switch (pb.colocated_table_id().value_case()) {
373
0
      case ColocatedTableIdentifierPB::kCotableId: {
374
0
        schema->set_cotable_id(
375
0
            VERIFY_RESULT(Uuid::FromString(pb.colocated_table_id().cotable_id())));
376
0
        break;
377
0
      }
378
23
      case ColocatedTableIdentifierPB::kPgtableId:
379
23
        schema->set_pgtable_id(pb.colocated_table_id().pgtable_id());
380
23
        break;
381
1.30M
      case ColocatedTableIdentifierPB::VALUE_NOT_SET:
382
1.30M
        break;
383
1.30M
    }
384
1.30M
  }
385
1.30M
  return Status::OK();
386
1.30M
}
387
388
961M
void ColumnSchemaToPB(const ColumnSchema& col_schema, ColumnSchemaPB *pb, int flags) {
389
961M
  pb->Clear();
390
961M
  pb->set_name(col_schema.name());
391
961M
  col_schema.type()->ToQLTypePB(pb->mutable_type());
392
961M
  pb->set_is_nullable(col_schema.is_nullable());
393
961M
  pb->set_is_static(col_schema.is_static());
394
961M
  pb->set_is_counter(col_schema.is_counter());
395
961M
  pb->set_order(col_schema.order());
396
961M
  pb->set_sorting_type(col_schema.sorting_type());
397
961M
  pb->set_pg_type_oid(col_schema.pg_type_oid());
398
  // We only need to process the *hash* primary key here. The regular primary key is set by the
399
  // conversion for SchemaPB. The reason is that ColumnSchema and ColumnSchemaPB are not matching
400
  // 1 to 1 as ColumnSchema doesn't have "is_key" field. That was Kudu's code, and we keep it that
401
  // way for now.
402
961M
  if (col_schema.is_hash_key()) {
403
514k
    pb->set_is_key(true);
404
514k
    pb->set_is_hash_key(true);
405
514k
  }
406
961M
}
407
408
409
9.65M
ColumnSchema ColumnSchemaFromPB(const ColumnSchemaPB& pb) {
410
  // Only "is_hash_key" is used to construct ColumnSchema. The field "is_key" will be read when
411
  // processing SchemaPB.
412
9.65M
  return ColumnSchema(pb.name(), QLType::FromQLTypePB(pb.type()), pb.is_nullable(),
413
9.65M
                      pb.is_hash_key(), pb.is_static(), pb.is_counter(), pb.order(),
414
9.65M
                      SortingType(pb.sorting_type()), pb.pg_type_oid());
415
9.65M
}
416
417
CHECKED_STATUS ColumnPBsToColumnTuple(
418
    const RepeatedPtrField<ColumnSchemaPB>& column_pbs,
419
1.34M
    vector<ColumnSchema>* columns , vector<ColumnId>* column_ids, int* num_key_columns) {
420
1.34M
  columns->reserve(column_pbs.size());
421
1.34M
  bool is_handling_key = true;
422
9.65M
  for (const ColumnSchemaPB& pb : column_pbs) {
423
9.65M
    columns->push_back(ColumnSchemaFromPB(pb));
424
9.65M
    if (pb.is_key()) {
425
2.73M
      if (!is_handling_key) {
426
1
        return STATUS(InvalidArgument,
427
1
                      "Got out-of-order key column", pb.ShortDebugString());
428
1
      }
429
2.73M
      (*num_key_columns)++;
430
6.91M
    } else {
431
6.91M
      is_handling_key = false;
432
6.91M
    }
433
9.65M
    if (pb.has_id()) {
434
9.64M
      column_ids->push_back(ColumnId(pb.id()));
435
9.64M
    }
436
9.65M
  }
437
438
1.34M
  DCHECK_LE((*num_key_columns), columns->size());
439
1.34M
  return Status::OK();
440
1.34M
}
441
442
Status ColumnPBsToSchema(const RepeatedPtrField<ColumnSchemaPB>& column_pbs,
443
3
                         Schema* schema) {
444
445
3
  vector<ColumnSchema> columns;
446
3
  vector<ColumnId> column_ids;
447
3
  int num_key_columns = 0;
448
3
  RETURN_NOT_OK(ColumnPBsToColumnTuple(column_pbs, &columns, &column_ids, &num_key_columns));
449
450
  // TODO(perf): could make the following faster by adding a
451
  // Reset() variant which actually takes ownership of the column
452
  // vector.
453
2
  return schema->Reset(columns, column_ids, num_key_columns);
454
3
}
455
456
void SchemaToColumnPBs(const Schema& schema,
457
                       RepeatedPtrField<ColumnSchemaPB>* cols,
458
140M
                       int flags) {
459
140M
  cols->Clear();
460
140M
  size_t idx = 0;
461
961M
  for (const ColumnSchema& col : schema.columns()) {
462
961M
    ColumnSchemaPB* col_pb = cols->Add();
463
961M
    ColumnSchemaToPB(col, col_pb);
464
961M
    col_pb->set_is_key(idx < schema.num_key_columns());
465
466
961M
    if (schema.has_column_ids() && !(flags & SCHEMA_PB_WITHOUT_IDS)) {
467
961M
      col_pb->set_id(schema.column_id(idx));
468
961M
    }
469
470
961M
    idx++;
471
961M
  }
472
140M
}
473
474
591k
Result<UsePrivateIpMode> GetPrivateIpMode() {
475
2.35M
  for (auto i : kUsePrivateIpModeList) {
476
2.35M
    if (FLAGS_use_private_ip == ToCString(i)) {
477
591k
      return i;
478
591k
    }
479
2.35M
  }
480
18.4E
  return STATUS_FORMAT(
481
591k
      IllegalState,
482
591k
      "Invalid value of FLAGS_use_private_ip: $0, using private ip everywhere",
483
591k
      FLAGS_use_private_ip);
484
591k
}
485
486
580k
UsePrivateIpMode GetMode() {
487
580k
  auto result = GetPrivateIpMode();
488
580k
  if (result.ok()) {
489
580k
    return *result;
490
580k
  }
491
80
  YB_LOG_EVERY_N_SECS(WARNING, 300) << result.status();
492
80
  return UsePrivateIpMode::never;
493
80
}
494
495
580k
PublicAddressAllowed UsePublicIp(const CloudInfoPB& connect_to, const CloudInfoPB& connect_from) {
496
580k
  auto mode = GetMode();
497
498
580k
  if (mode == UsePrivateIpMode::never) {
499
578k
    return PublicAddressAllowed::kTrue;
500
578k
  }
501
2.70k
  if (connect_to.placement_cloud() != connect_from.placement_cloud()) {
502
2.33k
    return PublicAddressAllowed::kTrue;
503
2.33k
  }
504
364
  if (mode == UsePrivateIpMode::cloud) {
505
50
    return PublicAddressAllowed::kFalse;
506
50
  }
507
314
  if (connect_to.placement_region() != connect_from.placement_region()) {
508
0
    return PublicAddressAllowed::kTrue;
509
0
  }
510
314
  if (mode == UsePrivateIpMode::region) {
511
0
    return PublicAddressAllowed::kFalse;
512
0
  }
513
314
  if (connect_to.placement_zone() != connect_from.placement_zone()) {
514
0
    return PublicAddressAllowed::kTrue;
515
0
  }
516
314
  return mode == UsePrivateIpMode::zone
517
0
      ? PublicAddressAllowed::kFalse
518
314
      : PublicAddressAllowed::kTrue;
519
314
}
520
521
5.81k
const HostPortPB& PublicHostPort(const ServerRegistrationPB& registration) {
522
5.81k
  return GetHostPort(registration.broadcast_addresses(),
523
5.81k
                     registration.private_rpc_addresses(),
524
5.81k
                     PublicAddressAllowed::kTrue);
525
5.81k
}
526
527
const HostPortPB& DesiredHostPort(
528
    const google::protobuf::RepeatedPtrField<HostPortPB>& broadcast_addresses,
529
    const google::protobuf::RepeatedPtrField<HostPortPB>& private_host_ports,
530
    const CloudInfoPB& connect_to,
531
580k
    const CloudInfoPB& connect_from) {
532
580k
  return GetHostPort(broadcast_addresses,
533
580k
                     private_host_ports,
534
580k
                     UsePublicIp(connect_to, connect_from));
535
580k
}
536
537
const HostPortPB& DesiredHostPort(const ServerRegistrationPB& registration,
538
61.9k
                                  const CloudInfoPB& connect_from) {
539
61.9k
  return DesiredHostPort(
540
61.9k
      registration.broadcast_addresses(), registration.private_rpc_addresses(),
541
61.9k
      registration.cloud_info(), connect_from);
542
61.9k
}
543
544
static const std::string kSplitChildTabletIdsCategoryName = "split child tablet IDs";
545
546
StatusCategoryRegisterer split_child_tablet_ids_category_registerer(
547
    StatusCategoryDescription::Make<SplitChildTabletIdsTag>(&kSplitChildTabletIdsCategoryName));
548
549
0
std::string SplitChildTabletIdsTag::ToMessage(Value value) {
550
0
  return Format("Split child tablet IDs: $0", value);
551
0
}
552
553
} // namespace yb