Allow for setting max_keys to wrap Acc

Acc in response is now of form {Reason, Acc} not just Acc so that the application can understand the reason for the results ending - and take appropriate action (e.g. restart again from the LastKey to return more results).
This commit is contained in:
Martin Sumner 2018-10-31 14:22:28 +00:00
parent 142e3a17bb
commit aaccd09a98
3 changed files with 22 additions and 7 deletions

View file

@ -906,12 +906,20 @@ book_headfold(Pid, Tag, {range, Bucket, KeyRange}, FoldAccT, JournalCheck, SnapP
book_returnfolder(Pid, RunnerType). book_returnfolder(Pid, RunnerType).
%% @doc as book_headfold/7, but with the addition of a Last Modified Date %% @doc as book_headfold/7, but with the addition of a Last Modified Date
%% Range and Max Head Count. For version 2 objects this will filter out %% Range and Max Object Count. For version 2 objects this will filter out
%% all objects with a highest Last Modified Date that is outside of the range. %% all objects with a highest Last Modified Date that is outside of the range.
%% All version 1 objects will be included in the result set regardless of Last %% All version 1 objects will be included in the result set regardless of Last
%% Modified Date. %% Modified Date.
%% The Max Head Count will stop the fold once the count has been reached on %% The Max Object Count will stop the fold once the count has been reached on
%% this store only %% this store only. The Max Object Count if provided will mean that on
%% completion of the fold the accumulator will be wrapped in a tuple to
%% indicate the reason for completion:
%% - {no_more_keys, Acc} if the end of the range was reached wihtout hitting
%% the Max Object Count limit
%% - {max_count, Acc} if the Max Object Count limit was reached before
%% reaching the end of the range
%% If MaxObjectCount is false then the Acc will be returned not wrapped in a
%% tuple
-spec book_headfold(pid(), Tag, Limiter, FoldAccT, JournalCheck, SnapPreFold, -spec book_headfold(pid(), Tag, Limiter, FoldAccT, JournalCheck, SnapPreFold,
SegmentList, LastModRange, MaxObjectCount) -> SegmentList, LastModRange, MaxObjectCount) ->
{async, Runner} when {async, Runner} when

View file

@ -1405,14 +1405,21 @@ keyfolder(IMMiter, SSTiter, StartKey, EndKey, {AccFun, Acc}) ->
keyfolder(_Iterators, _KeyRange, {_AccFun, Acc}, keyfolder(_Iterators, _KeyRange, {_AccFun, Acc},
{_SegmentList, _LastModRange, MaxKeys}) when MaxKeys == 0 -> {_SegmentList, _LastModRange, MaxKeys}) when MaxKeys == 0 ->
Acc; {max_count, Acc};
keyfolder({[], SSTiter}, KeyRange, {AccFun, Acc}, keyfolder({[], SSTiter}, KeyRange, {AccFun, Acc},
{SegmentList, LastModRange, MaxKeys}) -> {SegmentList, LastModRange, MaxKeys}) ->
{StartKey, EndKey} = KeyRange, {StartKey, EndKey} = KeyRange,
case find_nextkey(SSTiter, StartKey, EndKey, case find_nextkey(SSTiter, StartKey, EndKey,
SegmentList, element(1, LastModRange)) of SegmentList, element(1, LastModRange)) of
no_more_keys -> no_more_keys ->
Acc; case MaxKeys > 0 of
true ->
% Need to single this query ended not because the
% MaxKeys was reached
{no_more_keys, Acc};
false ->
Acc
end;
{NxSSTiter, {SSTKey, SSTVal}} -> {NxSSTiter, {SSTKey, SSTVal}} ->
{Acc1, MK1} = {Acc1, MK1} =
maybe_accumulate(SSTKey, SSTVal, Acc, AccFun, maybe_accumulate(SSTKey, SSTVal, Acc, AccFun,

View file

@ -461,10 +461,10 @@ get_nextbucket(NextBucket, NextKey, Tag, LedgerSnapshot, BKList, {C, L}) ->
ExtractFun, ExtractFun,
null), null),
case R of case R of
null -> {no_more_keys, null} ->
leveled_log:log("B0008",[]), leveled_log:log("B0008",[]),
BKList; BKList;
{{B, K}, V} -> {_, {{B, K}, V}} ->
case leveled_codec:is_active({Tag, B, K, null}, V, Now) of case leveled_codec:is_active({Tag, B, K, null}, V, Now) of
true -> true ->
leveled_log:log("B0009",[B]), leveled_log:log("B0009",[B]),