-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathycsbc_test.cc
210 lines (186 loc) · 6.71 KB
/
ycsbc_test.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//
// ycsbc.cc
// YCSB-C
//
// Created by Jinglei Ren on 12/19/14.
// Copyright (c) 2014 Jinglei Ren <[email protected]>.
//
#include <cstring>
#include <string>
#include <iostream>
#include <vector>
#include <future>
#include "core/utils.h"
#include "core/timer.h"
#include "core/client.h"
#include "core/core_workload.h"
#include "db/db_factory.h"
using namespace std;
#define MAX_VAL 100
void TestUsageMessage(const char *command);
bool TestStrStartWith(const char *str, const char *pre);
string TestParseCommandLine(int argc, const char *argv[], utils::Properties &props);
int main(const int argc, const char *argv[]) {
utils::Properties props;
string file_name = TestParseCommandLine(argc, argv, props);
ycsbc::DB *db = ycsbc::DBFactory::CreateDB(props);
if (!db) {
cout << "Unknown database name " << props["dbname"] << endl;
exit(0);
}
ycsbc::CoreWorkload wl;
wl.Init(props);
// Loads data
db->Init();
std::string tableName = "ycsb_test";
for(uint64_t key=1; key<=MAX_VAL; key+=1) {
std::vector <ycsbc::DB::KVPair> values;
ycsbc::DB::KVPair pair;
pair.first.append("field");
pair.second.append(std::to_string(key));
values.push_back(pair);
assert(db->Insert(tableName, key, values) == ycsbc::DB::kOK);
}
db->Close();
// Perform read
db->Init();
for(uint64_t key=1; key<=MAX_VAL; key+=1) {
std::vector <ycsbc::DB::Kuint64VstrPair> result;
assert(db->Read(tableName, key, NULL, result) == ycsbc::DB::kOK);
//cout << result[0].first << " " << result[0].second << endl;
assert(std::to_string(result[0].first).compare(result[0].second) == 0);
}
db->Close();
cout << "load passed!" << endl;
// Update data
db->Init();
for(uint64_t key=1; key<=MAX_VAL; key+=1) {
std::vector <ycsbc::DB::KVPair> values;
ycsbc::DB::KVPair pair;
pair.first.append("field");
pair.second.append(std::to_string(MAX_VAL-key));
values.push_back(pair);
assert(db->Update(tableName, key, values) == ycsbc::DB::kOK);
}
db->Close();
// Perform read
db->Init();
for(uint64_t key=1; key<=MAX_VAL; key+=1) {
std::vector <ycsbc::DB::Kuint64VstrPair> result;
assert(db->Read(tableName, key, NULL, result) == ycsbc::DB::kOK);
//cout << result[0].first << " " << result[0].second << endl;
assert(std::to_string(MAX_VAL-key).compare(result[0].second) == 0);
}
//perform scan
/*std::vector <std::vector<ycsbc::DB::Kuint64VstrPair>> result;
assert(db->Scan(tableName, 1, 200, NULL, result) == ycsbc::DB::kOK);
for(int i=0; i<result.size(); i+=1) {
std::vector<ycsbc::DB::Kuint64VstrPair> tmp = result[i];
cout << tmp[0].first << " " << tmp[0].second << endl;
}*/
db->Close();
cout << "update passed!" << endl;
if (db) db->~DB();
}
string TestParseCommandLine(int argc, const char *argv[], utils::Properties &props) {
int argindex = 1;
string filename;
while (argindex < argc && TestStrStartWith(argv[argindex], "-")) {
if (strcmp(argv[argindex], "-threads") == 0) {
argindex++;
if (argindex >= argc) {
TestUsageMessage(argv[0]);
exit(0);
}
props.SetProperty("threadcount", argv[argindex]);
argindex++;
} else if (strcmp(argv[argindex], "-db") == 0) {
argindex++;
if (argindex >= argc) {
TestUsageMessage(argv[0]);
exit(0);
}
props.SetProperty("dbname", argv[argindex]);
argindex++;
} else if (strcmp(argv[argindex], "-type") == 0) {
// -type is only with storedsDB, it denotes the inner data structures we will use
argindex++;
if (argindex >= argc) {
TestUsageMessage(argv[0]);
exit(0);
}
props.SetProperty("type", argv[argindex]);
argindex++;
} else if (strcmp(argv[argindex], "-dbpath") == 0) {
// -dbpath is only with storedsDB, it shows where the db file is
argindex++;
if (argindex >= argc) {
TestUsageMessage(argv[0]);
exit(0);
}
props.SetProperty("dbpath", argv[argindex]);
argindex++;
} else if (strcmp(argv[argindex], "-host") == 0) {
argindex++;
if (argindex >= argc) {
TestUsageMessage(argv[0]);
exit(0);
}
props.SetProperty("host", argv[argindex]);
argindex++;
} else if (strcmp(argv[argindex], "-port") == 0) {
argindex++;
if (argindex >= argc) {
TestUsageMessage(argv[0]);
exit(0);
}
props.SetProperty("port", argv[argindex]);
argindex++;
} else if (strcmp(argv[argindex], "-slaves") == 0) {
argindex++;
if (argindex >= argc) {
TestUsageMessage(argv[0]);
exit(0);
}
props.SetProperty("slaves", argv[argindex]);
argindex++;
} else if (strcmp(argv[argindex], "-P") == 0) {
argindex++;
if (argindex >= argc) {
TestUsageMessage(argv[0]);
exit(0);
}
filename.assign(argv[argindex]);
ifstream input(argv[argindex]);
try {
props.Load(input);
} catch (const string &message) {
cout << message << endl;
exit(0);
}
input.close();
argindex++;
} else {
cout << "Unknown option '" << argv[argindex] << "'" << endl;
exit(0);
}
}
if (argindex == 1 || argindex != argc) {
TestUsageMessage(argv[0]);
exit(0);
}
return filename;
}
void TestUsageMessage(const char *command) {
cout << "Usage: " << command << " [options]" << endl;
cout << "Options:" << endl;
cout << " -db dbname: specify the name of the DB to use (default: storeds)" << endl;
cout << " -threads n: execute using n threads (default: 1)" << endl;
cout << " -dbpath dbpath: specify the name of the PMEM memory pool file to be created" << endl;
cout << " -type dsname: specify the name of the data-structure to use" << endl;
cout << " -P propertyfile: load properties from the given file. Multiple files can" << endl;
cout << " be specified, and will be processed in the order specified" << endl;
}
inline bool TestStrStartWith(const char *str, const char *pre) {
return strncmp(str, pre, strlen(pre)) == 0;
}