-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbasic_SUITE.erl
369 lines (310 loc) · 14.8 KB
/
basic_SUITE.erl
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
-module(basic_SUITE).
-include_lib("common_test/include/ct.hrl").
-export([all/0, init_per_suite/1, end_per_suite/1]).
-export([dual_store_compare_medium_so/1,
dual_store_compare_medium_ko/1,
dual_store_compare_large_so/1,
dual_store_compare_large_ko/1,
store_notsupported/1]).
all() -> [dual_store_compare_medium_so,
dual_store_compare_medium_ko,
dual_store_compare_large_so,
dual_store_compare_large_ko,
store_notsupported
].
init_per_suite(Config) ->
testutil:init_per_suite([{suite, "basic"}|Config]),
Config.
end_per_suite(Config) ->
testutil:end_per_suite(Config).
store_notsupported(_Config) ->
RootPath = testutil:reset_filestructure(),
VnodePath1 = filename:join(RootPath, "vnode1/"),
SplitF = fun(_X) -> {rand:uniform(1000), 1, 0, null} end,
RPid = self(),
ReturnFun = fun(R) -> RPid ! {result, R} end,
RepairFun = fun(_KL) -> null end,
{ok, Cntrl1} =
aae_controller:aae_start({parallel, leveled_ko},
true,
{1, 300},
[{2, 0}, {2, 1}],
VnodePath1,
SplitF,
[info, warn, error, critical]),
BKVList = testutil:gen_keys([], 100),
ok = testutil:put_keys(Cntrl1, 2, BKVList, none),
{ok, _P1, GUID1} =
aae_exchange:start([{exchange_sendfun(Cntrl1), [{2,0}]}],
[{exchange_notsupported_sendfun(), [{3, 0}]}],
RepairFun,
ReturnFun),
io:format("Exchange id ~s~n", [GUID1]),
{ExchangeState1, 0} = testutil:start_receiver(),
io:format("ExchangeState ~w~n", [ExchangeState1]),
true = ExchangeState1 == not_supported,
aae_controller:aae_close(Cntrl1),
RootPath = testutil:reset_filestructure().
dual_store_compare_medium_so(_Config) ->
dual_store_compare_tester(10000, leveled_so).
dual_store_compare_medium_ko(_Config) ->
dual_store_compare_tester(10000, leveled_ko).
dual_store_compare_large_so(_Config) ->
dual_store_compare_tester(100000, leveled_so).
dual_store_compare_large_ko(_Config) ->
dual_store_compare_tester(100000, leveled_ko).
dual_store_compare_tester(InitialKeyCount, StoreType) ->
% Setup to AAE controllers, each representing the same data. One store
% will be split into two three preflists, the other into two. The
% preflists will be mapped as follows:
% {2, 0} <-> {3, 0}
% {2, 1} <-> {3, 1} & {3, 2}
%
% Think of these preflists in terms of needless partitions for test
% purposes. Although this is a comparison between 2 'nodes', it is
% more like a comparison between 2 clusters where n=1, there is 1
% vnode, but data is still partitioned into either 2 or 3 partitions.
% Don't try and make sense of this in term of a ring - the
% mock_vnode_coverage_fold tests have a more Riak ring-like setup.
RootPath = testutil:reset_filestructure(),
VnodePath1 = filename:join(RootPath, "vnode1/"),
VnodePath2 = filename:join(RootPath, "vnode2/"),
SplitF = fun(_X) -> {rand:uniform(1000), 1, 0, null} end,
RPid = self(),
ReturnFun = fun(R) -> RPid ! {result, R} end,
RepairFun = fun(_KL) -> null end,
{ok, Cntrl1} =
aae_controller:aae_start({parallel, StoreType},
true,
{1, 300},
[{2, 0}, {2, 1}],
VnodePath1,
SplitF,
[warn, error, critical]),
{ok, Cntrl2} =
aae_controller:aae_start({parallel, StoreType},
true,
{1, 300},
[{3, 0}, {3, 1}, {3, 2}],
VnodePath2,
SplitF,
[warn, error, critical]),
initial_load(InitialKeyCount, Cntrl1, Cntrl2),
SW1 = os:timestamp(),
ok = aae_controller:aae_mergeroot(Cntrl1,
[{2, 0}, {2, 1}],
ReturnFun),
Root1A = testutil:start_receiver(),
ok = aae_controller:aae_mergeroot(Cntrl2,
[{3, 0}, {3, 1}, {3, 2}],
ReturnFun),
Root2A = testutil:start_receiver(),
true = Root1A == Root2A,
ok = aae_controller:aae_fetchroot(Cntrl1,
[{2, 0}],
ReturnFun),
[{{2, 0}, Root1B}] = testutil:start_receiver(),
ok = aae_controller:aae_fetchroot(Cntrl2,
[{3, 0}],
ReturnFun),
[{{3, 0}, Root2B}] = testutil:start_receiver(),
true = Root1B == Root2B,
ok = aae_controller:aae_mergeroot(Cntrl1,
[{2, 1}],
ReturnFun),
Root1C = testutil:start_receiver(),
ok = aae_controller:aae_mergeroot(Cntrl2,
[{3, 1}, {3, 2}],
ReturnFun),
Root2C = testutil:start_receiver(),
true = Root1C == Root2C,
%% Turn down logging in Cntrl1 and Cntrl2
ok = aae_controller:aae_loglevel(Cntrl1, [warn, error, critical]),
ok = aae_controller:aae_loglevel(Cntrl2, [warn, error, critical]),
io:format("Direct partition compare complete in ~w ms~n",
[timer:now_diff(os:timestamp(), SW1)/1000]),
% Change log levels
ok = aae_controller:aae_loglevel(Cntrl1, [info, warn, error, critical]),
ok = aae_controller:aae_loglevel(Cntrl2, [info, warn, error, critical]),
% Now do a comparison based based on some key range queries:
SW2 = os:timestamp(),
Bucket = integer_to_binary(1),
StartKey = list_to_binary(string:right(integer_to_list(10), 6, $0)),
EndKey = list_to_binary(string:right(integer_to_list(50), 6, $0)),
Elements = [{sibcount, null}],
SCFoldFun =
fun(FB, FK, FV, {FAccKL, FAccSc}) ->
{sibcount, FSc} = lists:keyfind(sibcount, 1, FV),
true = FB == Bucket,
true = FK >= StartKey,
true = FK < EndKey,
{[FK|FAccKL], FAccSc + FSc}
end,
SCInitAcc = {[], 0},
{async, SCFolder1} =
aae_controller:aae_fold(Cntrl1,
{key_range, Bucket, StartKey, EndKey},
all,
SCFoldFun,
SCInitAcc,
Elements),
{async, SCFolder2} =
aae_controller:aae_fold(Cntrl2,
{key_range, Bucket, StartKey, EndKey},
all,
SCFoldFun,
SCInitAcc,
Elements),
SCF1 = SCFolder1(),
SCF2 = SCFolder2(),
true = SCF1 == SCF2,
true = element(2, SCF1) == 8,
true = length(element(1, SCF1)) == 8,
io:format("Comparison through key range folder in ~w ms with results ~w~n",
[timer:now_diff(os:timestamp(), SW2)/1000, SCF1]),
% Confirm no differences when using different matching AAE exchanges
SW3 = os:timestamp(),
{ok, _P1, GUID1} =
aae_exchange:start([{exchange_sendfun(Cntrl1), [{2,0}]}],
[{exchange_sendfun(Cntrl2), [{3, 0}]}],
RepairFun,
ReturnFun),
io:format("Exchange id ~s~n", [GUID1]),
{ExchangeState1, 0} = testutil:start_receiver(),
true = ExchangeState1 == root_compare,
{ok, _P2, GUID2} =
aae_exchange:start([{exchange_sendfun(Cntrl1), [{2,1}]}],
[{exchange_sendfun(Cntrl2), [{3, 1}, {3, 2}]}],
RepairFun,
ReturnFun),
io:format("Exchange id ~s~n", [GUID2]),
{ExchangeState2, 0} = testutil:start_receiver(),
true = ExchangeState2 == root_compare,
{ok, _P3, GUID3} =
aae_exchange:start([{exchange_sendfun(Cntrl1), [{2, 0}, {2,1}]}],
[{exchange_sendfun(Cntrl2),
[{3, 0}, {3, 1}, {3, 2}]}],
RepairFun,
ReturnFun),
io:format("Exchange id ~s~n", [GUID3]),
{ExchangeState3, 0} = testutil:start_receiver(),
true = ExchangeState3 == root_compare,
{ok, _P4, GUID4} =
aae_exchange:start([{exchange_sendfun(Cntrl1), [{2,0}]},
{exchange_sendfun(Cntrl1), [{2,1}]}],
[{exchange_sendfun(Cntrl2),
[{3, 0}, {3, 1}, {3, 2}]}],
RepairFun,
ReturnFun),
io:format("Exchange id ~s~n", [GUID4]),
{ExchangeState4, 0} = testutil:start_receiver(),
true = ExchangeState4 == root_compare,
BKVListN = create_discrepancy(Cntrl1, InitialKeyCount),
{ok, _P6, GUID6} =
aae_exchange:start([{exchange_sendfun(Cntrl1), [{2,0}]},
{exchange_sendfun(Cntrl1), [{2,1}]}],
[{exchange_sendfun(Cntrl2),
[{3, 0}, {3, 1}, {3, 2}]}],
RepairFun,
ReturnFun),
io:format("Exchange id ~s~n", [GUID6]),
{ExchangeState6, 10} = testutil:start_receiver(),
true = ExchangeState6 == clock_compare,
% Same again, but request a missing partition, and should get same result
{ok, _P6a, GUID6a} =
aae_exchange:start([{exchange_sendfun(Cntrl1), [{2,0}]},
{exchange_sendfun(Cntrl1), [{2,1}]}],
[{exchange_sendfun(Cntrl2),
[{3, 0}, {3, 1}, {3, 2}, {3, 3}]}],
RepairFun,
ReturnFun),
io:format("Exchange id ~s~n", [GUID6a]),
{ExchangeState6a, 10} = testutil:start_receiver(),
true = ExchangeState6a == clock_compare,
{ok, _P6b, GUID6b} =
aae_exchange:start(full,
[{exchange_sendfun(Cntrl1), [{2,0}]},
{exchange_sendfun(Cntrl1), [{2,1}]}],
[{exchange_sendfun(Cntrl2),
[{3, 0}, {3, 1}, {3, 2}, {3, 3}]}],
RepairFun,
ReturnFun,
none,
[{scan_timeout, 0}, {max_results, 256}]),
io:format("Exchange id ~s~n", [GUID6b]),
{timeout, 0} = testutil:start_receiver(),
% Nothing repaired last time. The deltas are all new keys though, so
% We can repair by adding them in to the other vnode
RepairFun0 = testutil:repair_fun(BKVListN, Cntrl2, 3),
{ok, _P7, GUID7} =
aae_exchange:start([{exchange_sendfun(Cntrl1), [{2,0}]},
{exchange_sendfun(Cntrl1), [{2,1}]}],
[{exchange_sendfun(Cntrl2),
[{3, 0}, {3, 1}, {3, 2}]}],
RepairFun0,
ReturnFun),
io:format("Exchange id ~s~n", [GUID7]),
{ExchangeState7, 10} = testutil:start_receiver(),
true = ExchangeState7 == clock_compare,
{ok, _P8, GUID8} =
aae_exchange:start([{exchange_sendfun(Cntrl1), [{2,0}]},
{exchange_sendfun(Cntrl1), [{2,1}]}],
[{exchange_sendfun(Cntrl2),
[{3, 0}, {3, 1}, {3, 2}]}],
RepairFun,
ReturnFun),
io:format("Exchange id ~s~n", [GUID8]),
{ExchangeState8, 0} = testutil:start_receiver(),
true = ExchangeState8 == root_compare,
io:format("Comparison through exchange complete in ~w ms~n",
[timer:now_diff(os:timestamp(), SW3)/1000]),
% Shutdown and tidy up
ok = aae_controller:aae_close(Cntrl1),
ok = aae_controller:aae_close(Cntrl2),
RootPath = testutil:reset_filestructure().
initial_load(InitialKeyCount, Cntrl1, Cntrl2) ->
SW0 = os:timestamp(),
BKVListXS = testutil:gen_keys([], InitialKeyCount),
{BKVList, _Discard} = lists:split(20, BKVListXS),
% The first 20 keys discarded to create an overlap between the add
% replace list
ok = testutil:put_keys(Cntrl1, 2, BKVList, none),
ok = testutil:put_keys(Cntrl2, 3, lists:reverse(BKVList), none),
{BKVListRem, _Ignore} = lists:split(10, BKVList),
ok = testutil:remove_keys(Cntrl1, 2, BKVListRem),
ok = testutil:remove_keys(Cntrl2, 3, BKVListRem),
% Change all of the keys - cheat by using undefined rather than replace
% properly
BKVListR = testutil:gen_keys([], 100),
% As 100 > 20 expect 20 of these keys to be new, so no clock will be
% returned from fetch_clock, and 80 of these will be updates
ok = testutil:put_keys(Cntrl1, 2, BKVListR, undefined),
ok = testutil:put_keys(Cntrl2, 3, BKVListR, undefined),
io:format("Initial put complete in ~w ms~n",
[timer:now_diff(os:timestamp(), SW0)/1000]).
create_discrepancy(Cntrl, InitialKeyCount) ->
% Create a discrepancy and discover it through exchange
BKVListN = testutil:gen_keys([], InitialKeyCount + 10, InitialKeyCount),
_SL = lists:foldl(fun({B, K, _V}, Acc) ->
BK = aae_util:make_binarykey(B, K),
Seg = leveled_tictac:keyto_segment48(BK),
Seg0 = aae_keystore:generate_treesegment(Seg),
io:format("Generate new key B ~w K ~w " ++
"for Segment ~w ~w ~w partition ~w ~w~n",
[B, K, Seg0, Seg0 bsr 8, Seg0 band 255,
testutil:calc_preflist(K, 2),
testutil:calc_preflist(K, 3)]),
[Seg0|Acc]
end,
[],
BKVListN),
ok = testutil:put_keys(Cntrl, 2, BKVListN),
BKVListN.
exchange_sendfun(Cntrl) -> testutil:exchange_sendfun(Cntrl).
exchange_notsupported_sendfun() ->
SendFun =
fun(_Msg, _Preflists, Colour) ->
RPid = self(),
aae_exchange:reply(RPid, not_supported, Colour)
end,
SendFun.