forked from utsaslab/RECIPE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crash_test.cpp
733 lines (606 loc) · 22.8 KB
/
crash_test.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
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
/*
* crash_test.cpp
*
*/
#include <fstream>
#include <iostream>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <string>
#include "tbb/tbb.h"
#include "ROWEX/Tree.h"
#include "FAST_FAIR/btree.h"
#include "CCEH/src/CCEH-crash.h"
#include "masstree-crash.h"
#include "Bwtree/src/bwtree.h"
#include "Bwtree/test/test_suite.h"
#include "clht.h"
#include "ssmem.h"
#include "WORT/wort.h"
#include "WOART/woart.h"
#include "wbtree/wbtree.h"
#include "fptree/FPTree.h"
#ifdef HOT
#include <hot/rowex/HOTRowex.hpp>
#include <idx/benchmark/Benchmark.hpp>
#include <idx/benchmark/NoThreadInfo.hpp>
#include <idx/contenthelpers/IdentityKeyExtractor.hpp>
#include <idx/contenthelpers/OptionalValue.hpp>
#endif
#define OFFSET 10000
#define stringify( type ) # type
using namespace std;
template<typename ValueType = Key *>
class KeyExtractor {
public:
typedef uint8_t* KeyType;
inline KeyType operator()(ValueType const &value) const {
return value->fkey;
}
};
// key types
enum {
RANDINT_KEY,
STRING_KEY,
};
// index types
enum {
TYPE_PART,
TYPE_PHOT,
TYPE_PBWTREE,
TYPE_PMASSTREE,
TYPE_PCLHT,
TYPE_WORT,
TYPE_WOART,
TYPE_WBTREE,
TYPE_FPTREE,
TYPE_FASTFAIR,
TYPE_LEVELHASH,
TYPE_CCEH,
};
const char* typeIndexName[]= {
stringify(TYPE_PART),
stringify(TYPE_PHOT),
stringify(TYPE_PBWTREE),
stringify(TYPE_PMASSTREE),
stringify(TYPE_PCLHT),
stringify(TYPE_WORT),
stringify(TYPE_WOART),
stringify(TYPE_WBTREE),
stringify(TYPE_FPTREE),
stringify(TYPE_FASTFAIR),
stringify(TYPE_LEVELHASH),
stringify(TYPE_CCEH)
};
const char* typeKeyName[]={
stringify(RANDINT_KEY),
stringify(STRING_KEY)
};
class Error {
typedef struct {
int missingValues = 0;
int incorrectValues = 0;
} errorSummary;
private:
errorSummary es;
public:
void IncrementMissingValue() {
es.missingValues ++;
}
void IncrementIncorrectValue(){
es.incorrectValues ++;
}
void PrintErrorStat(){
fprintf(stderr, "Missing values = %d, incorrect values = %d\n", es.missingValues, es.incorrectValues);
}
bool IsError(){
if (es.missingValues == 0 && es.incorrectValues == 0)
return false;
else
return true;
}
};
struct globalSummary{
int numCrashStates = 0;
int numFailedStates = 0;
};
// global variables
Error errorStat;
globalSummary *gs;
void loadKey(TID tid, Key &key) {
return ;
}
int indexType(string index){
if (!index.compare("p-art"))
return TYPE_PART;
else if (!index.compare("p-hot"))
return TYPE_PHOT;
else if (!index.compare("p-bwtree"))
return TYPE_PBWTREE;
else if (!index.compare("p-clht"))
return TYPE_PCLHT;
else if (!index.compare("p-masstree"))
return TYPE_PMASSTREE;
else if (!index.compare("cceh"))
return TYPE_CCEH;
else
return -1;
}
int keyType(string key_type){
if (!key_type.compare("randint"))
return RANDINT_KEY;
else if (!key_type.compare("string"))
return STRING_KEY;
else
return -1;
}
void testMASSTREE(int total_keys, int num_threads, bool perform_delete, int delete_key_start, int num_delete_keys,
std::vector<Key *> &keysToInsert,
std::vector<Key *> &insertedKeys) {
fprintf(stderr, "\n-------Testing MASSTREE with %d insert keys and %d deletes-----\n", total_keys, num_delete_keys);
std::vector<Key *>::iterator it;
int inserted = 0, deleted = 0, searched = 0;
bool success = true;
masstree::leafnode *init_root = new masstree::leafnode(0);
masstree::masstree *tree = new masstree::masstree(init_root);
// insert keys now
tbb::parallel_for(tbb::blocked_range<uint64_t>(0, total_keys), [&](const tbb::blocked_range<uint64_t> &scope) {
for (uint64_t i = scope.begin(); i != scope.end(); i++) {
//std::cout << "Inserting key " << keysToInsert[i]->fkey << std::endl;
success = tree->put((char *)keysToInsert[i]->fkey, keysToInsert[i]->value);
if (! success){
std::cout << "Inserting key " << keysToInsert[i]->fkey << " failed" << std::endl;
it = find(insertedKeys.begin(), insertedKeys.end(), keysToInsert[i]);
if ( it != insertedKeys.end()){
insertedKeys.erase(it);
}
}
}
});
inserted = insertedKeys.size();
// delete keys now
tbb::parallel_for(tbb::blocked_range<uint64_t>(delete_key_start, delete_key_start + num_delete_keys), [&](const tbb::blocked_range<uint64_t> &scope) {
for (uint64_t i = scope.begin(); i != scope.end() ; i++) {
//std::cout << "Deleting key " << keysToInsert[i]->fkey << std::endl;
success = tree->del((char *)keysToInsert[i]->fkey);
if (!success){
std::cout << "Deleting key " << keysToInsert[i]->fkey << " failed" << std::endl;
continue;
}
it = find(insertedKeys.begin(), insertedKeys.end(), keysToInsert[i]);
if ( it != insertedKeys.end()){
insertedKeys.erase(it);
}
//std::cout << "Removed key "<< keysToInsert[i]->fkey << std::endl;
deleted ++;
}
});
// Reading all keys for now
tbb::parallel_for(tbb::blocked_range<uint64_t>(0, insertedKeys.size()), [&](const tbb::blocked_range<uint64_t> &scope) {
for (uint64_t i = scope.begin(); i != scope.end(); i++) {
//std::cout << " Searching for key " << insertedKeys[i]->fkey << std::endl;
uint64_t *val = reinterpret_cast<uint64_t *> (tree->get((char *)insertedKeys[i]->fkey));
if (!val){
std::cout << "Missing key " << insertedKeys[i]->fkey << std::endl;
errorStat.IncrementMissingValue();
}
else if (*val != insertedKeys[i]->value) {
std::cout << "[MASSTREE] Incorrect value : " << *val << " expected:" << insertedKeys[i]->value << std::endl;
errorStat.IncrementIncorrectValue();
}
//std::cout << "Value for key " << insertedKeys[i]->fkey << " is " << *val << std::endl;
searched ++;
}
});
cout << "Total keys inserted = " << inserted << endl;
cout << "Total keys deleted = " << deleted << endl;
cout << "Total keys searched = " << searched << endl;
gs->numCrashStates++;
errorStat.PrintErrorStat();
if(errorStat.IsError()) {
gs->numFailedStates++;
cout << "ERROR ENCOUNTERED IN THIS CRASH STATE" << endl;
} else {
cout << "Passed clean" << endl;
}
cout << "********* Global summary *********" << endl;
cout << "Crash States : " << gs->numCrashStates << endl;
cout << "Failed States : " << gs->numFailedStates << endl;
cout << "-----------------------------------------------" << endl;
}
#ifdef HOT
void testHOT(int total_keys, int num_threads, bool perform_delete, int delete_key_start, int num_delete_keys,
std::vector<Key *> &keysToInsert,
std::vector<Key *> &insertedKeys) {
fprintf(stderr, "\n-------Testing HOT with %d insert keys and %d deletes-----\n", total_keys, num_delete_keys);
std::vector<Key *>::iterator it;
int inserted = 0, deleted = 0, searched = 0;
bool success;
hot::rowex::HOTRowex<Key *, KeyExtractor> mTrie;
// insert keys now
tbb::parallel_for(tbb::blocked_range<uint64_t>(0, total_keys), [&](const tbb::blocked_range<uint64_t> &scope) {
for (uint64_t i = scope.begin(); i != scope.end(); i++) {
Key *key = key->make_leaf((char *)keysToInsert[i]->fkey, keysToInsert[i]->key_len, keysToInsert[i]->value);
//std::cout << "Inserting key " << keysToInsert[i]->fkey << " : " << keysToInsert[i]->value << std::endl;
success = mTrie.insert(keysToInsert[i]);
if (!success){
std::cout << "Inserting key " << i << " : " << keysToInsert[i]->fkey << " failed" << std::endl;
it = find(insertedKeys.begin(), insertedKeys.end(), keysToInsert[i]);
if ( it != insertedKeys.end()){
insertedKeys.erase(it);
}
}
}
});
inserted = insertedKeys.size();
// Reading all keys for now
tbb::parallel_for(tbb::blocked_range<uint64_t>(0, insertedKeys.size()), [&](const tbb::blocked_range<uint64_t> &scope) {
for (uint64_t i = scope.begin(); i != scope.end(); i++) {
idx::contenthelpers::OptionalValue<Key *> val = mTrie.lookup((uint8_t *)insertedKeys[i]->fkey);
//std::cout << " Value for key " << insertedKeys[i]->fkey << " is " << val.mValue->value << std::endl;
if (! val.mIsValid){
std::cout << "Missing key " << insertedKeys[i]->fkey << std::endl;
errorStat.IncrementMissingValue();
}
//std::cout << "Value for key " << insertedKeys[i]->fkey << " is " << val->value << std::endl;
else if (val.mValue->value != insertedKeys[i]->value) {
std::cout << "[HOT] Incorrect value : " << val.mValue->value << " expected:" << insertedKeys[i]->value << std::endl;
errorStat.IncrementIncorrectValue();
}
searched ++;
}
});
cout << "Total keys inserted = " << inserted << endl;
cout << "Total keys deleted = " << deleted << endl;
cout << "Total keys searched = " << searched << endl;
gs->numCrashStates++;
errorStat.PrintErrorStat();
if(errorStat.IsError()) {
gs->numFailedStates++;
cout << "ERROR ENCOUNTERED IN THIS CRASH STATE" << endl;
} else {
cout << "Passed clean" << endl;
}
cout << "********* Global summary *********" << endl;
cout << "Crash States : " << gs->numCrashStates << endl;
cout << "Failed States : " << gs->numFailedStates << endl;
cout << "-----------------------------------------------" << endl;
}
#endif
void testART(int total_keys, int num_threads, bool perform_delete, int delete_key_start, int num_delete_keys,
std::vector<Key *> &keysToInsert,
std::vector<Key *> &insertedKeys) {
fprintf(stderr, "\n-------Testing ART with %d insert keys and %d deletes-----\n", total_keys, num_delete_keys);
std::vector<Key *>::iterator it;
int inserted = 0, deleted = 0, searched = 0;
ART_ROWEX::Tree tree(loadKey);
// insert keys now
tbb::parallel_for(tbb::blocked_range<uint64_t>(0, total_keys), [&](const tbb::blocked_range<uint64_t> &scope) {
auto t = tree.getThreadInfo();
for (uint64_t i = scope.begin(); i != scope.end(); i++) {
Key *key = key->make_leaf((char *)keysToInsert[i]->fkey, keysToInsert[i]->key_len, keysToInsert[i]->value);
tree.insert(key, t);
}
});
inserted = insertedKeys.size();
// delete keys now
tbb::parallel_for(tbb::blocked_range<uint64_t>(delete_key_start, delete_key_start + num_delete_keys), [&](const tbb::blocked_range<uint64_t> &scope) {
auto t = tree.getThreadInfo();
for (uint64_t i = scope.begin(); i != scope.end() ; i++) {
Key *key = key->make_leaf((char *)keysToInsert[i]->fkey, keysToInsert[i]->key_len, keysToInsert[i]->value);
tree.remove(key, t);
it = find(insertedKeys.begin(), insertedKeys.end(), keysToInsert[i]);
if ( it != insertedKeys.end()){
insertedKeys.erase(it);
}
//std::cout << "Removed key "<< keysToInsert[i]->fkey << std::endl;
deleted ++;
}
});
// Reading all keys for now
tbb::parallel_for(tbb::blocked_range<uint64_t>(0, insertedKeys.size()), [&](const tbb::blocked_range<uint64_t> &scope) {
auto t = tree.getThreadInfo();
for (uint64_t i = scope.begin(); i != scope.end(); i++) {
Key *key = key->make_leaf((char *)insertedKeys[i]->fkey, insertedKeys[i]->key_len, insertedKeys[i]->value);
Key *val = reinterpret_cast<Key *>(tree.lookup(key, t));
if (!val){
std::cout << "Missing key " << insertedKeys[i]->fkey << std::endl;
errorStat.IncrementMissingValue();
}
//std::cout << "Value for key " << insertedKeys[i]->fkey << " is " << val->value << std::endl;
else if (val->value != insertedKeys[i]->value) {
std::cout << "[ART] wrong key read: " << val->value << " expected:" << insertedKeys[i]->value << std::endl;
errorStat.IncrementIncorrectValue();
}
searched ++;
}
});
cout << "Total keys inserted = " << inserted << endl;
cout << "Total keys deleted = " << deleted << endl;
cout << "Total keys searched = " << searched << endl;
gs->numCrashStates++;
errorStat.PrintErrorStat();
if(errorStat.IsError()) {
gs->numFailedStates++;
cout << "ERROR ENCOUNTERED IN THIS CRASH STATE" << endl;
} else {
cout << "Passed clean" << endl;
}
cout << "********* Global summary *********" << endl;
cout << "Crash States : " << gs->numCrashStates << endl;
cout << "Failed States : " << gs->numFailedStates << endl;
cout << "-----------------------------------------------" << endl;
}
void testCCEH(int total_keys, int num_threads, bool perform_delete, int delete_key_start, int num_delete_keys,
std::vector<uint64_t> &keysToInsert,
std::vector<uint64_t> &insertedKeys) {
fprintf(stderr, "\n-------Testing CCEH with %d insert keys and %d deletes-----\n", total_keys, num_delete_keys);
std::vector<uint64_t>::iterator it;
int inserted = 0, deleted = 0, searched = 0;
bool success;
// kNumSlot = 1024
Hash *table = new CCEH((2 * 1024)/Segment::kNumSlot);
// insert keys now
tbb::parallel_for(tbb::blocked_range<uint64_t>(0, total_keys), [&](const tbb::blocked_range<uint64_t> &scope) {
for (uint64_t i = scope.begin(); i != scope.end(); i++) {
std::cout << "Key " << i << " : Inserting " << keysToInsert[i] << std::endl;
success = table->Insert(keysToInsert[i], reinterpret_cast<const char *>(&keysToInsert[i]));
if (! success){
std::cout << "Inserting key " << i << " : " << keysToInsert[i] << " failed" << std::endl;
it = find(insertedKeys.begin(), insertedKeys.end(), keysToInsert[i]);
if ( it != insertedKeys.end()){
insertedKeys.erase(it);
}
}
}
});
inserted = insertedKeys.size();
// delete keys now
tbb::parallel_for(tbb::blocked_range<uint64_t>(delete_key_start, delete_key_start + num_delete_keys), [&](const tbb::blocked_range<uint64_t> &scope) {
for (uint64_t i = scope.begin(); i != scope.end() ; i++) {
success = table->Delete(keysToInsert[i]);
if (!success){
std::cout << "Deleting key " << i << " : " << keysToInsert[i] << " failed" << std::endl;
continue;
}
it = find(insertedKeys.begin(), insertedKeys.end(), keysToInsert[i]);
if ( it != insertedKeys.end()){
insertedKeys.erase(it);
}
//std::cout << "Removed key "<< keysToInsert[i]->fkey << std::endl;
deleted ++;
}
});
std::cout << " Searching keys now" << std::endl;
// Reading all keys for now
tbb::parallel_for(tbb::blocked_range<uint64_t>(0, insertedKeys.size()), [&](const tbb::blocked_range<uint64_t> &scope) {
for (uint64_t i = scope.begin(); i != scope.end(); i++) {
const char* value = table->Get(insertedKeys[i]);
if (value == NONE){
std::cout << "Missing key " << insertedKeys[i] << std::endl;
errorStat.IncrementMissingValue();
continue;
}
//uint64_t *val = reinterpret_cast<uint64_t *>(const_cast<char *>(table->Get(insertedKeys[i])));
uint64_t *val = reinterpret_cast<uint64_t *>(const_cast<char*>(value));
//std::cout << " Key " << i << " : Value for key " << insertedKeys[i]<< " is " << *val << std::endl;
if (*val != insertedKeys[i]) {
std::cout << "[CLHT] Incorrect value: " << *val << " expected:" << insertedKeys[i] << std::endl;
errorStat.IncrementIncorrectValue();
continue;
}
searched ++;
}
});
cout << "Total keys inserted = " << inserted << endl;
cout << "Total keys deleted = " << deleted << endl;
cout << "Total keys searched = " << searched << endl;
gs->numCrashStates++;
errorStat.PrintErrorStat();
if(errorStat.IsError()) {
gs->numFailedStates++;
cout << "ERROR ENCOUNTERED IN THIS CRASH STATE" << endl;
} else {
cout << "Passed clean" << endl;
}
cout << "********* Global summary *********" << endl;
cout << "Crash States : " << gs->numCrashStates << endl;
cout << "Failed States : " << gs->numFailedStates << endl;
cout << "-----------------------------------------------" << endl;
}
void testCLHT(int total_keys, int num_threads, bool perform_delete, int delete_key_start, int num_delete_keys,
std::vector<uint64_t> &keysToInsert,
std::vector<uint64_t> &insertedKeys) {
fprintf(stderr, "\n-------Testing CLHT with %d insert keys and %d deletes-----\n", total_keys, num_delete_keys);
std::vector<uint64_t>::iterator it;
int inserted =0, deleted = 0, searched = 0;
// start with 512 buckets
clht_t *ht = clht_create(1);
clht_gc_thread_init(ht, 0);
ssmem_allocator_t *alloc = (ssmem_allocator_t *) malloc(sizeof(ssmem_allocator_t));
ssmem_alloc_init_fs_size(alloc, SSMEM_DEFAULT_MEM_SIZE, SSMEM_GC_FREE_SET_SIZE, 0);
// insert keys now
for (int i = 0; i < total_keys; i++) {
//std::cout << "Inserting key "<< keysToInsert[i] << std::endl;
clht_put(ht, keysToInsert[i], keysToInsert[i]);
}
inserted = insertedKeys.size();
// delete keys now
for (int i = delete_key_start; i != delete_key_start + num_delete_keys ; i++) {
uintptr_t val = clht_remove(ht, keysToInsert[i]);
if (val != keysToInsert[i])
continue;
it = find(insertedKeys.begin(), insertedKeys.end(), keysToInsert[i]);
if ( it != insertedKeys.end()){
insertedKeys.erase(it);
}
//std::cout << "Removed key "<< keysToInsert[i]->fkey << std::endl;
deleted ++;
}
// Reading all keys for now
for (int i = 0; i < insertedKeys.size(); i++) {
uintptr_t val = clht_get(ht->ht, insertedKeys[i]);
if (val == 0){
std::cout << "Missing key " << insertedKeys[i] << std::endl;
errorStat.IncrementMissingValue();
}
//cout << "Value for key " << insertedKeys[i] << " is " << val << endl;
if (val != insertedKeys[i]) {
std::cout << "[CLHT] Incorrect Value: " << val << " expected:" << insertedKeys[i] << std::endl;
errorStat.IncrementIncorrectValue();
}
searched ++;
}
cout << "Total keys inserted = " << inserted << endl;
cout << "Total keys deleted = " << deleted << endl;
cout << "Total keys searched = " << searched << endl;
gs->numCrashStates++;
errorStat.PrintErrorStat();
if(errorStat.IsError()) {
gs->numFailedStates++;
cout << "ERROR ENCOUNTERED IN THIS CRASH STATE" << endl;
} else {
cout << "Passed clean" << endl;
}
cout << "********* Global summary *********" << endl;
cout << "Crash States : " << gs->numCrashStates << endl;
cout << "Failed States : " << gs->numFailedStates << endl;
cout << "-----------------------------------------------" << endl;
}
int main(int argc, char** argv)
{
// Parsing arguments
int total_keys = 1, delete_key_start = 0, num_delete_keys = 0;
int num_threads = 1;
bool perform_delete = false;
std::string input_keyfile = std::string("../sample.txt").data();
print_flag = true;
int index = 0;
int key_type = 0;
int c;
while((c = getopt(argc, argv, "n:t:i:d:m:p:k:")) != -1) {
switch(c) {
case 'n':
total_keys = atoi(optarg);
break;
case 't':
num_threads = atoi(optarg);
break;
case 'd':
cout << "In delete option" << endl;
perform_delete = true;
delete_key_start = atoi(optarg);
break;
case 'm':
num_delete_keys = atoi(optarg);
break;
case 'i':
input_keyfile = optarg;
break;
case 'p':
index = indexType(optarg);
if (index == -1){
fprintf(stderr, "Unknown index type %s\n", optarg);
exit(1);
}
break;
case 'k':
key_type = keyType(optarg);
if (key_type == -1){
fprintf(stderr, "Unknown key type %s\n", optarg);
exit(1);
}
break;
default:
break;
}
}
// ftok to generate unique key
key_t shmkey = ftok("shmfile",65);
// shmget returns an identifier in shmid
int shmid = shmget(shmkey, 1024, 0666|IPC_CREAT);
// shmat to attach to shared memory
gs = (globalSummary*) shmat(shmid, (void*)0, 0);
//initialize before the start of any process
gs->numCrashStates = 0;
gs->numFailedStates = 0;
// hashmap of inserted keys to facilitate deletes and search after crash
/*map<string, string> keysInserted;
map<string, string>::iterator it;
*/
int count = 0;
ifstream ifs(input_keyfile);
cout << "Reading keys from " << input_keyfile << endl;
if(!ifs) {
cout << "Input key load error" << endl;
exit(-1);
}
if (key_type == STRING_KEY){
std::vector<Key *> keysToInsert;
keysToInsert.reserve(total_keys);
memset(&keysToInsert[0], 0x00, total_keys * sizeof(Key *));
std::vector<Key *> insertedKeys;
insertedKeys.reserve(total_keys);
memset(&insertedKeys[0], 0x00, total_keys * sizeof(Key *));
//Preload keys into the array
std::string key;
uint64_t val;
while ((count < total_keys) && ifs.good()) {
ifs >> key;
val = std::stoul(key.substr(4, key.size()));
keysToInsert.push_back(keysToInsert[count]->make_leaf((char *)key.c_str(), key.size()+1, val));
count++;
}
fprintf(stdout, "Loaded %d keys\n", count);
for (int i = 0; i < keysToInsert.size(); i++)
insertedKeys.push_back(keysToInsert[i]);
// init scheduler
tbb::task_scheduler_init init(num_threads);
// if type ART
if (index == TYPE_PART)
testART(total_keys, num_threads, perform_delete, delete_key_start, num_delete_keys, keysToInsert, insertedKeys);
else if (index == TYPE_PMASSTREE)
testMASSTREE(total_keys, num_threads, perform_delete, delete_key_start, num_delete_keys, keysToInsert, insertedKeys);
#ifdef HOT
else if (index == TYPE_PHOT)
testHOT(total_keys, num_threads, perform_delete, delete_key_start, num_delete_keys, keysToInsert, insertedKeys);
#endif
else {
fprintf(stderr, "\nUnknown combination %s, %s\n", typeIndexName[index], typeKeyName[key_type]);
exit(0);
}
}
else {
std::vector<uint64_t> keysToInsert;
keysToInsert.reserve(total_keys);
memset(&keysToInsert[0], 0x00, total_keys * sizeof(uint64_t));
std::vector<uint64_t> insertedKeys;
insertedKeys.reserve(total_keys);
memset(&insertedKeys[0], 0x00, total_keys * sizeof(uint64_t));
std::vector<uint64_t>::iterator it;
// Preload keys into the array
uint64_t key;
while ((count < total_keys) && ifs.good()) {
ifs >> key;
keysToInsert.push_back(key);
count++;
}
fprintf(stdout, "Loaded %d keys\n", count);
for (int i = 0; i < keysToInsert.size(); i++)
insertedKeys.push_back(keysToInsert[i]);
// init scheduler
tbb::task_scheduler_init init(num_threads);
if (index == TYPE_PCLHT)
testCLHT(total_keys, num_threads, perform_delete, delete_key_start, num_delete_keys, keysToInsert, insertedKeys);
if (index == TYPE_CCEH)
testCCEH(total_keys, num_threads, perform_delete, delete_key_start, num_delete_keys, keysToInsert, insertedKeys);
else {
fprintf(stderr, "\nUnknown combination %s, %s\n", typeIndexName[index], typeKeyName[key_type]);
exit(0);
}
}
// detach every terminating process from shared memory
shmdt(gs);
return 0;
}