YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/client/client_utils.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/client/client_utils.h"
15
16
#include <functional>
17
#include <set>
18
#include <string>
19
#include <unordered_set>
20
#include <vector>
21
22
#include "yb/client/client.h"
23
#include "yb/client/meta_cache.h"
24
25
#include "yb/common/entity_ids.h"
26
#include "yb/common/wire_protocol.h"
27
28
#include "yb/rpc/messenger.h"
29
#include "yb/rpc/rpc.h"
30
31
#include "yb/server/secure.h"
32
33
#include "yb/util/atomic.h"
34
#include "yb/util/locks.h"
35
#include "yb/util/monotime.h"
36
#include "yb/util/net/net_util.h"
37
#include "yb/util/result.h"
38
#include "yb/util/strongly_typed_uuid.h"
39
#include "yb/util/threadpool.h"
40
41
DECLARE_bool(TEST_running_test);
42
43
namespace yb {
44
namespace client {
45
46
constexpr int32_t kClientTimeoutSecs = 60;
47
48
std::future<Result<internal::RemoteTabletPtr>> LookupFirstTabletFuture(
49
0
    YBClient* client, const std::shared_ptr<YBTable>& table) {
50
0
  return client->LookupTabletByKeyFuture(
51
0
      table, "" /* partition_key */,
52
0
      CoarseMonoClock::now() + std::chrono::seconds(kClientTimeoutSecs));
53
0
}
54
55
Result<std::unique_ptr<rpc::Messenger>> CreateClientMessenger(
56
    const string& client_name,
57
    int32_t num_reactors,
58
    const scoped_refptr<MetricEntity>& metric_entity,
59
    const std::shared_ptr<MemTracker>& parent_mem_tracker,
60
6.73k
    rpc::SecureContext* secure_context) {
61
6.73k
  rpc::MessengerBuilder builder(client_name);
62
6.73k
  builder.set_num_reactors(num_reactors);
63
6.73k
  builder.set_metric_entity(metric_entity);
64
6.73k
  builder.UseDefaultConnectionContextFactory(parent_mem_tracker);
65
6.73k
  if (secure_context) {
66
14
    server::ApplySecureContext(secure_context, &builder);
67
14
  }
68
6.73k
  auto messenger = VERIFY_RESULT(builder.Build());
69
6.73k
  if (PREDICT_FALSE(FLAGS_TEST_running_test)) {
70
361
    messenger->TEST_SetOutboundIpBase(VERIFY_RESULT(HostToAddress("127.0.0.1")));
71
361
  }
72
6.73k
  return messenger;
73
6.73k
}
74
75
Result<std::vector<internal::RemoteTabletPtr>> FilterTabletsByHashPartitionKeyRange(
76
    const std::vector<internal::RemoteTabletPtr>& all_tablets,
77
    const std::string& partition_key_start,
78
0
    const std::string& partition_key_end) {
79
0
  RETURN_NOT_OK(PartitionSchema::IsValidHashPartitionRange(partition_key_start,
80
0
                                                           partition_key_end));
81
0
  std::vector<internal::RemoteTabletPtr> filtered_results;
82
0
  for (const auto& remote_tablet : all_tablets) {
83
0
    auto tablet_partition_start = remote_tablet->partition().partition_key_start();
84
0
    auto tablet_partition_end = remote_tablet->partition().partition_key_end();
85
    // Is this tablet at the start
86
0
    bool start_condition = partition_key_start.empty() || tablet_partition_end.empty() ||
87
0
                           tablet_partition_end > partition_key_start;
88
0
    bool end_condition = partition_key_end.empty() || tablet_partition_start < partition_key_end;
89
90
0
    if (start_condition && end_condition) {
91
0
      filtered_results.push_back(remote_tablet);
92
0
    }
93
0
  }
94
0
  return filtered_results;
95
0
}
96
97
98
} // namespace client
99
} // namespace yb