Add scan_backward LPN limit + test

This commit is contained in:
Scott Lystig Fritchie 2014-08-29 18:20:05 +09:00
parent c311a187ac
commit 1bb127eb65
2 changed files with 28 additions and 8 deletions

View file

@ -25,6 +25,7 @@
-export([pack_v1/3, unpack_v1/2, -export([pack_v1/3, unpack_v1/2,
add_back_pointer/3, add_back_pointer/3,
scan_backward/4, scan_backward/4,
scan_backward/5,
pad_bin/2]). pad_bin/2]).
-define(MAGIC_NUMBER_V1, 16#88990011). -define(MAGIC_NUMBER_V1, 16#88990011).
@ -74,16 +75,21 @@ add_back_pointer([], New) ->
add_back_pointer(BackPs, New) -> add_back_pointer(BackPs, New) ->
[New|BackPs]. [New|BackPs].
scan_backward(Proj, Stream, LastLPN, _WithPagesP) -> scan_backward(Proj, Stream, LastLPN, WithPagesP) ->
lists:reverse(scan_backward2(Proj, Stream, LastLPN, _WithPagesP)). scan_backward(Proj, Stream, LastLPN, 0, WithPagesP).
scan_backward2(Proj, Stream, LastLPN, WithPagesP) -> scan_backward(Proj, Stream, LastLPN, StopAtLPN, WithPagesP) ->
lists:reverse(scan_backward2(Proj, Stream, LastLPN, StopAtLPN, WithPagesP)).
scan_backward2(_Proj, _Stream, LastLPN, StopAtLPN, _WithPagesP)
when LastLPN =< StopAtLPN ->
[];
scan_backward2(Proj, Stream, LastLPN, StopAtLPN, WithPagesP) ->
case corfurl:read_page(Proj, LastLPN) of case corfurl:read_page(Proj, LastLPN) of
{ok, FullPage} -> {ok, FullPage} ->
case proplists:get_value(Stream, unpack_v1(FullPage, stream_list)) of case proplists:get_value(Stream, unpack_v1(FullPage, stream_list)) of
undefined -> undefined ->
{gahh, lpn, LastLPN, unpack_v1(FullPage, stream_list)}; {gah_fixme, lpn, LastLPN, unpack_v1(FullPage, stream_list)};
%% [];
[] -> [] ->
if WithPagesP -> if WithPagesP ->
[{LastLPN, unpack_v1(FullPage, page)}]; [{LastLPN, unpack_v1(FullPage, page)}];
@ -94,13 +100,16 @@ scan_backward2(Proj, Stream, LastLPN, WithPagesP) ->
if WithPagesP -> if WithPagesP ->
[{LastLPN, unpack_v1(FullPage, page)}| [{LastLPN, unpack_v1(FullPage, page)}|
scan_backward2(Proj, Stream, scan_backward2(Proj, Stream,
hd(BackPs), hd(BackPs), StopAtLPN,
WithPagesP)]; WithPagesP)];
true -> true ->
SkipLPN = lists:last(BackPs), SkipLPN = lists:last(BackPs),
[LastLPN] ++ (BackPs -- [SkipLPN]) ++ AddLPNs = [LPN || LPN <- BackPs,
LPN /= SkipLPN,
LPN > StopAtLPN],
[LastLPN] ++ AddLPNs ++
scan_backward2(Proj, Stream, scan_backward2(Proj, Stream,
SkipLPN, SkipLPN, StopAtLPN,
WithPagesP) WithPagesP)
end end
end; end;

View file

@ -136,6 +136,17 @@ scan_backward_test_int(PageSize, _Seq, P1) ->
%% oldest -> newest (i.e. smallest LPN to largest LPN) order. %% oldest -> newest (i.e. smallest LPN to largest LPN) order.
ShouldBe = tango:scan_backward(P2, StreamNum, BackwardStartLPN, ShouldBe = tango:scan_backward(P2, StreamNum, BackwardStartLPN,
false), false),
StopAtLimit = NumPages div 2,
StopAtKicksInAt = StopAtLimit + 2,
{StopAtLPN, ShouldBeLPNS} =
if BackwardStartLPN < StopAtKicksInAt ->
{0, ShouldBe};
true ->
{StopAtLimit, [LPN || LPN <- ShouldBe, LPN > StopAtLimit]}
end,
ShouldBeLPNS =
tango:scan_backward(P2, StreamNum, BackwardStartLPN, StopAtLPN,
false),
%% If we scan backward, we should get a list of LPNs in %% If we scan backward, we should get a list of LPNs in
%% oldest -> newest (i.e. smallest LPN to largest LPN) order %% oldest -> newest (i.e. smallest LPN to largest LPN) order