]>
Commit | Line | Data |
---|---|---|
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> |
11fdf7f2 | 11 | #include "utilities/blob_db/blob_db_impl.h" |
7c673cae | 12 | |
f67539c2 | 13 | namespace ROCKSDB_NAMESPACE { |
11fdf7f2 TL |
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]; | |
7c673cae | 32 | } |
7c673cae FG |
33 | return s; |
34 | } | |
35 | ||
11fdf7f2 TL |
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) { | |
20effc67 TL |
41 | assert(handles); |
42 | ||
11fdf7f2 TL |
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."); | |
7c673cae | 47 | } |
7c673cae | 48 | |
11fdf7f2 TL |
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 { | |
20effc67 TL |
55 | if (!handles->empty()) { |
56 | for (ColumnFamilyHandle* cfh : *handles) { | |
57 | blob_db_impl->DestroyColumnFamilyHandle(cfh); | |
58 | } | |
59 | ||
60 | handles->clear(); | |
61 | } | |
62 | ||
11fdf7f2 TL |
63 | delete blob_db_impl; |
64 | *blob_db = nullptr; | |
7c673cae | 65 | } |
7c673cae FG |
66 | return s; |
67 | } | |
68 | ||
11fdf7f2 TL |
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( | |
494da23a | 85 | log, " BlobDBOptions.ttl_range_secs: %" PRIu64, |
11fdf7f2 TL |
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); | |
f67539c2 TL |
102 | ROCKS_LOG_HEADER( |
103 | log, " BlobDBOptions.garbage_collection_cutoff: %f", | |
104 | garbage_collection_cutoff); | |
11fdf7f2 TL |
105 | ROCKS_LOG_HEADER( |
106 | log, " BlobDBOptions.disable_background_tasks: %d", | |
107 | disable_background_tasks); | |
7c673cae FG |
108 | } |
109 | ||
11fdf7f2 | 110 | } // namespace blob_db |
f67539c2 | 111 | } // namespace ROCKSDB_NAMESPACE |
11fdf7f2 | 112 | #endif |