YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/master/snapshot_state.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_MASTER_SNAPSHOT_STATE_H
15
#define YB_MASTER_SNAPSHOT_STATE_H
16
17
#include "yb/common/hybrid_time.h"
18
#include "yb/common/snapshot.h"
19
20
#include "yb/docdb/docdb_fwd.h"
21
22
#include "yb/master/state_with_tablets.h"
23
24
#include "yb/tablet/tablet_fwd.h"
25
26
#include "yb/tserver/tserver_fwd.h"
27
28
#include "yb/util/async_task_util.h"
29
30
DECLARE_int64(max_concurrent_snapshot_rpcs);
31
DECLARE_int64(max_concurrent_snapshot_rpcs_per_tserver);
32
33
namespace yb {
34
namespace master {
35
36
YB_STRONGLY_TYPED_BOOL(ForClient);
37
38
struct TabletSnapshotOperation {
39
  TabletId tablet_id;
40
  SnapshotScheduleId schedule_id;
41
  TxnSnapshotId snapshot_id;
42
  SysSnapshotEntryPB::State state;
43
  HybridTime snapshot_hybrid_time;
44
45
0
  std::string ToString() const {
46
0
    return YB_STRUCT_TO_STRING(tablet_id, snapshot_id, state, snapshot_hybrid_time);
47
0
  }
48
};
49
50
using TabletSnapshotOperations = std::vector<TabletSnapshotOperation>;
51
52
class SnapshotState : public StateWithTablets {
53
 public:
54
  SnapshotState(
55
      SnapshotCoordinatorContext* context, const TxnSnapshotId& id,
56
      const tserver::TabletSnapshotOpRequestPB& request,
57
      uint64_t throttle_limit = std::numeric_limits<int>::max());
58
59
  SnapshotState(
60
      SnapshotCoordinatorContext* context, const TxnSnapshotId& id,
61
      const SysSnapshotEntryPB& entry);
62
63
0
  const TxnSnapshotId& id() const {
64
0
    return id_;
65
0
  }
66
67
0
  HybridTime snapshot_hybrid_time() const {
68
0
    return snapshot_hybrid_time_;
69
0
  }
70
71
0
  HybridTime previous_snapshot_hybrid_time() const {
72
0
    return previous_snapshot_hybrid_time_;
73
0
  }
74
75
0
  const SnapshotScheduleId& schedule_id() const {
76
0
    return schedule_id_;
77
0
  }
78
79
0
  int64_t version() const {
80
0
    return version_;
81
0
  }
82
83
0
  AsyncTaskTracker& CleanupTracker() {
84
0
    return cleanup_tracker_;
85
0
  }
86
87
0
  AsyncTaskThrottler& Throttler() {
88
0
    return throttler_;
89
0
  }
90
91
  Result<tablet::CreateSnapshotData> SysCatalogSnapshotData(
92
      const tablet::SnapshotOperation& operation) const;
93
94
  std::string ToString() const;
95
  CHECKED_STATUS ToPB(SnapshotInfoPB* out);
96
  CHECKED_STATUS ToEntryPB(SysSnapshotEntryPB* out, ForClient for_client);
97
  CHECKED_STATUS StoreToWriteBatch(docdb::KeyValueWriteBatchPB* out);
98
  CHECKED_STATUS TryStartDelete();
99
  void PrepareOperations(TabletSnapshotOperations* out);
100
  void SetVersion(int value);
101
  bool NeedCleanup() const;
102
  bool ShouldUpdate(const SnapshotState& other) const;
103
  void DeleteAborted(const Status& status);
104
105
 private:
106
  bool IsTerminalFailure(const Status& status) override;
107
  CHECKED_STATUS CheckDoneStatus(const Status& status) override;
108
109
  TxnSnapshotId id_;
110
  HybridTime snapshot_hybrid_time_;
111
  HybridTime previous_snapshot_hybrid_time_;
112
  SysRowEntries entries_;
113
  // When snapshot is taken as a part of snapshot schedule schedule_id_ will contain this
114
  // schedule id. Otherwise it will be nil.
115
  SnapshotScheduleId schedule_id_;
116
  int64_t version_;
117
  bool delete_started_ = false;
118
  AsyncTaskTracker cleanup_tracker_;
119
  AsyncTaskThrottler throttler_;
120
};
121
122
Result<docdb::KeyBytes> EncodedSnapshotKey(
123
    const TxnSnapshotId& id, SnapshotCoordinatorContext* context);
124
125
} // namespace master
126
} // namespace yb
127
128
#endif  // YB_MASTER_SNAPSHOT_STATE_H