YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/client/snapshot_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_CLIENT_SNAPSHOT_TEST_UTIL_H
15
#define YB_CLIENT_SNAPSHOT_TEST_UTIL_H
16
17
#include "yb/client/txn-test-base.h"
18
#include "yb/common/snapshot.h"
19
20
#include "yb/integration-tests/mini_cluster.h"
21
#include "yb/master/master_backup.proxy.h"
22
#include "yb/rpc/proxy.h"
23
#include "yb/util/net/net_fwd.h"
24
#include "yb/util/net/net_util.h"
25
#include "yb/util/tsan_util.h"
26
27
using namespace std::literals;
28
29
namespace yb {
30
namespace client {
31
32
using Snapshots = google::protobuf::RepeatedPtrField<master::SnapshotInfoPB>;
33
constexpr auto kWaitTimeout = std::chrono::seconds(15);
34
35
using Schedules = google::protobuf::RepeatedPtrField<master::SnapshotScheduleInfoPB>;
36
using ImportedSnapshotData = google::protobuf::RepeatedPtrField<
37
    master::ImportSnapshotMetaResponsePB::TableMetaPB>;
38
constexpr auto kSnapshotInterval = 10s * kTimeMultiplier;
39
constexpr auto kSnapshotRetention = 20h;
40
41
YB_STRONGLY_TYPED_BOOL(WaitSnapshot);
42
YB_STRONGLY_TYPED_BOOL(ListDeleted);
43
YB_STRONGLY_TYPED_BOOL(PrepareForBackup);
44
45
class SnapshotTestUtil {
46
 public:
47
  SnapshotTestUtil() = default;
48
  ~SnapshotTestUtil() = default;
49
0
  void SetProxy(rpc::ProxyCache* proxy_cache) {
50
0
      proxy_cache_ = proxy_cache;
51
0
  }
52
0
  void SetCluster(MiniCluster* cluster) {
53
0
      cluster_ = cluster;
54
0
  }
55
56
0
  Result<master::MasterBackupProxy> MakeBackupServiceProxy() {
57
0
    return master::MasterBackupProxy(
58
0
        proxy_cache_, VERIFY_RESULT(cluster_->GetLeaderMiniMaster())->bound_rpc_addr());
59
0
  }
Unexecuted instantiation: _ZN2yb6client16SnapshotTestUtil22MakeBackupServiceProxyEv
Unexecuted instantiation: _ZN2yb6client16SnapshotTestUtil22MakeBackupServiceProxyEv
60
61
  Result<master::SysSnapshotEntryPB::State> SnapshotState(const TxnSnapshotId& snapshot_id);
62
63
  Result<bool> IsSnapshotDone(const TxnSnapshotId& snapshot_id);
64
  Result<Snapshots> ListSnapshots(
65
      const TxnSnapshotId& snapshot_id = TxnSnapshotId::Nil(),
66
      ListDeleted list_deleted = ListDeleted::kTrue,
67
      PrepareForBackup prepare_for_backup = PrepareForBackup::kFalse);
68
  CHECKED_STATUS VerifySnapshot(
69
      const TxnSnapshotId& snapshot_id, master::SysSnapshotEntryPB::State state,
70
      size_t expected_num_tablets, size_t expected_num_namespaces = 1,
71
      size_t expected_num_tables = 1);
72
  CHECKED_STATUS WaitSnapshotInState(
73
      const TxnSnapshotId& snapshot_id, master::SysSnapshotEntryPB::State state,
74
      MonoDelta duration = kWaitTimeout);
75
  CHECKED_STATUS WaitSnapshotDone(
76
      const TxnSnapshotId& snapshot_id, MonoDelta duration = kWaitTimeout);
77
78
  Result<TxnSnapshotRestorationId> StartRestoration(
79
      const TxnSnapshotId& snapshot_id, HybridTime restore_at = HybridTime());
80
  Result<bool> IsRestorationDone(const TxnSnapshotRestorationId& restoration_id);
81
  CHECKED_STATUS RestoreSnapshot(
82
      const TxnSnapshotId& snapshot_id, HybridTime restore_at = HybridTime());
83
  Result<TxnSnapshotId> StartSnapshot(const TableHandle& table);
84
  Result<TxnSnapshotId> CreateSnapshot(const TableHandle& table);
85
  CHECKED_STATUS DeleteSnapshot(const TxnSnapshotId& snapshot_id);
86
  CHECKED_STATUS WaitAllSnapshotsDeleted();
87
88
  Result<ImportedSnapshotData> StartImportSnapshot(const master::SnapshotInfoPB& snapshot);
89
  CHECKED_STATUS WaitAllSnapshotsCleaned();
90
91
  Result<SnapshotScheduleId> CreateSchedule(
92
      const TableHandle& table,
93
      MonoDelta interval = kSnapshotInterval, MonoDelta retention = kSnapshotRetention);
94
  Result<SnapshotScheduleId> CreateSchedule(
95
      const TableHandle& table, WaitSnapshot wait_snapshot,
96
      MonoDelta interval = kSnapshotInterval, MonoDelta retention = kSnapshotRetention);
97
98
  Result<Schedules> ListSchedules(const SnapshotScheduleId& id = SnapshotScheduleId::Nil());
99
100
  Result<TxnSnapshotId> PickSuitableSnapshot(
101
      const SnapshotScheduleId& schedule_id, HybridTime hybrid_time);
102
103
  CHECKED_STATUS WaitScheduleSnapshot(
104
      const SnapshotScheduleId& schedule_id, HybridTime min_hybrid_time);
105
106
  CHECKED_STATUS WaitScheduleSnapshot(
107
      const SnapshotScheduleId& schedule_id, int max_snapshots = 1,
108
      HybridTime min_hybrid_time = HybridTime::kMin);
109
110
 private:
111
  rpc::ProxyCache* proxy_cache_;
112
  MiniCluster* cluster_;
113
};
114
115
} // namespace client
116
} // namespace yb
117
118
#endif  // YB_CLIENT_SNAPSHOT_TEST_UTIL_H