-
Notifications
You must be signed in to change notification settings - Fork 0
/
kvstore.h
53 lines (35 loc) · 1.21 KB
/
kvstore.h
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
#pragma once
#include "disk.h"
#include "index.h"
#include "kvstore_api.h"
#include "skiplist.h"
#include "filter.h"
#include <future>
class KVStore : public KVStoreAPI {
private:
const std::string dir_;
SkipList memtable;
SkipList imm_memtable;
Index index;
Disk disk;
Filter filter;
std::future<void> flush = std::async(std::launch::async, []() { return; });
const uint64_t MAX_MEMTABLE_SIZE = 2U * 1024U * 1024U; // 2MB
uint64_t maxFileNums[maxLevel]{};
const uint64_t MAX_FILE_SIZE = 2U * 1024U * 1024U; // 2MB
public:
explicit KVStore(const std::string &dir);
~KVStore();
void put(uint64_t key, const std::string &s) override;
[[nodiscard]] std::string get(uint64_t key) const override;
void
scan(uint64_t lower, uint64_t upper, std::vector<std::pair<uint64_t, std::string>> &result) const override;
bool del(uint64_t key) override;
void reset() override;
void print() const;
void write_to_disk(int level, const Data &data);
void compact(int level);
bool inRange(uint64_t lower, uint64_t upper, const Range &range);
void wal(const std::string &method, uint64_t key, const std::string &value);
void recover_memtable();
};