checkpoint_impl.h 3.1 KB

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