1 // Copyright (c) 2017-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).
9 #include "rocksdb/utilities/checkpoint.h"
12 #include "file/filename.h"
13 #include "rocksdb/db.h"
15 namespace ROCKSDB_NAMESPACE
{
17 class CheckpointImpl
: public Checkpoint
{
19 // Creates a Checkpoint object to be used for creating openable snapshots
20 explicit CheckpointImpl(DB
* db
) : db_(db
) {}
22 // Builds an openable snapshot of RocksDB on the same disk, which
23 // accepts an output directory on the same disk, and under the directory
24 // (1) hard-linked SST files pointing to existing live SST files
25 // SST files will be copied if output directory is on a different filesystem
26 // (2) a copied manifest files and other files
27 // The directory should not already exist and will be created by this API.
28 // The directory will be an absolute path
29 using Checkpoint::CreateCheckpoint
;
30 virtual Status
CreateCheckpoint(const std::string
& checkpoint_dir
,
31 uint64_t log_size_for_flush
,
32 uint64_t* sequence_number_ptr
) override
;
34 // Exports all live SST files of a specified Column Family onto export_dir
35 // and returning SST files information in metadata.
36 // - SST files will be created as hard links when the directory specified
37 // is in the same partition as the db directory, copied otherwise.
38 // - export_dir should not already exist and will be created by this API.
39 // - Always triggers a flush.
40 using Checkpoint::ExportColumnFamily
;
41 virtual Status
ExportColumnFamily(
42 ColumnFamilyHandle
* handle
, const std::string
& export_dir
,
43 ExportImportFilesMetaData
** metadata
) override
;
45 // Checkpoint logic can be customized by providing callbacks for link, copy,
47 Status
CreateCustomCheckpoint(
48 const DBOptions
& db_options
,
49 std::function
<Status(const std::string
& src_dirname
,
50 const std::string
& fname
, FileType type
)>
52 std::function
<Status(const std::string
& src_dirname
,
53 const std::string
& fname
, uint64_t size_limit_bytes
,
54 FileType type
, const std::string
& checksum_func_name
,
55 const std::string
& checksum_val
)>
57 std::function
<Status(const std::string
& fname
,
58 const std::string
& contents
, FileType type
)>
60 uint64_t* sequence_number
, uint64_t log_size_for_flush
,
61 bool get_live_table_checksum
= false);
64 void CleanStagingDirectory(const std::string
& path
, Logger
* info_log
);
66 // Export logic customization by providing callbacks for link or copy.
67 Status
ExportFilesInMetaData(
68 const DBOptions
& db_options
, const ColumnFamilyMetaData
& metadata
,
69 std::function
<Status(const std::string
& src_dirname
,
70 const std::string
& fname
)>
72 std::function
<Status(const std::string
& src_dirname
,
73 const std::string
& fname
)>
80 } // namespace ROCKSDB_NAMESPACE
82 #endif // ROCKSDB_LITE