-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathresize-example.cc
82 lines (70 loc) · 2.18 KB
/
resize-example.cc
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
#include "lmdb-safe.hh"
#include <string.h>
using namespace std;
int main(int argc, char** argv)
{
auto env = getMDBEnv("resize", MDB_NOSUBDIR | MDB_NOSYNC, 0600);
auto main = env->openDB("ahu", MDB_CREATE );
MDBInVal key("counter");
auto rwtxn = env->getRWTransaction();
rwtxn->put(main, "counter", "1234");
rwtxn->put(main, MDBInVal::fromStruct(std::make_pair(12,13)), "hoi dan 12,13");
rwtxn->put(main, MDBInVal::fromStruct(std::make_pair(14,15)),
MDBInVal::fromStruct(std::make_pair(20,23)));
MDBOutVal out;
if(!rwtxn->get(main, MDBInVal::fromStruct(std::make_pair(12,13)), out))
cout << "Got: " << out.get<string_view>() << endl;
else
cout << "Got nothing!1"<<endl;
if(!rwtxn->get(main, MDBInVal::fromStruct(std::make_pair(14,15)), out)) {
auto res = out.get_struct<pair<int,int>>();
cout << "Got: " << res.first<<", "<<res.second << endl;
}
else
cout << "Got nothing!1"<<endl;
rwtxn->put(main, 12.12, 7.3);
if(!rwtxn->get(main, 12.12, out)) {
cout<<"Got: "<< out.get<double>() <<endl;
}
else
cout << "Got nothing!1"<<endl;
rwtxn->commit();
return 0;
if(argc==1) {
for(;;) {
auto rotxn = env->getROTransaction();
MDBOutVal data;
if(!rotxn->get(main, key, data)) {
cout<<"Counter is "<<data.get<unsigned int>() << endl;
cout <<data.get<string>() << endl;
cout<<data.get<string_view>() << endl;
struct Bert
{
uint16_t x,y;
};
auto b = data.get_struct<Bert>();
cout<<b.x<<" "<<b.y<<endl;
cout<<data.get<unsigned long>() << endl;
}
else
cout<<"Didn't find it"<<endl;
exit(1);
}
}
else {
size_t size = 1ULL*4096*244140ULL;
for(unsigned int n=0;;++n) {
if(!(n%16384)) {
size += 16384;
if(int rc=mdb_env_set_mapsize(*env.get(), size))
throw std::runtime_error("Resizing: "+string(mdb_strerror(rc)));
cout<<"Did resize"<<endl;
}
auto txn = env->getRWTransaction();
txn->put(main, key, MDBInVal(n));
for(int k=0; k < 100; ++k)
txn->put(main, MDBInVal(n+1000*k), MDBInVal(n+1000*k));
txn->commit();
}
}
}