diff --git a/src/leveled_bookie.erl b/src/leveled_bookie.erl index e3c77ab..363912a 100644 --- a/src/leveled_bookie.erl +++ b/src/leveled_bookie.erl @@ -906,12 +906,20 @@ book_headfold(Pid, Tag, {range, Bucket, KeyRange}, FoldAccT, JournalCheck, SnapP book_returnfolder(Pid, RunnerType). %% @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 version 1 objects will be included in the result set regardless of Last %% Modified Date. -%% The Max Head Count will stop the fold once the count has been reached on -%% this store only +%% The Max Object Count will stop the fold once the count has been reached on +%% 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, SegmentList, LastModRange, MaxObjectCount) -> {async, Runner} when diff --git a/src/leveled_penciller.erl b/src/leveled_penciller.erl index 64b89d8..21c822c 100644 --- a/src/leveled_penciller.erl +++ b/src/leveled_penciller.erl @@ -1405,14 +1405,21 @@ keyfolder(IMMiter, SSTiter, StartKey, EndKey, {AccFun, Acc}) -> keyfolder(_Iterators, _KeyRange, {_AccFun, Acc}, {_SegmentList, _LastModRange, MaxKeys}) when MaxKeys == 0 -> - Acc; + {max_count, Acc}; keyfolder({[], SSTiter}, KeyRange, {AccFun, Acc}, {SegmentList, LastModRange, MaxKeys}) -> {StartKey, EndKey} = KeyRange, case find_nextkey(SSTiter, StartKey, EndKey, SegmentList, element(1, LastModRange)) of 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}} -> {Acc1, MK1} = maybe_accumulate(SSTKey, SSTVal, Acc, AccFun, diff --git a/src/leveled_runner.erl b/src/leveled_runner.erl index e3b5445..ffaf509 100644 --- a/src/leveled_runner.erl +++ b/src/leveled_runner.erl @@ -461,10 +461,10 @@ get_nextbucket(NextBucket, NextKey, Tag, LedgerSnapshot, BKList, {C, L}) -> ExtractFun, null), case R of - null -> + {no_more_keys, null} -> leveled_log:log("B0008",[]), BKList; - {{B, K}, V} -> + {_, {{B, K}, V}} -> case leveled_codec:is_active({Tag, B, K, null}, V, Now) of true -> leveled_log:log("B0009",[B]),