/Users/deen/code/yugabyte-db/src/yb/master/snapshot_schedule_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_SCHEDULE_STATE_H |
15 | | #define YB_MASTER_SNAPSHOT_SCHEDULE_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/master_fwd.h" |
23 | | #include "yb/master/master_backup.pb.h" |
24 | | |
25 | | #include "yb/util/async_task_util.h" |
26 | | #include "yb/util/tostring.h" |
27 | | |
28 | | namespace yb { |
29 | | namespace master { |
30 | | |
31 | | YB_DEFINE_ENUM(SnapshotScheduleOperationType, (kCreateSnapshot)(kCleanup)); |
32 | | |
33 | | struct SnapshotScheduleOperation { |
34 | | SnapshotScheduleOperationType type; |
35 | | SnapshotScheduleId schedule_id; |
36 | | TxnSnapshotId snapshot_id; |
37 | | SnapshotScheduleFilterPB filter; |
38 | | HybridTime previous_snapshot_hybrid_time; |
39 | | |
40 | 0 | std::string ToString() const { |
41 | 0 | return YB_STRUCT_TO_STRING( |
42 | 0 | type, schedule_id, snapshot_id, filter, previous_snapshot_hybrid_time); |
43 | 0 | } |
44 | | }; |
45 | | |
46 | | struct CreatingSnapshotData { |
47 | | CoarseTimePoint start_time; |
48 | | TxnSnapshotId snapshot_id = TxnSnapshotId::Nil(); |
49 | | }; |
50 | | |
51 | | using SnapshotScheduleOperations = std::vector<SnapshotScheduleOperation>; |
52 | | |
53 | | class SnapshotScheduleState { |
54 | | public: |
55 | | SnapshotScheduleState( |
56 | | SnapshotCoordinatorContext* context, const CreateSnapshotScheduleRequestPB& req); |
57 | | |
58 | | SnapshotScheduleState( |
59 | | SnapshotCoordinatorContext* context, const SnapshotScheduleId& id, |
60 | | const SnapshotScheduleOptionsPB& options); |
61 | | |
62 | 945 | const SnapshotScheduleId& id() const { |
63 | 945 | return id_; |
64 | 945 | } |
65 | | |
66 | 9 | bool ShouldUpdate(const SnapshotScheduleState& other) const { |
67 | 9 | return true; |
68 | 9 | } |
69 | | |
70 | 191 | const SnapshotScheduleOptionsPB& options() const { |
71 | 191 | return options_; |
72 | 191 | } |
73 | | |
74 | 3 | SnapshotScheduleOptionsPB& mutable_options() { |
75 | 3 | return options_; |
76 | 3 | } |
77 | | |
78 | 0 | AsyncTaskTracker& CleanupTracker() { |
79 | 0 | return cleanup_tracker_; |
80 | 0 | } |
81 | | |
82 | | bool deleted() const; |
83 | | |
84 | | void PrepareOperations( |
85 | | HybridTime last_snapshot_time, HybridTime now, SnapshotScheduleOperations* operations); |
86 | | Result<SnapshotScheduleOperation> ForceCreateSnapshot(HybridTime last_snapshot_time); |
87 | | void SnapshotFinished(const TxnSnapshotId& snapshot_id, const Status& status); |
88 | | |
89 | | Result<docdb::KeyBytes> EncodedKey() const; |
90 | | static Result<docdb::KeyBytes> EncodedKey( |
91 | | const SnapshotScheduleId& schedule_id, SnapshotCoordinatorContext* context); |
92 | | |
93 | | CHECKED_STATUS StoreToWriteBatch(docdb::KeyValueWriteBatchPB* write_batch) const; |
94 | | CHECKED_STATUS ToPB(SnapshotScheduleInfoPB* pb) const; |
95 | | std::string ToString() const; |
96 | | |
97 | 1 | const CreatingSnapshotData& creating_snapshot_data() const { |
98 | 1 | return creating_snapshot_data_; |
99 | 1 | } |
100 | | |
101 | | private: |
102 | | std::string LogPrefix() const; |
103 | | |
104 | | SnapshotScheduleOperation MakeCreateSnapshotOperation(HybridTime last_snapshot_time); |
105 | | |
106 | | SnapshotCoordinatorContext& context_; |
107 | | SnapshotScheduleId id_; |
108 | | SnapshotScheduleOptionsPB options_; |
109 | | |
110 | | // When snapshot is being created for this schedule, this field contains id of this snapshot. |
111 | | // To prevent creating other snapshots during that time. |
112 | | CreatingSnapshotData creating_snapshot_data_; |
113 | | |
114 | | AsyncTaskTracker cleanup_tracker_; |
115 | | }; |
116 | | |
117 | | } // namespace master |
118 | | } // namespace yb |
119 | | |
120 | | #endif // YB_MASTER_SNAPSHOT_SCHEDULE_STATE_H |