-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRocksDBOptions.cpp
96 lines (80 loc) · 3 KB
/
RocksDBOptions.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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// Created by Manuja DeSilva on 4/26/20.
//
#include "RocksDBOptions.h"
using namespace std;
bool RocksDBOptions::IsParameterValueValid(int value) {
if (value == -1) {
return false;
} else {
return true;
}
}
void RocksDBOptions::SetBloomFilterSize(int num_bits) {
if (this->IsParameterValueValid(num_bits)) {
this->table_options_.filter_policy.reset(rocksdb::NewBloomFilterPolicy(num_bits, false));
cout << "Set bloom filter size to " << num_bits << " bits." << endl;
} else {
cout << "Using default bloom filter size." << endl;
}
}
void RocksDBOptions::SetLRUCacheSize(int size_in_mb) {
if (this->IsParameterValueValid(size_in_mb)) {
this->table_options_.block_cache = rocksdb::NewLRUCache(size_in_mb << 20);
cout << "Set LRU cache size to " << size_in_mb << " MB." << endl;
} else {
cout << "Using default LRU cache size." << endl;
}
}
void RocksDBOptions::SetMemtableSize(int size_in_mb) {
if (this->IsParameterValueValid(size_in_mb)) {
this->options_.write_buffer_size = size_in_mb << 20;
cout << "Set memtable size to " << size_in_mb << " MB." << endl;
} else {
cout << "Using default memtable size. " << endl;
}
}
void RocksDBOptions::SetCompactionStrategy(int type) {
if (type == 0) {
this->options_.compaction_style = rocksdb::kCompactionStyleLevel;
cout << "Using level style compaction" << endl;
} else if (type == 1) {
this->options_.compaction_style = rocksdb::kCompactionStyleUniversal;
cout << "Using universal style compaction" << endl;
} else {
cout << "Defaulting to level style compaction." << endl;
return;
}
}
void RocksDBOptions::SetNumMemtables(int num_memtables) {
if (this->IsParameterValueValid(num_memtables)) {
this->options_.max_write_buffer_number = num_memtables;
cout << "Set number of memtables to " << num_memtables << endl;
} else {
cout << "Using default number of memtables." << endl;
}
}
void RocksDBOptions::SetMaxBackgroundCompactions(int num) {
this->options_.max_background_compactions = num;
}
void RocksDBOptions::SetMaxBackgroundFlushes(int num) {
this->options_.max_background_flushes = num;
}
void RocksDBOptions::SetBackgroundFlushThreads(int num) {
this->options_.env->SetBackgroundThreads(num, rocksdb::Env::Priority::HIGH);
}
void RocksDBOptions::SetBackgroundCompactThreads(int num_memtables) {
this->options_.env->SetBackgroundThreads(num, rocksdb::Env::Priority::LOW);
}
void RocksDBOptions::SetMaxWriteBuffer(int num) {
this->options_.max_write_buffer_number = num;
}
void RocksDBOptions::SetMinWriteBufferToMerge(int num) {
this->options_.min_write_buffer_number_to_merge = num;
}
rocksdb::Options RocksDBOptions::FinalizeOptions() {
this->options_.table_factory.reset(NewBlockBasedTableFactory(this->table_options_));
return this->options_;
}
//set this->options_ = rocksdb::Options manually
//get options manually after setting