]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/utilities/blob_db/blob_db.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / utilities / blob_db / blob_db.cc
CommitLineData
11fdf7f2
TL
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//
7c673cae 6#ifndef ROCKSDB_LITE
7c673cae 7
11fdf7f2 8#include "utilities/blob_db/blob_db.h"
7c673cae 9
f67539c2 10#include <cinttypes>
1e59de90
TL
11
12#include "logging/logging.h"
11fdf7f2 13#include "utilities/blob_db/blob_db_impl.h"
7c673cae 14
f67539c2 15namespace ROCKSDB_NAMESPACE {
11fdf7f2
TL
16namespace blob_db {
17
18Status 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];
7c673cae 34 }
7c673cae
FG
35 return s;
36}
37
11fdf7f2
TL
38Status 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) {
20effc67
TL
43 assert(handles);
44
11fdf7f2
TL
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.");
7c673cae 49 }
7c673cae 50
11fdf7f2
TL
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 {
20effc67
TL
57 if (!handles->empty()) {
58 for (ColumnFamilyHandle* cfh : *handles) {
59 blob_db_impl->DestroyColumnFamilyHandle(cfh);
60 }
61
62 handles->clear();
63 }
64
11fdf7f2
TL
65 delete blob_db_impl;
66 *blob_db = nullptr;
7c673cae 67 }
7c673cae
FG
68 return s;
69}
70
11fdf7f2
TL
71BlobDB::BlobDB() : StackableDB(nullptr) {}
72
73void 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(
494da23a 87 log, " BlobDBOptions.ttl_range_secs: %" PRIu64,
11fdf7f2
TL
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);
f67539c2
TL
104 ROCKS_LOG_HEADER(
105 log, " BlobDBOptions.garbage_collection_cutoff: %f",
106 garbage_collection_cutoff);
11fdf7f2
TL
107 ROCKS_LOG_HEADER(
108 log, " BlobDBOptions.disable_background_tasks: %d",
109 disable_background_tasks);
7c673cae
FG
110}
111
11fdf7f2 112} // namespace blob_db
f67539c2 113} // namespace ROCKSDB_NAMESPACE
11fdf7f2 114#endif