Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions src/leveled_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
striphead_to_v1details/1,
endkey_passed/2,
key_dominates/2,
maybe_reap_expiredkey/2,
to_objectkey/3,
to_objectkey/5,
to_querykey/3,
Expand All @@ -52,7 +51,6 @@
idx_indexspecs/5,
obj_objectspecs/3,
segment_hash/1,
to_lookup/1,
next_key/1,
return_proxy/4,
get_metadata/1,
Expand Down Expand Up @@ -248,19 +246,6 @@ headkey_to_canonicalbinary(
{?HEAD_TAG, <<BucketType/binary, Bucket/binary>>, Key, SubKey}
).

-spec to_lookup(ledger_key()) -> maybe_lookup().
%% @doc
%% Should it be possible to lookup a key in the merge tree. This is not true
%% For keys that should only be read through range queries. Direct lookup
%% keys will have presence in bloom filters and other lookup accelerators.
to_lookup(Key) when is_tuple(Key) ->
case element(1, Key) of
?IDX_TAG ->
no_lookup;
_ ->
lookup
end.

%% @doc
%% Some helper functions to get a sub_components of the key/value

Expand Down Expand Up @@ -447,27 +432,6 @@ check_captured_terms(
key_dominates(LObj, RObj) ->
strip_to_seqonly(LObj) >= strip_to_seqonly(RObj).

-spec maybe_reap_expiredkey(ledger_kv(), {boolean(), integer()}) -> boolean().
%% @doc
%% Make a reap decision based on the level in the ledger (needs to be expired
%% and in the basement). the level is a tuple of the is_basement boolean, and
%% a timestamp passed into the calling function
maybe_reap_expiredkey(KV, LevelD) ->
Status = strip_to_statusonly(KV),
maybe_reap(Status, LevelD).

maybe_reap({_, infinity}, _) ->
% key is not set to expire
false;
maybe_reap({_, TS}, {true, CurrTS}) when CurrTS > TS ->
% basement and ready to expire
true;
maybe_reap(tomb, {true, _CurrTS}) ->
% always expire in basement
true;
maybe_reap(_, _) ->
false.

-spec count_tombs(
list(ledger_kv()), non_neg_integer()
) ->
Expand Down
131 changes: 74 additions & 57 deletions src/leveled_penciller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2018,13 +2018,13 @@ find_nextkeys(
find_nextkeys(
Iter, {[], {BKL, BestKV}}, FoundKVs, _Ls, {W, _SW}, _SearchInfo
) when
length(FoundKVs) == W - 1, BestKV =/= null
W == 1, BestKV =/= null
->
% All levels scanned, and there are now W keys (W - 1 previously found plus
% the latest best key)
{maps:update_with(BKL, fun tl/1, Iter), [BestKV | FoundKVs]};
find_nextkeys(
Iter, {[], {BKL, BestKV}}, FoundKVs, Ls, BatchInfo, SearchInfo
Iter, {[], {BKL, BestKV}}, FoundKVs, Ls, {W, SW}, SearchInfo
) when
BestKV =/= null
->
Expand All @@ -2034,15 +2034,15 @@ find_nextkeys(
{Ls, ?NULL_KEY},
[BestKV | FoundKVs],
Ls,
BatchInfo,
{W - 1, SW},
SearchInfo
);
find_nextkeys(
Iter,
{[LCnt | OtherLevels] = LoopLs, {BKL, BKV} = PrevBest},
FoundKVs,
Ls,
{_W, ScanWidth} = BI,
{W, ScanWidth} = BI,
{{StartKey, EndKey}, {LowLastMod, _High}, SegChecker} = SI
) ->
case maps:get(LCnt, Iter) of
Expand All @@ -2055,40 +2055,6 @@ find_nextkeys(
BI,
SI
);
[{next, Owner, _SK} | RestOfKeys] ->
% Expansion required
Pointer = {next, Owner, StartKey, EndKey},
UpdList =
leveled_sst:sst_expandpointer(
Pointer, RestOfKeys, ScanWidth, SegChecker, LowLastMod
),
% Need to loop around at this level (LCnt) as we have not yet
% examined a real key at this level
find_nextkeys(
maps:update(LCnt, UpdList, Iter),
{LoopLs, PrevBest},
FoundKVs,
Ls,
BI,
SI
);
[{pointer, SSTPid, Slot, PSK, PEK} | RestOfKeys] ->
% Expansion required
Pointer = {pointer, SSTPid, Slot, PSK, PEK},
UpdList =
leveled_sst:sst_expandpointer(
Pointer, RestOfKeys, ScanWidth, SegChecker, LowLastMod
),
% Need to loop around at this level (LCnt) as we have not yet
% examined a real key at this level
find_nextkeys(
maps:update(LCnt, UpdList, Iter),
{LoopLs, PrevBest},
FoundKVs,
Ls,
BI,
SI
);
[{Key, Val} | _RestOfKeys] when BKV == null ->
find_nextkeys(
Iter,
Expand All @@ -2098,24 +2064,53 @@ find_nextkeys(
BI,
SI
);
[{Key, Val} | _RestOfKeys] when Key < element(1, BKV) ->
find_nextkeys(
Iter,
{OtherLevels, {LCnt, {Key, Val}}},
FoundKVs,
Ls,
BI,
SI
);
[{Key, _Val} | _RestOfKeys] when Key > element(1, BKV) ->
find_nextkeys(
Iter,
{OtherLevels, PrevBest},
FoundKVs,
Ls,
BI,
SI
);
[{Key, Val} | RestOfKeys] when Key < element(1, BKV) ->
case OtherLevels of
[] when W > 1 ->
%% This is the last level to be checked, and it contains
%% the best key. Only needed to compare this level and
%% with the next-best key in the next loop
find_nextkeys(
maps:update(LCnt, RestOfKeys, Iter),
{[LCnt], {BKL, BKV}},
[{Key, Val} | FoundKVs],
Ls,
{W - 1, ScanWidth},
SI
);
_ ->
find_nextkeys(
Iter,
{OtherLevels, {LCnt, {Key, Val}}},
FoundKVs,
Ls,
BI,
SI
)
end;
[{Key, Val} | _RestOfKeys] when BKV =/= null, Key > element(1, BKV) ->
case OtherLevels of
[] when W > 1 ->
%% No other levels to try so next best is the Key, make
%% this level's key the next best and try all other levels
find_nextkeys(
maps:update_with(BKL, fun tl/1, Iter),
{lists:subtract(Ls, [LCnt]), {LCnt, {Key, Val}}},
[BKV | FoundKVs],
Ls,
{W - 1, ScanWidth},
SI
);
_ ->
find_nextkeys(
Iter,
{OtherLevels, PrevBest},
FoundKVs,
Ls,
BI,
SI
)
end;
[{Key, Val} | _RestOfKeys] when BKV =/= null ->
case leveled_codec:key_dominates({Key, Val}, BKV) of
true ->
Expand All @@ -2136,7 +2131,29 @@ find_nextkeys(
BI,
SI
)
end
end;
[Pointer0 | RestOfKeys] ->
Pointer =
case Pointer0 of
{next, Owner, _SK} ->
{next, Owner, StartKey, EndKey};
Pointer0 ->
Pointer0
end,
UpdList =
leveled_sst:sst_expandpointer(
Pointer, RestOfKeys, ScanWidth, SegChecker, LowLastMod
),
% Need to loop around at this level (LCnt) as we have not yet
% examined a real key at this level
find_nextkeys(
maps:update(LCnt, UpdList, Iter),
{LoopLs, PrevBest},
FoundKVs,
Ls,
BI,
SI
)
end.

%%%============================================================================
Expand Down
Loading