Fix silly-dumb errors in seal epoch comparisons

This commit is contained in:
Scott Lystig Fritchie 2014-02-27 00:19:25 +09:00
parent 96b561cde9
commit 63d1c93fc9
3 changed files with 55 additions and 15 deletions

View file

@ -186,12 +186,12 @@ handle_call({{read, _ClientEpoch, LogicalPN}, LC1}, _From, State) ->
{reply, {Reply, LC2}, State};
handle_call({{seal, ClientEpoch}, LC1}, _From, #state{min_epoch=MinEpoch} = State)
when ClientEpoch =< MinEpoch ->
when ClientEpoch < MinEpoch ->
LC2 = lclock_update(LC1),
{reply, {error_badepoch, LC2}, State};
handle_call({{seal, ClientEpoch}, LC1}, _From, #state{max_logical_page=MLPN}=State) ->
LC2 = lclock_update(LC1),
NewState = State#state{min_epoch=ClientEpoch},
NewState = State#state{min_epoch=ClientEpoch+1},
ok = write_hard_state(NewState),
{reply, {{ok, MLPN}, LC2}, NewState};

View file

@ -56,6 +56,7 @@ basic_test() ->
try
Epoch1 = 1,
Epoch2 = 2,
Epoch3 = 3,
LPN = 1,
Bin1 = <<42:64>>,
Bin2 = <<42042:64>>,
@ -71,13 +72,13 @@ basic_test() ->
0 = ?M:get__min_epoch(P1),
0 = ?M:get__trim_watermark(P1),
{ok, LPN} = ?M:seal(P1, Epoch1),
1 = ?M:get__min_epoch(P1),
2 = ?M:get__min_epoch(P1),
error_overwritten = ?M:write(P1, Epoch2, LPN, Bin1),
ok = ?M:write(P1, Epoch2, LPN+1, Bin2),
Epoch1 = ?M:get__min_epoch(P1),
Epoch2 = ?M:get__min_epoch(P1),
{ok, Bin1} = ?M:read(P1, Epoch1, LPN),
error_badepoch = ?M:read(P1, Epoch1, LPN),
{ok, Bin2} = ?M:read(P1, Epoch2, LPN+1),
error_unwritten = ?M:read(P1, Epoch2, LPN+2),
badarg = ?M:read(P1, Epoch2, 1 bsl 2982),
@ -88,23 +89,23 @@ basic_test() ->
error_badepoch = ?M:read(P1, Epoch1, LPN),
error_badepoch = ?M:read(P1, Epoch1, LPN+1),
{ok, Bin1} = ?M:read(P1, Epoch2, LPN),
{ok, Bin2} = ?M:read(P1, Epoch2, LPN+1),
{ok, Bin1} = ?M:read(P1, Epoch3, LPN),
{ok, Bin2} = ?M:read(P1, Epoch3, LPN+1),
error_badepoch = ?M:trim(P1, Epoch1, LPN+1),
ok = ?M:trim(P1, Epoch2, LPN+1),
error_trimmed = ?M:trim(P1, Epoch2, LPN+1),
ok = ?M:trim(P1, Epoch3, LPN+1),
error_trimmed = ?M:trim(P1, Epoch3, LPN+1),
%% Current watermark processing is broken. But we'll test what's
%% there now.
ExpectedWaterFixMe = LPN+1,
ExpectedWaterFixMe = ?M:get__trim_watermark(P1),
ok = ?M:fill(P1, Epoch2, LPN+3),
error_trimmed = ?M:read(P1, Epoch2, LPN+3),
error_trimmed = ?M:fill(P1, Epoch2, LPN+3),
error_trimmed = ?M:trim(P1, Epoch2, LPN+3),
ok = ?M:fill(P1, Epoch3, LPN+3),
error_trimmed = ?M:read(P1, Epoch3, LPN+3),
error_trimmed = ?M:fill(P1, Epoch3, LPN+3),
error_trimmed = ?M:trim(P1, Epoch3, LPN+3),
Epoch2 = ?M:get__min_epoch(P1),
Epoch3 = ?M:get__min_epoch(P1),
ok = ?M:stop(P1),
ok
after
@ -117,7 +118,7 @@ seal_persistence_test() ->
try
0 = ?M:get__min_epoch(P1),
Epoch = 665,
{ok, LPN} = ?M:seal(P1, Epoch),
{ok, LPN} = ?M:seal(P1, Epoch-1),
Epoch = ?M:get__min_epoch(P1),
ok = ?M:stop(P1),

View file

@ -152,6 +152,45 @@ smoke1_test() ->
setup_del_all(NumFLUs)
end.
smoke_append_badepoch_test() ->
PDir = "./tmp.smoke2.projection",
NumFLUs = 6,
PageSize = 8,
NumPages = 10,
FLUs = [F1, F2, F3, F4, F5, F6] =
setup_basic_flus(NumFLUs, PageSize, NumPages),
{ok, Seq} = corfurl_sequencer:start_link(FLUs),
%% We know that the first LPN will be 1.
LPN_Pgs = [{X, list_to_binary(
lists:flatten(io_lib:format("~8..0w", [X])))} ||
X <- lists:seq(1, 5)],
try
LittleEpoch = 4,
BigEpoch = 42,
P0 = ?M:new_simple_projection(PDir, BigEpoch, 1, 1*100,
[[F1, F2, F3], [F4, F5, F6]]),
P1 = P0#proj{seq={Seq, unused, unused}},
[begin {{ok, LPN}, _} = corfurl_client:append_page(P1, Pg) end || {LPN, Pg} <- LPN_Pgs],
[{ok, _} = corfurl_flu:seal(FLU, BigEpoch) || FLU <- FLUs],
[begin
{error_badepoch, _} = corfurl_client:append_page(P1, Pg)
end || {_LPN, Pg} <- LPN_Pgs],
P2 = P1#proj{epoch=LittleEpoch},
[begin
{error_badepoch, _} = corfurl_client:append_page(P2, Pg)
end || {_LPN, Pg} <- LPN_Pgs],
ok
after
corfurl_util:delete_dir(PDir),
corfurl_sequencer:stop(Seq),
[corfurl_flu:stop(F) || F <- FLUs],
setup_del_all(NumFLUs)
end.
-ifdef(TIMING_TEST).
forfun_test_() ->