blob_db.cc 3.6 KB

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