From 1bb127eb651ce8eda9f5e3b212345959f133c5e9 Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Fri, 29 Aug 2014 18:20:05 +0900 Subject: [PATCH] Add scan_backward LPN limit + test --- prototype/tango-prototype/src/tango.erl | 25 +++++++++++++------ prototype/tango-prototype/test/tango_test.erl | 11 ++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/prototype/tango-prototype/src/tango.erl b/prototype/tango-prototype/src/tango.erl index 8cf0c40..4513a93 100644 --- a/prototype/tango-prototype/src/tango.erl +++ b/prototype/tango-prototype/src/tango.erl @@ -25,6 +25,7 @@ -export([pack_v1/3, unpack_v1/2, add_back_pointer/3, scan_backward/4, + scan_backward/5, pad_bin/2]). -define(MAGIC_NUMBER_V1, 16#88990011). @@ -74,16 +75,21 @@ add_back_pointer([], New) -> add_back_pointer(BackPs, New) -> [New|BackPs]. -scan_backward(Proj, Stream, LastLPN, _WithPagesP) -> - lists:reverse(scan_backward2(Proj, Stream, LastLPN, _WithPagesP)). +scan_backward(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 {ok, FullPage} -> case proplists:get_value(Stream, unpack_v1(FullPage, stream_list)) of undefined -> - {gahh, lpn, LastLPN, unpack_v1(FullPage, stream_list)}; - %% []; + {gah_fixme, lpn, LastLPN, unpack_v1(FullPage, stream_list)}; [] -> if WithPagesP -> [{LastLPN, unpack_v1(FullPage, page)}]; @@ -94,13 +100,16 @@ scan_backward2(Proj, Stream, LastLPN, WithPagesP) -> if WithPagesP -> [{LastLPN, unpack_v1(FullPage, page)}| scan_backward2(Proj, Stream, - hd(BackPs), + hd(BackPs), StopAtLPN, WithPagesP)]; true -> SkipLPN = lists:last(BackPs), - [LastLPN] ++ (BackPs -- [SkipLPN]) ++ + AddLPNs = [LPN || LPN <- BackPs, + LPN /= SkipLPN, + LPN > StopAtLPN], + [LastLPN] ++ AddLPNs ++ scan_backward2(Proj, Stream, - SkipLPN, + SkipLPN, StopAtLPN, WithPagesP) end end; diff --git a/prototype/tango-prototype/test/tango_test.erl b/prototype/tango-prototype/test/tango_test.erl index 29febf7..be7e7a9 100644 --- a/prototype/tango-prototype/test/tango_test.erl +++ b/prototype/tango-prototype/test/tango_test.erl @@ -136,6 +136,17 @@ scan_backward_test_int(PageSize, _Seq, P1) -> %% oldest -> newest (i.e. smallest LPN to largest LPN) order. ShouldBe = tango:scan_backward(P2, StreamNum, BackwardStartLPN, 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 %% oldest -> newest (i.e. smallest LPN to largest LPN) order