Partial fix for bug in last commit, but not good enough

This commit is contained in:
Scott Lystig Fritchie 2014-02-27 15:18:22 +09:00
parent 6858041c7d
commit b7b9255f5f

View file

@ -18,11 +18,6 @@
%%
%% -------------------------------------------------------------------
%% TODO: fix this failure case with append_page(Bin) -> {ok, 2},
%% but read_page(LPN=1) can read Bin, and model believes that
%% LPN=1 was never written
%% Ca = [{2,2,1},{{[{set,{var,1},{call,corfurl_pulse,setup,[2,2,1,standard]}}],[[{set,{var,3},{call,corfurl_pulse,append,[{var,1},<<0>>]}}],[{set,{var,2},{call,corfurl_pulse,stop_sequencer,[{var,1},kill]}},{set,{var,4},{call,corfurl_pulse,trim,[{var,1},386862782]}},{set,{var,5},{call,corfurl_pulse,scan_forward,[{var,1},5412106233,1]}}]]},{24672,25300,90107}},[{events,[[{no_bad_reads,[]}]]}]].
-module(corfurl_client).
-export([append_page/2, read_page/2, fill_page/2, trim_page/2, scan_forward/3]).
@ -40,22 +35,8 @@ append_page(Proj, _Page, 0) ->
{{error_failed, ?MODULE, ?LINE}, Proj};
append_page(#proj{seq={Sequencer,_,_}} = Proj, Page, Retries) ->
try
case corfurl_sequencer:get(Sequencer, 1) of
{ok, LPN} ->
case append_page2(Proj, LPN, Page) of
lost_race ->
append_page(Proj, Page, Retries - 1);
error_badepoch ->
case poll_for_new_epoch_projection(Proj) of
{ok, NewProj} ->
append_page(NewProj, Page, Retries - 1);
Else ->
{Else, Proj}
end;
Else ->
{Else, Proj}
end
end
{ok, LPN} = corfurl_sequencer:get(Sequencer, 1),
append_page1(Proj, LPN, Page, 5)
catch
exit:{Reason,{_gen_server_or_pulse_gen_server,call,[Sequencer|_]}}
when Reason == noproc; Reason == normal ->
@ -64,6 +45,23 @@ append_page(#proj{seq={Sequencer,_,_}} = Proj, Page, Retries) ->
{{error_failed, ?MODULE, ?LINE}, incomplete_code, Exit}
end.
append_page1(Proj, _LPN, _Page, 0) ->
{{error_failed, ?MODULE, ?LINE}, Proj};
append_page1(Proj, LPN, Page, Retries) ->
case append_page2(Proj, LPN, Page) of
lost_race ->
append_page(Proj, Page, Retries - 1);
error_badepoch ->
case poll_for_new_epoch_projection(Proj) of
{ok, NewProj} ->
append_page1(NewProj, LPN, Page, Retries - 1);
Else ->
{Else, Proj}
end;
Else ->
{Else, Proj}
end.
append_page2(Proj, LPN, Page) ->
case corfurl:write_page(Proj, LPN, Page) of
ok ->