YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/tablet/tablet_snapshots.h
Line
Count
Source
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_TABLET_TABLET_SNAPSHOTS_H
15
#define YB_TABLET_TABLET_SNAPSHOTS_H
16
17
#include "yb/common/hybrid_time.h"
18
#include "yb/common/snapshot.h"
19
20
#include "yb/tablet/tablet_fwd.h"
21
#include "yb/tablet/tablet_component.h"
22
23
#include "yb/docdb/docdb_fwd.h"
24
25
#include "yb/util/opid.h"
26
#include "yb/util/status_fwd.h"
27
28
namespace rocksdb {
29
30
class DB;
31
32
}
33
34
namespace yb {
35
36
class Env;
37
class FsManager;
38
class RWOperationCounter;
39
class rw_semaphore;
40
41
namespace tablet {
42
43
YB_DEFINE_ENUM(CreateIntentsCheckpointIn, (kSubDir)(kUseIntentsDbSuffix));
44
45
struct CreateSnapshotData {
46
  HybridTime snapshot_hybrid_time;
47
  HybridTime hybrid_time;
48
  OpId op_id;
49
  std::string snapshot_dir;
50
  SnapshotScheduleId schedule_id;
51
};
52
53
class TabletSnapshots : public TabletComponent {
54
 public:
55
  explicit TabletSnapshots(Tablet* tablet);
56
57
  // Create snapshot for this tablet.
58
  CHECKED_STATUS Create(SnapshotOperation* operation);
59
60
  CHECKED_STATUS Create(const CreateSnapshotData& data);
61
62
  // Restore snapshot for this tablet. In addition to backup/restore, this is used for initial
63
  // syscatalog RocksDB creation without the initdb overhead.
64
  CHECKED_STATUS Restore(SnapshotOperation* operation);
65
66
  // Delete snapshot for this tablet.
67
  CHECKED_STATUS Delete(const SnapshotOperation& operation);
68
69
  CHECKED_STATUS RestoreFinished(SnapshotOperation* operation);
70
71
  // Prepares the operation context for a snapshot operation.
72
  CHECKED_STATUS Prepare(SnapshotOperation* operation);
73
74
  Result<std::string> RestoreToTemporary(const TxnSnapshotId& snapshot_id, HybridTime restore_at);
75
76
  //------------------------------------------------------------------------------------------------
77
  // Create a RocksDB checkpoint in the provided directory. Only used when table_type_ ==
78
  // YQL_TABLE_TYPE.
79
  // use_subdir_for_intents specifies whether to create intents DB checkpoint inside
80
  // <dir>/<kIntentsSubdir> or <dir>.<kIntentsDBSuffix>
81
  CHECKED_STATUS CreateCheckpoint(
82
      const std::string& dir,
83
      CreateIntentsCheckpointIn create_intents_checkpoint_in =
84
          CreateIntentsCheckpointIn::kUseIntentsDbSuffix);
85
86
  // Returns the location of the last rocksdb checkpoint. Used for tests only.
87
1
  std::string TEST_LastRocksDBCheckpointDir() { return TEST_last_rocksdb_checkpoint_dir_; }
88
89
  CHECKED_STATUS CreateDirectories(const std::string& rocksdb_dir, FsManager* fs);
90
91
  static std::string SnapshotsDirName(const std::string& rocksdb_dir);
92
93
  static bool IsTempSnapshotDir(const std::string& dir);
94
95
 private:
96
  struct RestoreMetadata;
97
98
  // Restore the RocksDB checkpoint from the provided directory.
99
  // Only used when table_type_ == YQL_TABLE_TYPE.
100
  CHECKED_STATUS RestoreCheckpoint(
101
      const std::string& dir, HybridTime restore_at, const RestoreMetadata& metadata,
102
      const docdb::ConsensusFrontier& frontier);
103
104
  // Applies specified snapshot operation.
105
  CHECKED_STATUS Apply(SnapshotOperation* operation);
106
107
  CHECKED_STATUS CleanupSnapshotDir(const std::string& dir);
108
  Env& env();
109
110
  std::string TEST_last_rocksdb_checkpoint_dir_;
111
};
112
113
} // namespace tablet
114
} // namespace yb
115
116
#endif // YB_TABLET_TABLET_SNAPSHOTS_H