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