YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/integration-tests/backfill-test-util.h
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
#ifndef YB_INTEGRATION_TESTS_BACKFILL_TEST_UTIL_H
15
#define YB_INTEGRATION_TESTS_BACKFILL_TEST_UTIL_H
16
17
#include <algorithm>
18
#include <string>
19
20
#include "yb/client/yb_table_name.h"
21
22
#include "yb/integration-tests/external_mini_cluster.h"
23
24
#include "yb/master/master_ddl.proxy.h"
25
26
#include "yb/rpc/rpc_controller.h"
27
28
#include "yb/util/result.h"
29
#include "yb/util/test_util.h"
30
31
namespace yb {
32
33
Result<master::BackfillJobPB> GetBackfillJobs(
34
    const master::MasterDdlProxy& proxy,
35
695
    const master::TableIdentifierPB &table_identifier) {
36
695
  master::GetBackfillJobsRequestPB req;
37
695
  master::GetBackfillJobsResponsePB resp;
38
695
  rpc::RpcController rpc;
39
695
  constexpr auto kAdminRpcTimeout = 5;
40
695
  rpc.set_timeout(MonoDelta::FromSeconds(kAdminRpcTimeout));
41
42
695
  req.mutable_table_identifier()->CopyFrom(table_identifier);
43
695
  RETURN_NOT_OK(proxy.GetBackfillJobs(req, &resp, &rpc));
44
695
  if (resp.backfill_jobs_size() == 0) {
45
226
    return STATUS(NotFound, "No backfill job running yet");
46
469
  } else {
47
0
    CHECK_EQ(resp.backfill_jobs_size(), 1) << "As of now only one outstanding backfill "
48
0
                                           << "job should be pending.";
49
469
    return resp.backfill_jobs(0);
50
469
  }
51
695
}
52
53
Result<master::BackfillJobPB> GetBackfillJobs(
54
    ExternalMiniCluster* cluster,
55
0
    const client::YBTableName& table_name) {
56
0
  master::TableIdentifierPB table_identifier;
57
0
  table_name.SetIntoTableIdentifierPB(&table_identifier);
58
0
  return GetBackfillJobs(
59
0
      cluster->GetMasterProxy<master::MasterDdlProxy>(), table_identifier);
60
0
}
61
62
Result<master::BackfillJobPB> GetBackfillJobs(
63
    ExternalMiniCluster* cluster,
64
0
    const TableId& table_id) {
65
0
  master::TableIdentifierPB table_identifier;
66
0
  if (!table_id.empty()) {
67
0
    table_identifier.set_table_id(table_id);
68
0
  }
69
0
  return GetBackfillJobs(
70
0
      cluster->GetMasterProxy<master::MasterDdlProxy>(), table_identifier);
71
0
}
72
73
CHECKED_STATUS WaitForBackfillSatisfyCondition(
74
    const master::MasterDdlProxy& proxy,
75
    const master::TableIdentifierPB& table_identifier,
76
    const std::function<Result<bool>(Result<master::BackfillJobPB>)>& condition,
77
10
    MonoDelta max_wait) {
78
10
  return WaitFor(
79
350
      [proxy, condition, &table_identifier]() {
80
350
        Result<master::BackfillJobPB> backfill_job = GetBackfillJobs(proxy, table_identifier);
81
350
        return condition(backfill_job);
82
350
      },
cassandra_cpp_driver-test.cc:_ZZN2yb31WaitForBackfillSatisfyConditionERKNS_6master14MasterDdlProxyERKNS0_17TableIdentifierPBERKNSt3__18functionIFNS_6ResultIbEENS9_INS0_13BackfillJobPBEEEEEENS_9MonoDeltaEENK3$_0clEv
Line
Count
Source
79
350
      [proxy, condition, &table_identifier]() {
80
350
        Result<master::BackfillJobPB> backfill_job = GetBackfillJobs(proxy, table_identifier);
81
350
        return condition(backfill_job);
82
350
      },
Unexecuted instantiation: pg_index_backfill-test.cc:_ZZN2yb31WaitForBackfillSatisfyConditionERKNS_6master14MasterDdlProxyERKNS0_17TableIdentifierPBERKNSt3__18functionIFNS_6ResultIbEENS9_INS0_13BackfillJobPBEEEEEENS_9MonoDeltaEENK3$_0clEv
83
10
      max_wait, "Waiting for backfill to satisfy condition.");
84
10
}
85
86
CHECKED_STATUS WaitForBackfillSatisfyCondition(
87
    const master::MasterDdlProxy& proxy,
88
    const client::YBTableName& table_name,
89
    const std::function<Result<bool>(Result<master::BackfillJobPB>)>& condition,
90
10
    MonoDelta max_wait = MonoDelta::FromSeconds(60)) {
91
10
  master::TableIdentifierPB table_identifier;
92
10
  table_name.SetIntoTableIdentifierPB(&table_identifier);
93
10
  return WaitForBackfillSatisfyCondition(proxy, table_identifier, condition, max_wait);
94
10
}
95
96
CHECKED_STATUS WaitForBackfillSatisfyCondition(
97
    const master::MasterDdlProxy& proxy,
98
    const TableId& table_id,
99
    const std::function<Result<bool>(Result<master::BackfillJobPB>)>& condition,
100
0
    MonoDelta max_wait = MonoDelta::FromSeconds(60)) {
101
0
  master::TableIdentifierPB table_identifier;
102
0
  if (!table_id.empty()) {
103
0
    table_identifier.set_table_id(table_id);
104
0
  }
105
0
  return WaitForBackfillSatisfyCondition(proxy, table_identifier, condition, max_wait);
106
0
}
107
108
CHECKED_STATUS WaitForBackfillSafeTimeOn(
109
    const master::MasterDdlProxy& proxy,
110
    const master::TableIdentifierPB& table_identifier,
111
11
    MonoDelta max_wait = MonoDelta::FromSeconds(60)) {
112
11
  return WaitFor(
113
345
      [proxy, &table_identifier]() {
114
345
        Result<master::BackfillJobPB> backfill_job = GetBackfillJobs(proxy, table_identifier);
115
345
        return backfill_job && backfill_job->has_backfilling_timestamp();
116
345
      },
cassandra_cpp_driver-test.cc:_ZZN2yb25WaitForBackfillSafeTimeOnERKNS_6master14MasterDdlProxyERKNS0_17TableIdentifierPBENS_9MonoDeltaEENK3$_1clEv
Line
Count
Source
113
345
      [proxy, &table_identifier]() {
114
345
        Result<master::BackfillJobPB> backfill_job = GetBackfillJobs(proxy, table_identifier);
115
345
        return backfill_job && backfill_job->has_backfilling_timestamp();
116
345
      },
Unexecuted instantiation: pg_index_backfill-test.cc:_ZZN2yb25WaitForBackfillSafeTimeOnERKNS_6master14MasterDdlProxyERKNS0_17TableIdentifierPBENS_9MonoDeltaEENK3$_1clEv
117
11
      max_wait, "waiting for backfill to get past GetSafeTime.");
118
11
}
119
120
CHECKED_STATUS WaitForBackfillSafeTimeOn(
121
    const master::MasterDdlProxy& proxy,
122
    const client::YBTableName& table_name,
123
11
    MonoDelta max_wait = MonoDelta::FromSeconds(60)) {
124
11
  master::TableIdentifierPB table_identifier;
125
11
  table_name.SetIntoTableIdentifierPB(&table_identifier);
126
11
  return WaitForBackfillSafeTimeOn(proxy, table_identifier, max_wait);
127
11
}
128
129
CHECKED_STATUS WaitForBackfillSafeTimeOn(
130
    const master::MasterDdlProxy& proxy,
131
    const TableId& table_id,
132
0
    MonoDelta max_wait = MonoDelta::FromSeconds(60)) {
133
0
  master::TableIdentifierPB table_identifier;
134
0
  if (!table_id.empty()) {
135
0
    table_identifier.set_table_id(table_id);
136
0
  }
137
0
  return WaitForBackfillSafeTimeOn(proxy, table_identifier, max_wait);
138
0
}
139
140
CHECKED_STATUS WaitForBackfillSafeTimeOn(
141
    ExternalMiniCluster* cluster,
142
    const client::YBTableName& table_name,
143
11
    MonoDelta max_wait = MonoDelta::FromSeconds(60)) {
144
11
  return WaitForBackfillSafeTimeOn(
145
11
      cluster->GetMasterProxy<master::MasterDdlProxy>(), table_name, max_wait);
146
11
}
147
148
CHECKED_STATUS WaitForBackfillSafeTimeOn(
149
    ExternalMiniCluster* cluster,
150
    const TableId& table_id,
151
0
    MonoDelta max_wait = MonoDelta::FromSeconds(60)) {
152
0
  return WaitForBackfillSafeTimeOn(
153
0
      cluster->GetMasterProxy<master::MasterDdlProxy>(), table_id, max_wait);
154
0
}
155
156
}  // namespace yb
157
158
#endif  // YB_INTEGRATION_TESTS_BACKFILL_TEST_UTIL_H