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