-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisk_storage.hpp
69 lines (53 loc) · 1.49 KB
/
disk_storage.hpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef __DISK_STORAGE_HPP_INCLUDED__
#define __DISK_STORAGE_HPP_INCLUDED__
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <leveldb/db.h>
#include <leveldb/write_batch.h>
#include <leveldb/cache.h>
#include <leveldb/filter_policy.h>
#include <boost/foreach.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include "gen-cpp/Numerator.h"
#include "exc.hpp"
#include "memory_storage.hpp"
#include "logger_initializer.hpp"
namespace numerator {
struct KVPair {
NumID key;
std::string value;
KVPair(): key(0) {}
KVPair(NumID k, const std::string &v): key(k), value(v) {}
};
typedef std::vector<KVPair> KVPairs;
typedef std::vector<NumID> Keys;
typedef std::vector<std::string> Values;
typedef std::vector<FailureIdx> Failures;
class DiskStorage {
public:
DiskStorage():
db(NULL),
cache_size(0)
{}
~DiskStorage()
{
delete db;
delete options.block_cache;
delete options.filter_policy;
}
void init(const std::string &path, int cache = 0);
void write(const KVPairs &kv_pairs);
NumID load_in_memory(MemoryStorage &storage);
void lookup(const Keys &keys, Values &values, Failures &failures);
void dump(std::ostream &stream, bool binary_dump=false);
void restore(std::ifstream &stream, bool binary_dump=false);
private:
leveldb::DB *db;
int cache_size;
leveldb::Options options;
};
} // namespace
#endif