-
Notifications
You must be signed in to change notification settings - Fork 0
/
rocksdb-handle.cpp
30 lines (22 loc) · 994 Bytes
/
rocksdb-handle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "rocksdb-handle.h"
std::shared_ptr<RocksDBHandle> OpenRocksDB(std::string const& dbname) {
rocksdb::DB* ptr;
rocksdb::DBOptions opts;
opts.create_if_missing = true;
opts.create_missing_column_families = true;
rocksdb::ColumnFamilyOptions defaultFamily;
rocksdb::ColumnFamilyOptions logFamily;
std::vector<rocksdb::ColumnFamilyDescriptor> families;
families.emplace_back(rocksdb::kDefaultColumnFamilyName, defaultFamily);
families.emplace_back("logs", logFamily);
std::vector<rocksdb::ColumnFamilyHandle*> handles;
auto status = rocksdb::DB::Open(opts, dbname, families, &handles, &ptr);
if (!status.ok()) {
throw std::runtime_error(status.ToString());
}
std::unique_ptr<rocksdb::DB> db_ptr{ptr};
std::unique_ptr<rocksdb::ColumnFamilyHandle> defs_ptr{handles[0]};
std::unique_ptr<rocksdb::ColumnFamilyHandle> logs_ptr{handles[1]};
return std::make_shared<RocksDBHandle>(std::move(db_ptr), std::move(defs_ptr),
std::move(logs_ptr));
}