2017-05-10 23:54:35 +02:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2017-05-10 23:54:35 +02:00
|
|
|
//
|
2016-08-09 19:16:32 +02:00
|
|
|
#ifndef ROCKSDB_LITE
|
2017-05-10 23:54:35 +02:00
|
|
|
|
2017-08-01 21:48:22 +02:00
|
|
|
#ifndef __STDC_FORMAT_MACROS
|
|
|
|
#define __STDC_FORMAT_MACROS
|
|
|
|
#endif
|
|
|
|
|
2017-05-10 23:54:35 +02:00
|
|
|
#include "utilities/blob_db/blob_db.h"
|
2017-08-01 21:48:22 +02:00
|
|
|
|
|
|
|
#include <inttypes.h>
|
2017-05-10 23:54:35 +02:00
|
|
|
#include "utilities/blob_db/blob_db_impl.h"
|
2016-08-09 19:16:32 +02:00
|
|
|
|
|
|
|
namespace rocksdb {
|
2017-05-10 23:54:35 +02:00
|
|
|
namespace blob_db {
|
2016-08-09 19:16:32 +02:00
|
|
|
|
2017-05-10 23:54:35 +02:00
|
|
|
Status BlobDB::Open(const Options& options, const BlobDBOptions& bdb_options,
|
|
|
|
const std::string& dbname, BlobDB** blob_db) {
|
|
|
|
*blob_db = nullptr;
|
|
|
|
DBOptions db_options(options);
|
|
|
|
ColumnFamilyOptions cf_options(options);
|
|
|
|
std::vector<ColumnFamilyDescriptor> column_families;
|
|
|
|
column_families.push_back(
|
|
|
|
ColumnFamilyDescriptor(kDefaultColumnFamilyName, cf_options));
|
|
|
|
std::vector<ColumnFamilyHandle*> handles;
|
|
|
|
Status s = BlobDB::Open(db_options, bdb_options, dbname, column_families,
|
|
|
|
&handles, blob_db);
|
|
|
|
if (s.ok()) {
|
|
|
|
assert(handles.size() == 1);
|
|
|
|
// i can delete the handle since DBImpl is always holding a reference to
|
|
|
|
// default column family
|
|
|
|
delete handles[0];
|
2016-08-09 19:16:32 +02:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2017-12-11 21:01:22 +01:00
|
|
|
Status BlobDB::Open(const DBOptions& db_options,
|
2017-05-10 23:54:35 +02:00
|
|
|
const BlobDBOptions& bdb_options, const std::string& dbname,
|
|
|
|
const std::vector<ColumnFamilyDescriptor>& column_families,
|
2017-12-11 21:01:22 +01:00
|
|
|
std::vector<ColumnFamilyHandle*>* handles,
|
|
|
|
BlobDB** blob_db) {
|
2017-11-03 01:26:46 +01:00
|
|
|
if (column_families.size() != 1 ||
|
|
|
|
column_families[0].name != kDefaultColumnFamilyName) {
|
|
|
|
return Status::NotSupported(
|
|
|
|
"Blob DB doesn't support non-default column family.");
|
|
|
|
}
|
|
|
|
|
2017-12-11 21:01:22 +01:00
|
|
|
BlobDBImpl* blob_db_impl = new BlobDBImpl(dbname, bdb_options, db_options,
|
|
|
|
column_families[0].options);
|
|
|
|
Status s = blob_db_impl->Open(handles);
|
|
|
|
if (s.ok()) {
|
|
|
|
*blob_db = static_cast<BlobDB*>(blob_db_impl);
|
|
|
|
} else {
|
|
|
|
delete blob_db_impl;
|
|
|
|
*blob_db = nullptr;
|
2016-08-09 19:16:32 +02:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
2017-05-10 23:54:35 +02:00
|
|
|
|
2017-12-11 21:01:22 +01:00
|
|
|
BlobDB::BlobDB() : StackableDB(nullptr) {}
|
2017-05-10 23:54:35 +02:00
|
|
|
|
2017-08-01 21:48:22 +02:00
|
|
|
void BlobDBOptions::Dump(Logger* log) const {
|
2017-11-02 23:47:30 +01:00
|
|
|
ROCKS_LOG_HEADER(log, " blob_db_options.blob_dir: %s",
|
2017-08-01 21:48:22 +02:00
|
|
|
blob_dir.c_str());
|
2017-11-02 23:47:30 +01:00
|
|
|
ROCKS_LOG_HEADER(log, " blob_db_options.path_relative: %d",
|
2017-08-01 21:48:22 +02:00
|
|
|
path_relative);
|
2017-11-02 23:47:30 +01:00
|
|
|
ROCKS_LOG_HEADER(log, " blob_db_options.is_fifo: %d",
|
2017-08-01 21:48:22 +02:00
|
|
|
is_fifo);
|
2017-11-02 23:47:30 +01:00
|
|
|
ROCKS_LOG_HEADER(log, " blob_db_options.blob_dir_size: %" PRIu64,
|
2017-08-01 21:48:22 +02:00
|
|
|
blob_dir_size);
|
2017-11-02 23:47:30 +01:00
|
|
|
ROCKS_LOG_HEADER(log, " blob_db_options.ttl_range_secs: %" PRIu32,
|
2017-08-01 21:48:22 +02:00
|
|
|
ttl_range_secs);
|
2017-11-02 23:47:30 +01:00
|
|
|
ROCKS_LOG_HEADER(log, " blob_db_options.bytes_per_sync: %" PRIu64,
|
2017-08-01 21:48:22 +02:00
|
|
|
bytes_per_sync);
|
2017-11-02 23:47:30 +01:00
|
|
|
ROCKS_LOG_HEADER(log, " blob_db_options.blob_file_size: %" PRIu64,
|
2017-08-01 21:48:22 +02:00
|
|
|
blob_file_size);
|
2017-11-02 23:47:30 +01:00
|
|
|
ROCKS_LOG_HEADER(log, " blob_db_options.ttl_extractor: %p",
|
2017-08-01 21:48:22 +02:00
|
|
|
ttl_extractor.get());
|
2017-11-02 23:47:30 +01:00
|
|
|
ROCKS_LOG_HEADER(log, " blob_db_options.compression: %d",
|
2017-08-01 21:48:22 +02:00
|
|
|
static_cast<int>(compression));
|
2017-11-02 23:47:30 +01:00
|
|
|
ROCKS_LOG_HEADER(log, "blob_db_options.enable_garbage_collection: %d",
|
|
|
|
enable_garbage_collection);
|
|
|
|
ROCKS_LOG_HEADER(log, " blob_db_options.disable_background_tasks: %d",
|
2017-08-01 21:48:22 +02:00
|
|
|
disable_background_tasks);
|
|
|
|
}
|
2017-05-10 23:54:35 +02:00
|
|
|
|
|
|
|
} // namespace blob_db
|
2016-08-09 19:16:32 +02:00
|
|
|
} // namespace rocksdb
|
2017-05-10 23:54:35 +02:00
|
|
|
#endif
|