-
Notifications
You must be signed in to change notification settings - Fork 1
/
rocksdb.cpp
40 lines (35 loc) · 1.1 KB
/
rocksdb.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
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include "rocksdb.hpp"
#include "rocksdbmerge.h"
RocksDB::RocksDB() {
opts.error_if_exists = true;
opts.create_if_missing = true;
// opts.IncreaseParallelism();
// opts.OptimizeLevelStyleCompaction();
opts.merge_operator.reset(new kmerMergeOperator());
}
void RocksDB::openRO(const std::string& path) {
rocksdb::DB* p;
auto status = rocksdb::DB::OpenForReadOnly(opts, path.c_str(), &p);
db.reset(p);
if (!status.ok()) throw std::runtime_error(status.ToString());
}
void RocksDB::open(const std::string& path) {
rocksdb::DB* p;
auto status = rocksdb::DB::Open(opts, path.c_str(), &p);
db.reset(p);
if (!status.ok()) throw std::runtime_error(status.ToString());
}
void RocksDB::add(const multikmap_t& kmap, const Alphabet& alpha, int K,
DynamicProgress<ProgressBar>* bars) {
PBar p(bars, kmap.size(), "Writing to rocksDB");
for (const auto& [k, v] : kmap) {
auto dec = leftpad(decodeSequenceView(k, alpha), K);
Slice ks(&dec[0], dec.size());
auto s = serialize(v);
db->Merge(writeopts, ks, s);
p.step();
}
p.completeMsg("Merged batch");
p.complete();
}