-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
74 lines (67 loc) · 2.38 KB
/
main.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
#include <rocksdb/db.h>
#include <rocksdb/table.h>
#include <iostream>
#include <random>
#include <cstdint>
#include <chrono>
void status(rocksdb::Status status) {
if (!status.ok()) {
std::cout << status.getState() << std::endl;
std::terminate();
}
}
void populate(rocksdb::DB* db, int tuples)
{
// for a tuple we do not create the correct schema.
// Instead we make sure that bytes 4-7 contain the correct
// column B
char row[72];
uint64_t key = 0;
int32_t max = std::numeric_limits<int32_t>::min();
std::mt19937 dev;
std::uniform_int_distribution<int32_t> dist;
std::uniform_int_distribution<char> cdist;
for (int i = 0; i < 72; ++i) {
*(row + i) = cdist(dev);
}
rocksdb::WriteOptions options;
for (int i = 0; i < tuples; ++i) {
int32_t d = dist(dev);
max = std::max(d, max);
*reinterpret_cast<int32_t*>(row + 4) = d;
db->Put(options, rocksdb::Slice(reinterpret_cast<char*>(&key), sizeof(key)), rocksdb::Slice(row, 72));
++key;
}
std::cout << "Done with Population - max is: " << max << std::endl;
}
using Clock = std::chrono::steady_clock;
int main(int argc, char** argv)
{
std::string dbPath = "/tmp/db";
if (argc > 1 )
dbPath = argv[1];
rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
options.error_if_exists = true;
options.allow_mmap_reads = true;
options.compression = rocksdb::CompressionType::kNoCompression;
options.target_file_size_base = 256 * 1024 * 1024;
std::cout<< "Using database in " << dbPath << std::endl;
status(rocksdb::DB::Open(options, dbPath, &db));
std::unique_ptr<rocksdb::DB> dbptr(db); // for deletion
rocksdb::ReadOptions roptions;
roptions.verify_checksums = false;
rocksdb::WriteOptions woptions;
populate(db, 12500000);
auto begin = Clock::now();
std::unique_ptr<rocksdb::Iterator> iter(db->NewIterator(roptions));
int32_t max = std::numeric_limits<int32_t>::min();
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
int32_t d = *reinterpret_cast<const int32_t*>(iter->value().data() + 4);
max = std::max(d, max);
}
auto end = Clock::now();
std::cout << "Max is " << max << std::endl;
std::cout << "Time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << " ms" << std::endl;
}