-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathhash_api.h
More file actions
403 lines (384 loc) · 11.6 KB
/
Copy pathhash_api.h
File metadata and controls
403 lines (384 loc) · 11.6 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#include <string>
constexpr size_t pool_size = 1024ul * 1024ul * 1024ul * 128ul;
std::string index_pool_name = "/mnt/pmem/hash/";
#ifdef HALOT
#define NONVAR 1
// #define VARVALUE 1
#include "Halo/Halo.hpp"
using namespace HALO;
class hash_api {
public:
#ifdef NONVAR
Halo<size_t, size_t> *t;
#elif VARVALUE
Halo<size_t, std::string> *t;
#else
Halo<std::string, std::string> *t;
#endif
hash_api(size_t sz = 16 * 1024 * 1024) {
PM_PATH = "/mnt/pmem/hash/HaLo/";
#ifdef NONVAR
t = new Halo<size_t, size_t>(sz);
#elif VARVALUE
t = new Halo<size_t, std::string>(sz);
#else
t = new Halo<std::string, std::string>(sz);
#endif
}
~hash_api() { delete t; }
std::string hash_name() { return "Halo"; };
bool find(size_t key, void *p) {
#ifdef NONVAR
auto pt = reinterpret_cast<Pair_t<size_t, size_t> *>(p);
pt->set_key(key);
#elif VARVALUE
auto pt = reinterpret_cast<Pair_t<size_t, std::string> *>(p);
pt->set_key(key);
#else
auto pt = reinterpret_cast<Pair_t<std::string, std::string> *>(p);
pt->set_key(reinterpret_cast<char *>(&key), 8);
#endif
return t->Get(pt);
}
bool insert(size_t key, size_t value_len, char *value, int tid = 0,
int *r = nullptr) {
#ifdef NONVAR
Pair_t<size_t, size_t> p(key, *reinterpret_cast<size_t *>(value));
#elif VARVALUE
Pair_t<size_t, std::string> p(key, value, value_len);
#else
Pair_t<std::string, std::string> p(reinterpret_cast<char *>(&key), 8, value,
value_len);
#endif
return t->Insert(p, r);
}
bool update(size_t key, size_t value_len, char *value, int tid = 0,
int *r = nullptr) {
#ifdef NONVAR
Pair_t<size_t, size_t> p(key, *reinterpret_cast<size_t *>(value));
#elif VARVALUE
Pair_t<size_t, std::string> p(key, value, value_len);
#else
Pair_t<std::string, std::string> p(reinterpret_cast<char *>(&key), 8, value,
value_len);
#endif
return t->Update(p);
}
bool erase(size_t key, int tid = 0) {
#ifdef NONVAR
Pair_t<size_t, size_t> p;
p.set_key(key);
#elif VARVALUE
Pair_t<size_t, std::string> p;
p.set_key(key);
#else
Pair_t<std::string, std::string> p;
p.set_key(reinterpret_cast<char *>(&key), 8);
#endif
t->Delete(p);
return true;
}
void wait() { t->wait_all(); }
void load_factor() { t->load_factor(); }
};
#endif
#ifdef CCEHT
#include "third/CCEH/CCEH_baseline.h"
class hash_api {
public:
cceh::CCEH<size_t> *cceh;
hash_api(size_t sz = 1024 * 16) {
bool file_exist = false;
index_pool_name += "CCEH.data";
if (FileExists(index_pool_name.c_str())) file_exist = true;
Allocator::Initialize(index_pool_name.c_str(), pool_size);
cceh = reinterpret_cast<cceh::CCEH<size_t> *>(
Allocator::GetRoot(sizeof(cceh::CCEH<size_t>)));
if (!file_exist) {
new (cceh) cceh::CCEH<size_t>(sz, Allocator::Get()->pm_pool_);
} else {
new (cceh) cceh::CCEH<size_t>();
}
}
~hash_api() { Allocator::Close_pool(); }
std::string hash_name() { return "CCEH"; };
bool find(size_t key) {
cceh->Get(key);
return true;
};
bool insert(size_t key, size_t value_len, char *value, int tid = 0,
int *r = nullptr) {
cceh->Insert(key, DEFAULT);
return true;
}
bool update(size_t key, size_t value_len, char *value, int tid = 0,
int *r = nullptr) {
return false;
}
bool erase(size_t key, int tid = 0) {
cceh->Delete(key);
return true;
}
void wait() {}
void load_factor() {}
};
#endif
#ifdef DASHT
#include "third/Dash/ex_finger.h"
class hash_api {
public:
extendible::Finger_EH<size_t> *dash;
// sz is the number of segment.
hash_api(size_t sz = 1024 * 16) {
bool file_exist = false;
index_pool_name += "DASH.data";
if (FileExists(index_pool_name.c_str())) file_exist = true;
Allocator::Initialize(index_pool_name.c_str(), pool_size);
dash = reinterpret_cast<extendible::Finger_EH<size_t> *>(
Allocator::GetRoot(sizeof(extendible::Finger_EH<size_t>)));
if (!file_exist) {
new (dash) extendible::Finger_EH<size_t>(sz, Allocator::Get()->pm_pool_);
} else {
new (dash) extendible::Finger_EH<size_t>();
}
}
~hash_api() { Allocator::Close_pool(); }
std::string hash_name() { return "Dash"; };
bool find(size_t key) {
dash->Get(key);
return true;
};
bool insert(size_t key, size_t value_len, char *value, int tid = 0,
int *r = nullptr) {
dash->Insert(key, DEFAULT);
return true;
}
bool update(size_t key, size_t value_len, char *value, int tid = 0,
int *r = nullptr) {
return false;
}
bool erase(size_t key, int tid = 0) {
dash->Delete(key);
return true;
}
void wait() {}
void load_factor() {}
};
#endif
#ifdef CLEVELT
#include <filesystem>
// clang-format off
#include "third/CLevel/libpmemobj++/make_persistent.hpp"
#include "third/CLevel/libpmemobj++/p.hpp"
#include "third/CLevel/libpmemobj++/persistent_ptr.hpp"
#include "third/CLevel/libpmemobj++/pool.hpp"
#include "third/CLevel/src/libpmemobj_cpp_examples_common.hpp"
#include "third/CLevel/libpmemobj++/experimental/clevel_hash.hpp"
// clang-format on
#define LAYOUT "clevel_hash"
namespace nvobj = pmem::obj;
class hash_api {
typedef nvobj::experimental::clevel_hash<nvobj::p<uint64_t>,
nvobj::p<uint64_t>>
persistent_map_type;
struct root {
nvobj::persistent_ptr<persistent_map_type> cons;
};
nvobj::pool<root> pop;
nvobj::persistent_ptr<persistent_map_type> map;
public:
hash_api(size_t sz = 1024 * 16, int tnum = 32) {
const char *path = "/mnt/pmem/pmem.data ";
if (!std::filesystem::exists(path))
pop =
nvobj::pool<root>::create(path, LAYOUT, pool_size, S_IWUSR | S_IRUSR);
else
pop = nvobj::pool<root>::open(path, LAYOUT);
auto proot = pop.root();
nvobj::transaction::manual tx(pop);
proot->cons = nvobj::make_persistent<persistent_map_type>();
proot->cons->set_thread_num(tnum);
map = proot->cons;
nvobj::transaction::commit();
}
~hash_api() { pop.close(); }
std::string hash_name() { return "CLevel"; };
bool find(size_t key) {
pmem::obj::p<uint64_t> k = key;
auto r = map->search(persistent_map_type::key_type(k));
return true;
};
bool insert(size_t key, size_t value_len, char *value, int tid,
int *r = nullptr) {
auto rr = map->insert(persistent_map_type::value_type(key, key), tid);
return true;
}
bool update(size_t key, size_t value_len, char *value, int tid = 0,
int *r = nullptr) {
auto rr = map->update(persistent_map_type::value_type(key, key + 1), tid);
return true;
}
bool erase(size_t key, int tid) {
auto r = map->erase(persistent_map_type::key_type(key), tid);
return true;
}
void wait() {}
void load_factor() {}
};
#endif
#ifdef PCLHTT
#include "third/PCLHT/clht_lb_res.h"
class hash_api {
public:
PCLHT::clht_t *iclht;
hash_api(size_t sz = 1024 * 1024 * 16) {
sz = log2(sz / ENTRIES_PER_BUCKET);
sz = pow(2, sz);
iclht = PCLHT::clht_create(sz);
}
bool find(size_t key) {
auto r = PCLHT::clht_get(iclht, key);
return true;
}
std::string hash_name() { return "PCLHT"; };
bool insert(size_t key, size_t value_len, char *value, int tid,
int *r = nullptr) {
PCLHT::clht_put(iclht, key, key);
return true;
}
bool update(size_t key, size_t value_len, char *value, int tid = 0,
int *r = nullptr) {
// PCLHT::clht_put_replace(iclht, key, key);
return false;
}
bool erase(size_t key, int tid) {
PCLHT::clht_remove(iclht, key);
return true;
}
void wait() {}
void load_factor() {}
};
#endif
#ifdef CLHTT
#include "third/CLHT/include/clht_lb_res.h"
class hash_api {
public:
clht_t *iclht;
hash_api(size_t sz = 1024 * 1024 * 16) {
sz = log2(sz / ENTRIES_PER_BUCKET);
sz = pow(2, sz);
iclht = clht_create(sz);
}
bool find(size_t key) {
auto r = clht_get(iclht->ht, key);
return true;
}
std::string hash_name() { return "CLHT"; };
bool insert(size_t key, size_t value_len, char *value, int tid,
int *r = nullptr) {
clht_put(iclht, key, key);
return true;
}
bool update(size_t key, size_t value_len, char *value, int tid = 0,
int *r = nullptr) {
// clht_put_replace(iclht, key, key);
return false;
}
bool erase(size_t key, int tid) {
clht_remove(iclht, key);
return true;
}
void wait() {}
void load_factor() {}
};
#endif
#ifdef SOFTT
#include "third/SOFT/SOFTList.h"
constexpr size_t BUCKET_NUM = 16 * 1024 * 1024;
class hash_api {
public:
hash_api() { table = new SOFTList<size_t>[BUCKET_NUM]; }
std::string hash_name() { return "SOFT"; };
bool insert(size_t key, size_t value_len, char *value, int tid,
int *r = nullptr) {
SOFTList<size_t> &bucket = getBucket(key);
bucket.insert(key, key);
return true;
}
bool update(size_t key, size_t value_len, char *value, int tid,
int *r = nullptr) {
return true;
}
void thread_ini(int id) {
init_alloc(id);
init_volatileAlloc(id);
}
bool find(size_t key) {
SOFTList<size_t> &bucket = getBucket(key);
auto r = bucket.contains(key);
return true;
}
bool erase(size_t key, int tid) {
SOFTList<size_t> &bucket = getBucket(key);
bucket.remove(key);
return true;
}
void load_factor() {}
void wait() {}
private:
static size_t h(size_t k, size_t _len = 8,
size_t _seed = static_cast<size_t>(0xc70f6907UL)) {
auto _ptr = reinterpret_cast<void *>(&k);
return std::_Hash_bytes(_ptr, _len, _seed);
}
SOFTList<size_t> &getBucket(uintptr_t k) { return table[h(k) % BUCKET_NUM]; }
SOFTList<size_t> *table;
};
#endif
#ifdef VIPERT
#include <filesystem>
#include "third/viper/viper.hpp"
class hash_api {
public:
std::unique_ptr<viper::Viper<uint64_t, uint64_t>> viper_db;
hash_api() {
const size_t inital_size = pool_size;
index_pool_name += "VIPER.data";
if (!std::filesystem::exists(index_pool_name))
viper_db = viper::Viper<uint64_t, uint64_t>::create(index_pool_name,
inital_size);
else
viper_db = viper::Viper<uint64_t, uint64_t>::open(index_pool_name);
}
~hash_api() {}
std::string hash_name() { return "Viper"; };
bool find(size_t key, viper::Viper<uint64_t, uint64_t>::Client &c,
uint64_t *v) {
auto r = c.get(key, v);
return true;
}
bool insert(size_t key, size_t value_len, char *value,
viper::Viper<uint64_t, uint64_t>::Client &c) {
c.put(key, key);
return true;
}
bool update(size_t key, size_t value_len, char *value,
viper::Viper<uint64_t, uint64_t>::Client &c) {
c.put(key, key + 1);
return true;
}
viper::Viper<uint64_t, uint64_t>::Client get_client() {
return viper_db->get_client();
}
bool erase(size_t key, viper::Viper<uint64_t, uint64_t>::Client &c) {
c.remove(key);
return true;
}
void wait() {}
void load_factor(viper::Viper<uint64_t, uint64_t>::Client &c) {
// cout << "get_total_used_pmem: " << c.get_total_used_pmem() << endl;
// cout << "get_total_allocated_pmem: " << c.get_total_allocated_pmem()
// << endl;
}
};
#endif