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).
8 #include "utilities/blob_db/blob_db.h"
12 #include "logging/logging.h"
13 #include "utilities/blob_db/blob_db_impl.h"
15 namespace ROCKSDB_NAMESPACE
{
18 Status
BlobDB::Open(const Options
& options
, const BlobDBOptions
& bdb_options
,
19 const std::string
& dbname
, BlobDB
** blob_db
) {
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
,
30 assert(handles
.size() == 1);
31 // i can delete the handle since DBImpl is always holding a reference to
32 // default column family
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
,
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.");
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
);
55 *blob_db
= static_cast<BlobDB
*>(blob_db_impl
);
57 if (!handles
->empty()) {
58 for (ColumnFamilyHandle
* cfh
: *handles
) {
59 blob_db_impl
->DestroyColumnFamilyHandle(cfh
);
71 BlobDB::BlobDB() : StackableDB(nullptr) {}
73 void BlobDBOptions::Dump(Logger
* log
) const {
75 log
, " BlobDBOptions.blob_dir: %s",
78 log
, " BlobDBOptions.path_relative: %d",
81 log
, " BlobDBOptions.is_fifo: %d",
84 log
, " BlobDBOptions.max_db_size: %" PRIu64
,
87 log
, " BlobDBOptions.ttl_range_secs: %" PRIu64
,
90 log
, " BlobDBOptions.min_blob_size: %" PRIu64
,
93 log
, " BlobDBOptions.bytes_per_sync: %" PRIu64
,
96 log
, " BlobDBOptions.blob_file_size: %" PRIu64
,
99 log
, " BlobDBOptions.compression: %d",
100 static_cast<int>(compression
));
102 log
, " BlobDBOptions.enable_garbage_collection: %d",
103 enable_garbage_collection
);
105 log
, " BlobDBOptions.garbage_collection_cutoff: %f",
106 garbage_collection_cutoff
);
108 log
, " BlobDBOptions.disable_background_tasks: %d",
109 disable_background_tasks
);
112 } // namespace blob_db
113 } // namespace ROCKSDB_NAMESPACE