-
Notifications
You must be signed in to change notification settings - Fork 0
/
kvtest.hh
2297 lines (2013 loc) · 62.3 KB
/
kvtest.hh
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
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Masstree
* Eddie Kohler, Yandong Mao, Robert Morris
* Copyright (c) 2012-2013 President and Fellows of Harvard College
* Copyright (c) 2012-2013 Massachusetts Institute of Technology
*
* VLSC Laboratory
* Copyright (c) 2018-2019 Ecole Polytechnique Federale de Lausanne
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, subject to the conditions
* listed in the Masstree LICENSE file. These conditions include: you must
* preserve this copyright notice, and you cannot mention the copyright
* holders in advertising related to the Software without their permission.
* The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
* notice is a summary of the Masstree LICENSE file; the license in that file
* is legally binding.
*/
#ifndef KVTEST_HH
#define KVTEST_HH
#include "json.hh"
#include "misc.hh"
#include "kvproto.hh"
#include <vector>
#include <fstream>
#include <atomic>
#include <cstdio>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <thread>
#include "incll_copy.hh"
#include "incll_globals.hh"
#include "incll_trav.hh"
#ifdef YCSB
#include "ycsb_helper.hh"
#endif //ycsb
#ifdef PERF_WORKLOAD
#include "perf_utils.hh"
thread_local int instructions_fd;
thread_local int cycles_fd;
thread_local int l1dc_references_fd;
thread_local int l1dc_misses_fd;
thread_local int llc_references_fd;
thread_local int llc_misses_fd;
#endif
#ifdef PALLOCATOR
extern PDataAllocator pallocator;
extern int delaycount;
#endif //pallocator
using lcdf::Str;
using lcdf::String;
using lcdf::Json;
extern int kvtest_first_seed;
// Templated KV tests, so we can run them either client/server or linked with
// the kvd binary.
template <typename N>
inline Json& kvtest_set_time(Json& result, const lcdf::String& base, N n, double delta_t)
{
result.set(base, n);
if (delta_t > 0)
result.set(base + "_per_sec", n / delta_t);
return result;
}
template <typename N>
inline Json kvtest_set_time(const Json& result, const lcdf::String& base, N n, double delta_t) {
Json x(result);
kvtest_set_time(x, base, n, delta_t);
return x;
}
template <typename C>
void kvtest_sync_rw1_seed(C &client, int seed)
{
client.rand.reset(seed);
double tp0 = client.now();
unsigned n;
for (n = 0; !client.timeout(0) && n <= client.limit(); ++n) {
int32_t x = (int32_t) client.rand.next();
client.put_sync(x, x + 1);
}
client.wait_all();
double tp1 = client.now();
client.puts_done();
client.notice("now getting\n");
int32_t *a = (int32_t *) malloc(sizeof(int32_t) * n);
assert(a);
client.rand.reset(seed);
for (unsigned i = 0; i < n; ++i)
a[i] = (int32_t) client.rand.next();
for (unsigned i = 0; i < n; ++i)
std::swap(a[i], a[client.rand.next() % n]);
double tg0 = client.now();
unsigned g;
for (g = 0; g < n && !client.timeout(1); ++g)
client.get_check_sync(a[g], a[g] + 1);
client.wait_all();
double tg1 = client.now();
Json result = Json();
kvtest_set_time(result, "puts", n, tp1 - tp0);
kvtest_set_time(result, "gets", g, tg1 - tg0);
kvtest_set_time(result, "ops", n + g, (tp1 - tp0) + (tg1 - tg0));
client.report(result);
free(a);
}
template <typename C>
void kvtest_sync_rw1(C &client)
{
kvtest_sync_rw1_seed(client, kvtest_first_seed + client.id() % 48);
}
template <typename C>
unsigned kvtest_rw1puts_seed(C& client, int seed) {
client.rand.reset(seed);
double tp0 = client.now();
unsigned n;
for (n = 0; !client.timeout(0) && n <= client.limit(); ++n) {
int32_t x = (int32_t) client.rand.next();
client.put(x, x + 1);
}
client.wait_all();
double tp1 = client.now();
client.puts_done();
client.report(kvtest_set_time(Json(), "puts", n, tp1 - tp0));
return n;
}
// do a bunch of inserts to distinct keys, then check that they all showed up.
// sometimes overwrites, but only w/ same value.
// different clients might use same key sometimes.
template <typename C>
void kvtest_rw1_seed(C &client, int seed)
{
unsigned n = kvtest_rw1puts_seed(client, seed);
client.notice("now getting\n");
int32_t *a = (int32_t *) malloc(sizeof(int32_t) * n);
assert(a);
client.rand.reset(seed);
for (unsigned i = 0; i < n; ++i)
a[i] = (int32_t) client.rand.next();
for (unsigned i = 0; i < n; ++i)
std::swap(a[i], a[client.rand.next() % n]);
double tg0 = client.now();
unsigned g;
#if 0
#define BATCH 8
for(g = 0; g+BATCH < n && !client.timeout(1); g += BATCH){
long key[BATCH], expected[BATCH];
for(int i = 0; i < BATCH; i++){
key[i] = a[g+i];
expected[i] = a[g+i] + 1;
}
client.many_get_check(BATCH, key, expected);
}
#else
for (g = 0; g < n && !client.timeout(1); ++g)
client.get_check(a[g], a[g] + 1);
#endif
client.wait_all();
double tg1 = client.now();
Json result = client.report(Json());
kvtest_set_time(result, "gets", g, tg1 - tg0);
double delta_puts = n / result["puts_per_sec"].as_d();
kvtest_set_time(result, "ops", n + g, delta_puts + (tg1 - tg0));
client.report(result);
free(a);
}
template <typename C>
void kvtest_rw1puts(C &client)
{
kvtest_rw1puts_seed(client, kvtest_first_seed + client.id() % 48);
}
template <typename C>
void kvtest_rw1(C &client)
{
kvtest_rw1_seed(client, kvtest_first_seed + client.id() % 48);
}
// do a bunch of inserts to distinct keys, then check that they all showed up.
// sometimes overwrites, but only w/ same value.
// different clients might use same key sometimes.
template <typename C>
void kvtest_rw1long_seed(C &client, int seed)
{
const char * const formats[] = {
"user%u", "machine%u", "opening%u", "fartparade%u"
};
char buf[64];
client.rand.reset(seed);
double tp0 = client.now();
unsigned n;
for (n = 0; !client.timeout(0) && n <= client.limit(); ++n) {
unsigned fmt = client.rand.next();
int32_t x = (int32_t) client.rand.next();
client.put(Str::snprintf(buf, sizeof(buf), formats[fmt % 4], x), x + 1);
}
client.wait_all();
double tp1 = client.now();
client.puts_done();
client.notice("now getting\n");
int32_t *a = (int32_t *) malloc(sizeof(int32_t) * n * 2);
assert(a);
client.rand.reset(seed);
for (unsigned i = 0; i < n * 2; ++i)
a[i] = (int32_t) client.rand.next();
for (unsigned i = 0; i < n; ++i) {
unsigned x = client.rand.next() % n;
std::swap(a[2 * i], a[2 * x]);
std::swap(a[2 * i + 1], a[2 * x + 1]);
}
double tg0 = client.now();
unsigned g;
for (g = 0; g < n && !client.timeout(1); ++g) {
unsigned fmt = a[2 * g];
int32_t x = (int32_t) a[2 * g + 1];
client.get_check(Str::snprintf(buf, sizeof(buf), formats[fmt % 4], x), x + 1);
}
client.wait_all();
double tg1 = client.now();
Json result = Json();
kvtest_set_time(result, "puts", n, tp1 - tp0);
kvtest_set_time(result, "gets", g, tg1 - tg0);
kvtest_set_time(result, "ops", n + g, (tp1 - tp0) + (tg1 - tg0));
client.report(result);
free(a);
}
template <typename C>
void kvtest_rw1long(C &client)
{
kvtest_rw1long_seed(client, kvtest_first_seed + client.id() % 48);
}
// interleave inserts and gets for random keys.
template <typename C>
void kvtest_rw2_seed(C &client, int seed, double getfrac)
{
client.rand.reset(seed);
const unsigned c = 2654435761U;
const unsigned offset = client.rand.next();
double t0 = client.now();
uint64_t puts = 0, gets = 0;
int getfrac65536 = (int) (getfrac * 65536 + 0.5);
while (!client.timeout(0) && (puts + gets) <= client.limit()) {
if (puts == 0 || (client.rand.next() % 65536) >= getfrac65536) {
// insert
unsigned x = (offset + puts) * c;
client.put(x, x + 1);
++puts;
} else {
// get
unsigned x = (offset + (client.rand.next() % puts)) * c;
client.get_check(x, x + 1);
++gets;
}
}
client.wait_all();
double t1 = client.now();
Json result = Json().set("puts", puts).set("gets", gets);
kvtest_set_time(result, "ops", puts + gets, t1 - t0);
client.report(result);
}
template <typename C>
void kvtest_rw2(C &client)
{
kvtest_rw2_seed(client, kvtest_first_seed + client.id() % 48, 0.5);
}
template <typename C>
void kvtest_rw2g90(C &client)
{
kvtest_rw2_seed(client, kvtest_first_seed + client.id() % 48, 0.9);
}
template <typename C>
void kvtest_rw2g98(C &client)
{
kvtest_rw2_seed(client, kvtest_first_seed + client.id() % 48, 0.98);
}
// interleave inserts and gets for random keys.
template <typename C>
void kvtest_rw2fixed_seed(C &client, int seed, double getfrac)
{
client.rand.reset(seed);
const unsigned c = 2654435761U;
const unsigned offset = client.rand.next();
double t0 = client.now();
uint64_t puts = 0, gets = 0;
int getfrac65536 = (int) (getfrac * 65536 + 0.5);
while (!client.timeout(0) && (puts + gets) <= client.limit()) {
if (puts == 0 || (client.rand.next() % 65536) >= getfrac65536) {
// insert
unsigned x = (offset + puts) * c;
x %= 100000000;
client.put(x, x + 1);
++puts;
} else {
// get
unsigned x = (offset + (client.rand.next() % puts)) * c;
x %= 100000000;
client.get_check(x, x + 1);
++gets;
}
}
client.wait_all();
double t1 = client.now();
Json result = Json().set("puts", puts).set("gets", gets);
kvtest_set_time(result, "ops", puts + gets, t1 - t0);
client.report(result);
}
template <typename C>
void kvtest_rw2fixed(C &client)
{
kvtest_rw2fixed_seed(client, kvtest_first_seed + client.id() % 48, 0.5);
}
template <typename C>
void kvtest_rw2fixedg90(C &client)
{
kvtest_rw2fixed_seed(client, kvtest_first_seed + client.id() % 48, 0.9);
}
template <typename C>
void kvtest_rw2fixedg98(C &client)
{
kvtest_rw2fixed_seed(client, kvtest_first_seed + client.id() % 48, 0.98);
}
// do a bunch of inserts to sequentially increasing keys,
// then check that they all showed up.
// different clients might use same key sometimes.
template <typename C>
void kvtest_rw3(C &client)
{
double t0 = client.now();
uint64_t n;
for (n = 0; !client.timeout(0) && n <= client.limit(); ++n)
client.put_key8(n, n + 1);
client.wait_all();
client.puts_done();
client.notice("now getting\n");
double t1 = client.now();
for (unsigned i = 0; i < n; ++i)
client.get_check_key8(i, i + 1);
client.wait_all();
double t2 = client.now();
Json result = Json();
kvtest_set_time(result, "puts", n, t1 - t0);
kvtest_set_time(result, "gets", n, t2 - t1);
kvtest_set_time(result, "ops", n + n, t2 - t0);
client.report(result);
}
// do a bunch of inserts to sequentially decreasing keys,
// then check that they all showed up.
// different clients might use same key sometimes.
template <typename C>
void kvtest_rw4(C &client)
{
const int top = 2147483647;
double t0 = client.now();
unsigned n;
for (n = 0; !client.timeout(0) && n <= client.limit(); ++n)
client.put_key8(top - n, n + 1);
client.wait_all();
client.puts_done();
client.notice("now getting\n");
double t1 = client.now();
for (unsigned i = 0; i < n; ++i)
client.get_check_key8(top - i, i + 1);
client.wait_all();
double t2 = client.now();
Json result = Json();
kvtest_set_time(result, "puts", n, t1 - t0);
kvtest_set_time(result, "gets", n, t2 - t1);
kvtest_set_time(result, "ops", n + n, t2 - t0);
client.report(result);
}
// do a bunch of inserts to sequentially decreasing 8B keys,
// then check that they all showed up.
// different clients might use same key sometimes.
template <typename C>
void kvtest_rw4fixed(C &client)
{
const int top = 99999999;
double t0 = client.now();
unsigned n;
for (n = 0; !client.timeout(0) && n <= client.limit(); ++n)
client.put_key8(top - n, n + 1);
client.wait_all();
client.puts_done();
client.notice("now getting\n");
double t1 = client.now();
for (unsigned i = 0; i < n; ++i)
client.get_check_key8(top - i, i + 1);
client.wait_all();
double t2 = client.now();
Json result = Json();
kvtest_set_time(result, "puts", n, t1 - t0);
kvtest_set_time(result, "gets", n, t2 - t1);
kvtest_set_time(result, "ops", n + n, t2 - t0);
client.report(result);
}
// update the same small set of keys over and over,
// to uncover concurrent update bugs in the server.
template <typename C>
void kvtest_same_seed(C &client, int seed)
{
client.rand.reset(seed);
double t0 = client.now();
unsigned n;
for (n = 0; !client.timeout(0) && n <= client.limit(); ++n) {
unsigned x = client.rand.next() % 10;
client.put(x, x + 1);
}
client.wait_all();
double t1 = client.now();
Json result = Json();
kvtest_set_time(result, "puts", n, t1 - t0);
client.report(result);
}
template <typename C>
void kvtest_same(C &client)
{
kvtest_same_seed(client, kvtest_first_seed + client.id() % 48);
}
// update the same small set of keys over and over, with interspersed gets.
template <typename C>
void kvtest_rwsmall_seed(C &client, int nkeys, int seed)
{
client.rand.reset(seed);
double t0 = client.now();
unsigned n;
for (n = 0; !client.timeout(0) && n <= client.limit(); ++n) {
unsigned x = client.rand.next() % (8 * nkeys);
if (x & 7)
client.get(x >> 3);
else
client.put(x >> 3, n);
}
client.wait_all();
double t1 = client.now();
Json result = Json();
kvtest_set_time(result, "ops", n, t1 - t0);
client.report(result);
}
template <typename C>
void kvtest_rwsmall24(C &client)
{
kvtest_rwsmall_seed(client, 24, kvtest_first_seed + client.id() % 48);
}
// update the same small set of keys over and over, with interspersed gets.
// but ensure that the keys are all on different cache lines.
template <typename C>
void kvtest_rwsep_seed(C &client, int nkeys, int clientid, int seed)
{
for (int n = clientid * (32 + nkeys); n < (clientid + 1) * (32 + nkeys); ++n)
client.put(1000000 + n, n);
client.rand.reset(seed);
double t0 = client.now();
unsigned n;
for (n = 0; !client.timeout(0) && n <= client.limit(); ++n) {
unsigned x = client.rand.next() % (8 * nkeys);
if (x & 7)
client.get(1000000 + clientid * (32 + nkeys) + (x >> 3));
else
client.put(1000000 + clientid * (32 + nkeys) + (x >> 3), n);
}
client.wait_all();
double t1 = client.now();
Json result = Json();
kvtest_set_time(result, "ops", n, t1 - t0);
client.report(result);
}
template <typename C>
void kvtest_rwsep24(C &client)
{
kvtest_rwsep_seed(client, 24, client.id(), kvtest_first_seed + client.id() % 48);
}
// Same as rw1, except that the keys are no more than 8 bytes
template <typename C>
void kvtest_rw1fixed_seed(C &client, int seed)
{
client.rand.reset(seed);
double tp0 = client.now();
unsigned n;
for (n = 0; !client.timeout(0) && n <= client.limit(); ++n) {
int32_t x = (int32_t) client.rand.next();
x %= 100000000;
client.put(x, x + 1);
}
client.wait_all();
double tp1 = client.now();
client.puts_done();
client.notice("now getting\n");
int32_t *a = (int32_t *) malloc(sizeof(int32_t) * n);
assert(a);
client.rand.reset(seed);
for (unsigned i = 0; i < n; ++i) {
a[i] = (int32_t) client.rand.next();
a[i] %= 100000000;
}
for (unsigned i = 0; i < n; ++i)
std::swap(a[i], a[client.rand.next() % n]);
double tg0 = client.now();
unsigned g;
#if 0
#define BATCH 8
for(g = 0; g+BATCH < n && !client.timeout(1); g += BATCH){
long key[BATCH], expected[BATCH];
for(int i = 0; i < BATCH; i++){
key[i] = a[g+i];
expected[i] = a[g+i] + 1;
}
client.many_get_check(BATCH, key, expected);
}
#else
for (g = 0; g < n && !client.timeout(1); ++g)
client.get_check(a[g], a[g] + 1);
#endif
client.wait_all();
double tg1 = client.now();
Json result = Json();
kvtest_set_time(result, "puts", n, tp1 - tp0);
kvtest_set_time(result, "gets", g, tg1 - tg0);
kvtest_set_time(result, "ops", n + g, (tp1 - tp0) + (tg1 - tg0));
client.report(result);
free(a);
}
template <typename C>
void kvtest_rw1fixed(C &client)
{
kvtest_rw1fixed_seed(client, kvtest_first_seed + client.id() % 48);
}
// Same as rw1, except that keys are 16-bytes (prefixed with "0"s)
template <typename C>
void kvtest_rw16_seed(C &client, int seed)
{
client.rand.reset(seed);
double tp0 = client.now();
int n;
char key[256];
char val[256];
for (n = 0; !client.timeout(0); ++n) {
int32_t x = (int32_t) client.rand.next();
sprintf(key, "%016d", x);
sprintf(val, "%016d", x + 1);
client.put(key, val);
}
client.wait_all();
double tp1 = client.now();
client.puts_done();
client.notice("now getting\n");
int32_t *a = (int32_t *) malloc(sizeof(int32_t) * n);
assert(a);
client.rand.reset(seed);
for (int i = 0; i < n; ++i)
a[i] = (int32_t) client.rand.next();
for (int i = 0; i < n; ++i)
std::swap(a[i], a[client.rand.next() % n]);
double tg0 = client.now();
int g;
for (g = 0; g < n && !client.timeout(1); ++g) {
sprintf(key, "%016d", a[g]);
sprintf(val, "%016d", a[g] + 1);
client.get_check(key, val);
}
client.wait_all();
double tg1 = client.now();
Json result = Json();
kvtest_set_time(result, "puts", n, tp1 - tp0);
kvtest_set_time(result, "gets", g, tg1 - tg0);
kvtest_set_time(result, "ops", n + g, (tp1 - tp0) + (tg1 - tg0));
client.report(result);
free(a);
}
template <typename C>
void kvtest_rw16(C &client)
{
kvtest_rw16_seed(client, kvtest_first_seed + client.id() % 48);
}
//global size for sanity checking tree size
std::atomic<size_t> global_size;
// generate a big tree, update the tree to current epoch as much as possible
//write/delete: write to tree, meanwhile try to get keys, if found remove
template <typename C>
void kvtest_recovery(C &client){
GH::init_thread_all(client.id());
ycsbc::OpRatios opratios(GH::get_rate, GH::put_rate, GH::rem_rate, GH::scan_rate);
unsigned pos = 0, val =0;
uint64_t n = 0;
size_t local_size = 0;
void *root_ptr = nullptr;
//begin initops epoch 1--------------------------------------------------
if(client.id() == 0){
DBGLOG("-----ninitops ge: %lu", globalepoch)
while (n < GH::n_initops) {
++n;
pos = rand() % GH::n_keys;
local_size +=
client.put(pos, pos + 1);
}
}
//end initops epoch 1-----------------------------------------------------
GH::advance_epoch(client.id(), client.get_root());
//begin nops1 epoch 2----------------------------------------------------
if(client.id() == 0){
DBGLOG("-----nops1 ge: %lu", globalepoch)
}
n = 0;
while(n<GH::n_ops1){
n++;
pos = client.rand.next() % GH::n_keys;
val = client.rand.next();
int op = opratios.get_next_op();
switch(op){
case 0:
client.get_sync(pos);
break;
case 1:
local_size +=
client.put(pos, val);
break;
case 2:
local_size -=
client.remove_sync(pos);
break;
default:
assert(0);
break;
}
}
//nops 1 end epoch 2----------------------------------------------------
global_size += local_size;
GH::advance_epoch(client.id(), client.get_root());
//begin copy epoch 3---------------------------------------------
if(client.id() == 0){
DBGLOG("-----copy ge: %lu", globalepoch)
}
void *copy = nullptr;
if(client.id() == 0){
assert(global_size == get_tree_size(client.get_root()));
copy = copy_tree(client.get_root());
assert(is_same_tree(client.get_root(), copy));
root_ptr = client.get_root();
DBGLOG("root addr %p ge: %lu", root_ptr, globalepoch);
}
GH::thread_barrier.wait_barrier(client.id());
//end copy epoch 3----------------------------------------------------
//begin nops2 epoch 3----------------------------------------------------
if(client.id() == 0){
DBGLOG("-----nops2 ge: %lu", globalepoch)
}
n = 0;
while(n<GH::n_ops2){
n++;
pos = client.rand.next() % GH::n_keys;
val = client.rand.next();
unsigned op = client.rand.next()%4;
switch(op){
case 0:
case 1:
client.get_sync(pos);
break;
case 2:
local_size -= client.remove_sync(pos);
break;
case 3:
local_size += client.put(pos, val);
break;
}
}
//end nops2 epoch 3----------------------------------------------------
//begin recovery epoch 3-----------------------------------------------
GH::thread_barrier.wait_barrier(client.id());
if(client.id() == 0){
DBGLOG("-----recovery ge: %lu", globalepoch)
failedepoch = 3;
}
//Begin Undo epoch 3 ------------------------------------------------
if(client.id() == 0){
#ifdef EXTLOG
void* undo_root = GH::node_logger->get_tree_root();
client.set_root(undo_root);
#endif //extlog
}
GH::thread_barrier.wait_barrier(client.id());
#ifdef EXTLOG
auto last_flush = GH::node_logger->get_last_flush();
GH::node_logger->undo(client.get_root());
GH::thread_barrier.wait_barrier(client.id());
GH::node_logger->undo_next_prev(client.get_root(), last_flush);
GH::thread_barrier.wait_barrier(client.id());
#endif//extlog
//End Undo epoch 3 ------------------------------------------------
if(client.id() == 0){
//ensure same root
DBGLOG("root addr %p ge: %lu", (void*)client.get_root(), globalepoch);
assert(root_ptr == client.get_root());
//ensure same tree
bool is_same = is_same_tree(client.get_root(), copy, true);
printf("%s\n", is_same ? "is same":"not same - recovery failed");
}
GH::thread_barrier.wait_barrier(client.id());
//end recovery epoch 3-----------------------------------------------
}
// generate a big tree, update the tree to current epoch as much as possible
//write/delete: write to tree, meanwhile try to get keys, if found remove
template <typename C>
void kvtest_rand(C &client, uint64_t n_keys){
GH::init_thread_all(client.id());
unsigned pos = 0, val =0;
uint64_t n = 0;
Json result = Json();
size_t local_size = 0;
if(client.id() == 0){
while (n < n_keys/2) {
++n;
pos = rand() % n_keys;
local_size +=
client.put(pos, pos + 1);
}
printf("Created tree\n");
}
//Barrier-------------------------------------------------------------
GH::thread_barrier.wait_barrier(client.id());
n = 0;
double t0 = client.now();
while(!client.timeout(0)){
n++;
pos = client.rand.next() % n_keys;
val = client.rand.next();
unsigned op = client.rand.next()%4;
switch(op){
case 0:
case 1:
client.get_sync(pos);
break;
case 2:
local_size -=
client.remove_sync(pos);
break;
case 3:
local_size +=
client.put(pos, val);
}
if ((n % (1 << 6)) == 0){
client.rcu_quiesce();
//set_global_epoch
}
#ifdef GLOBAL_FLUSH
GH::global_flush.ack_flush();
#endif
}
double t1 = client.now();
//result.set("time", t1-t0);
result.set("ops", (long)(n/(t1-t0)));
#ifdef GLOBAL_FLUSH
GH::global_flush.thread_done();
while(!GH::global_flush.ack_flush());
#endif
client.report(result);
global_size += local_size;
//Barrier-------------------------------------------------------------
GH::thread_barrier.wait_barrier(client.id());
//check size
if(client.id() == 0){
assert(global_size == get_tree_size(client.get_root()));
}
}
#ifdef YCSB
template <typename C, typename RandGen>
void kvtest_ycsb(C &client,
ycsbc::OpRatios op_ratios,
RandGen key_rand){
double t_beg = client.now();
uint64_t pos = 0, val = 0;
size_t init = GH::n_initops;
size_t nops1 = GH::n_ops1;
size_t nkeys = GH::n_keys;
int get_ops = 0;
int put_ops = 0;
int rem_ops = 0;
int scan_ops = 0;
GH::init_thread_all(client.id());
UniGen val_rand;
ycsbc::exp_init_all(key_rand, val_rand, op_ratios.op_rand, GH::n_keys);
quick_istr key;
std::vector<Str> keys(10), values(10);
uint64_t n = 0;
Json result = Json();
size_t local_size = 0;
if(client.id() == 0){
while (n < init) {
pos = n;
val = pos + 1;
local_size += client.put(pos, val);
++n;
}
#ifdef PALLOCATOR
size_t mem_usage = pallocator.get_mem_usage();
printf("Created tree of size %lu----------------\n", mem_usage/1000000);
#endif //pallocator
}
//Barrier-------------------------------------------------------------
GH::thread_barrier.wait_barrier(client.id());
client.rcu_quiesce();
#ifdef GLOBAL_FLUSH
GH::global_flush.ack_flush();
#endif //gf
n = 0;
#ifdef PERF_WORKLOAD
//begin perf measurements
setup_counters();
start_counters();
#endif //perf workload begin
#ifndef SKIP_CRITICAL_SECTION
double t0 = client.now();
while(n < nops1){
n++;
pos = key_rand.next() % nkeys;
unsigned op = op_ratios.get_next_op();
switch(op){
case ycsbc::get_op:{
client.get_sync(pos);
get_ops++;
}break;
case ycsbc::put_op:{
val = val_rand.next();
local_size += client.put(pos, val);
put_ops++;
}break;
case ycsbc::rem_op:{
local_size -= client.remove_sync(pos);
rem_ops++;
}break;
case ycsbc::scan_op:{
key.set(pos, 8);
client.scan_sync(key.string(), 10, keys, values);
scan_ops++;
}break;
default:
assert(0);
break;
}
if ((n % (1 << 6)) == 0){
client.rcu_quiesce();
//set_global_epoch
}
#ifdef GLOBAL_FLUSH
GH::global_flush.ack_flush();
#endif //gf
}
double t1 = client.now();
#else
double t0 = 0, t1 = 0;
#endif//skip cs
#ifdef PERF_WORKLOAD
stop_counters();
read_counters(result);
#endif
result.set("workload_time", t1-t0);
result.set("num_operations", n);
result.set("ops", (long)(n/(t1-t0)));
result.set("get_ops", (long)(get_ops/(t1-t0)));
result.set("put_ops", (long)(put_ops/(t1-t0)));
result.set("rem_ops", (long)(rem_ops/(t1-t0)));
result.set("scan_ops", (long)(scan_ops/(t1-t0)));
#ifdef GLOBAL_FLUSH
GH::global_flush.thread_done();
while(!GH::global_flush.ack_flush());
#endif
global_size += local_size;
//Barrier-------------------------------------------------------------
GH::thread_barrier.wait_barrier(client.id());
//check size
if(client.id() == 0){
assert(global_size == get_tree_size(client.get_root()));
}