blob_db.cc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include "utilities/blob_db/blob_db.h"
  7. #include <cinttypes>
  8. #include "logging/logging.h"
  9. #include "utilities/blob_db/blob_db_impl.h"
  10. namespace ROCKSDB_NAMESPACE::blob_db {
  11. Status BlobDB::Open(const Options& options, const BlobDBOptions& bdb_options,
  12. const std::string& dbname, BlobDB** blob_db) {
  13. *blob_db = nullptr;
  14. DBOptions db_options(options);
  15. ColumnFamilyOptions cf_options(options);
  16. std::vector<ColumnFamilyDescriptor> column_families;
  17. column_families.emplace_back(kDefaultColumnFamilyName, cf_options);
  18. std::vector<ColumnFamilyHandle*> handles;
  19. Status s = BlobDB::Open(db_options, bdb_options, dbname, column_families,
  20. &handles, blob_db);
  21. if (s.ok()) {
  22. assert(handles.size() == 1);
  23. // i can delete the handle since DBImpl is always holding a reference to
  24. // default column family
  25. delete handles[0];
  26. }
  27. return s;
  28. }
  29. Status BlobDB::Open(const DBOptions& db_options,
  30. const BlobDBOptions& bdb_options, const std::string& dbname,
  31. const std::vector<ColumnFamilyDescriptor>& column_families,
  32. std::vector<ColumnFamilyHandle*>* handles,
  33. BlobDB** blob_db) {
  34. assert(handles);
  35. if (column_families.size() != 1 ||
  36. column_families[0].name != kDefaultColumnFamilyName) {
  37. return Status::NotSupported(
  38. "Blob DB doesn't support non-default column family.");
  39. }
  40. BlobDBImpl* blob_db_impl = new BlobDBImpl(dbname, bdb_options, db_options,
  41. column_families[0].options);
  42. Status s = blob_db_impl->Open(handles);
  43. if (s.ok()) {
  44. *blob_db = static_cast<BlobDB*>(blob_db_impl);
  45. } else {
  46. if (!handles->empty()) {
  47. for (ColumnFamilyHandle* cfh : *handles) {
  48. blob_db_impl->DestroyColumnFamilyHandle(cfh);
  49. }
  50. handles->clear();
  51. }
  52. delete blob_db_impl;
  53. *blob_db = nullptr;
  54. }
  55. return s;
  56. }
  57. BlobDB::BlobDB() : StackableDB(nullptr) {}
  58. void BlobDBOptions::Dump(Logger* log) const {
  59. ROCKS_LOG_HEADER(
  60. log, " BlobDBOptions.blob_dir: %s",
  61. blob_dir.c_str());
  62. ROCKS_LOG_HEADER(
  63. log, " BlobDBOptions.path_relative: %d",
  64. path_relative);
  65. ROCKS_LOG_HEADER(
  66. log, " BlobDBOptions.is_fifo: %d",
  67. is_fifo);
  68. ROCKS_LOG_HEADER(
  69. log, " BlobDBOptions.max_db_size: %" PRIu64,
  70. max_db_size);
  71. ROCKS_LOG_HEADER(
  72. log, " BlobDBOptions.ttl_range_secs: %" PRIu64,
  73. ttl_range_secs);
  74. ROCKS_LOG_HEADER(
  75. log, " BlobDBOptions.min_blob_size: %" PRIu64,
  76. min_blob_size);
  77. ROCKS_LOG_HEADER(
  78. log, " BlobDBOptions.bytes_per_sync: %" PRIu64,
  79. bytes_per_sync);
  80. ROCKS_LOG_HEADER(
  81. log, " BlobDBOptions.blob_file_size: %" PRIu64,
  82. blob_file_size);
  83. ROCKS_LOG_HEADER(
  84. log, " BlobDBOptions.compression: %d",
  85. static_cast<int>(compression));
  86. ROCKS_LOG_HEADER(
  87. log, " BlobDBOptions.enable_garbage_collection: %d",
  88. enable_garbage_collection);
  89. ROCKS_LOG_HEADER(
  90. log, " BlobDBOptions.garbage_collection_cutoff: %f",
  91. garbage_collection_cutoff);
  92. ROCKS_LOG_HEADER(
  93. log, " BlobDBOptions.disable_background_tasks: %d",
  94. disable_background_tasks);
  95. }
  96. } // namespace ROCKSDB_NAMESPACE::blob_db