1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 //
6 // A checkpoint is an openable snapshot of a database at a point in time.
7 
8 #pragma once
9 #ifndef ROCKSDB_LITE
10 
11 #include <string>
12 #include <vector>
13 #include "rocksdb/status.h"
14 
15 namespace ROCKSDB_NAMESPACE {
16 
17 class DB;
18 class ColumnFamilyHandle;
19 struct LiveFileMetaData;
20 struct ExportImportFilesMetaData;
21 
22 class Checkpoint {
23  public:
24   // Creates a Checkpoint object to be used for creating openable snapshots
25   static Status Create(DB* db, Checkpoint** checkpoint_ptr);
26 
27   // Builds an openable snapshot of RocksDB on the same disk, which
28   // accepts an output directory on the same disk, and under the directory
29   // (1) hard-linked SST files pointing to existing live SST files
30   // SST files will be copied if output directory is on a different filesystem
31   // (2) a copied manifest files and other files
32   // The directory should not already exist and will be created by this API.
33   // The directory will be an absolute path
34   // log_size_for_flush: if the total log file size is equal or larger than
35   // this value, then a flush is triggered for all the column families. The
36   // default value is 0, which means flush is always triggered. If you move
37   // away from the default, the checkpoint may not contain up-to-date data
38   // if WAL writing is not always enabled.
39   // Flush will always trigger if it is 2PC.
40   // sequence_number_ptr: if it is not nullptr, the value it points to will be
41   // set to the DB's sequence number. The default value of this parameter is
42   // nullptr.
43   virtual Status CreateCheckpoint(const std::string& checkpoint_dir,
44                                   uint64_t log_size_for_flush = 0,
45                                   uint64_t* sequence_number_ptr = nullptr);
46 
47   // Exports all live SST files of a specified Column Family onto export_dir,
48   // returning SST files information in metadata.
49   // - SST files will be created as hard links when the directory specified
50   //   is in the same partition as the db directory, copied otherwise.
51   // - export_dir should not already exist and will be created by this API.
52   // - Always triggers a flush.
53   virtual Status ExportColumnFamily(ColumnFamilyHandle* handle,
54                                     const std::string& export_dir,
55                                     ExportImportFilesMetaData** metadata);
56 
~Checkpoint()57   virtual ~Checkpoint() {}
58 };
59 
60 }  // namespace ROCKSDB_NAMESPACE
61 #endif  // !ROCKSDB_LITE
62