Finding keys

Progresses from a segment list to scanning for the keys in that segment
This commit is contained in:
martinsumner 2017-06-19 18:38:55 +01:00
parent 8203487a11
commit d5b4cb844f
2 changed files with 33 additions and 5 deletions

View file

@ -61,7 +61,8 @@
find_dirtysegments/2, find_dirtysegments/2,
fetch_root/1, fetch_root/1,
fetch_leaves/2, fetch_leaves/2,
merge_trees/2 merge_trees/2,
get_segment/1
]). ]).
@ -200,6 +201,10 @@ merge_trees(TreeA, TreeB) ->
MergedTree#tictactree{level1 = NewLevel1, level2 = NewLevel2}. MergedTree#tictactree{level1 = NewLevel1, level2 = NewLevel2}.
get_segment(Key) ->
erlang:phash2(Key) band (?SEGMENT_COUNT - 1).
%%%============================================================================ %%%============================================================================
%%% Internal functions %%% Internal functions
%%%============================================================================ %%%============================================================================
@ -219,9 +224,6 @@ segmentcompare(SrcBin, SnkBin, Acc, Counter) ->
segmentcompare(SrcTail, SnkTail, [Counter|Acc], Counter + 1) segmentcompare(SrcTail, SnkTail, [Counter|Acc], Counter + 1)
end. end.
get_segment(Key) ->
erlang:phash2(Key) band (?SEGMENT_COUNT - 1).
merge_binaries(BinA, BinB) -> merge_binaries(BinA, BinB) ->
BitSize = bit_size(BinA), BitSize = bit_size(BinA),
BitSize = bit_size(BinB), BitSize = bit_size(BinB),

View file

@ -92,7 +92,33 @@ many_put_compare(_Config) ->
true = length(SegList0) == 1, true = length(SegList0) == 1,
% only the test object should be different % only the test object should be different
true = length(AltList) > 100000, true = length(AltList) > 100000,
% check there are a significant number fo differences from empty % check there are a significant number of differences from empty
FoldKeysFun =
fun(SegListToFind) ->
fun(_B, K, Acc) ->
Seg = leveled_tictac:get_segment(K),
case lists:member(Seg, SegListToFind) of
true ->
[K|Acc];
false ->
Acc
end
end
end,
SegQuery = {keylist, o_rkv, "Bucket", {FoldKeysFun(SegList0), []}},
{async, SegKeyFinder} =
leveled_bookie:book_returnfolder(Bookie2, SegQuery),
SWSKL0 = os:timestamp(),
SegKeyList = SegKeyFinder(),
io:format("Finding ~w keys in ~w dirty segments in ~w~n",
[length(SegKeyList),
length(SegList0),
timer:now_diff(os:timestamp(), SWSKL0)]),
true = length(SegKeyList) >= 1,
true = length(SegKeyList) < 10,
true = lists:member("Key1.1.4567.4321", SegKeyList),
% Now remove the object which represents the difference between these % Now remove the object which represents the difference between these
% stores and confirm that the tictac trees will now match % stores and confirm that the tictac trees will now match