TODO fix: wedge self

This commit is contained in:
Scott Lystig Fritchie 2015-07-01 17:19:11 +09:00
parent 1e14fe878f
commit 2c869ed598

View file

@ -85,7 +85,7 @@
-define(SERVER_CMD_READ_TIMEOUT, 600*1000). -define(SERVER_CMD_READ_TIMEOUT, 600*1000).
-export([start_link/1, stop/1, -export([start_link/1, stop/1,
update_wedge_state/3]). update_wedge_state/3, wedge_myself/2]).
-export([make_listener_regname/1, make_projection_server_regname/1]). -export([make_listener_regname/1, make_projection_server_regname/1]).
-export([encode_csum_file_entry/3, encode_csum_file_entry_bin/3, -export([encode_csum_file_entry/3, encode_csum_file_entry_bin/3,
decode_csum_file_entry/1, decode_csum_file_entry/1,
@ -128,6 +128,10 @@ update_wedge_state(PidSpec, Boolean, EpochId)
when (Boolean == true orelse Boolean == false), is_tuple(EpochId) -> when (Boolean == true orelse Boolean == false), is_tuple(EpochId) ->
PidSpec ! {wedge_state_change, Boolean, EpochId}. PidSpec ! {wedge_state_change, Boolean, EpochId}.
wedge_myself(PidSpec, EpochId)
when is_tuple(EpochId) ->
PidSpec ! {wedge_myself, EpochId}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
ets_table_name(FluName) when is_atom(FluName) -> ets_table_name(FluName) when is_atom(FluName) ->
@ -246,7 +250,8 @@ listen_server_loop(LSock, S) ->
spawn_link(fun() -> net_server_loop(Sock, S) end), spawn_link(fun() -> net_server_loop(Sock, S) end),
listen_server_loop(LSock, S). listen_server_loop(LSock, S).
append_server_loop(FluPid, #state{data_dir=DataDir,wedged=Wedged_p}=S) -> append_server_loop(FluPid, #state{data_dir=DataDir,wedged=Wedged_p,
epoch_id=OldEpochId}=S) ->
AppendServerPid = self(), AppendServerPid = self(),
receive receive
{seq_append, From, _Prefix, _Chunk, _CSum, _Extra} when Wedged_p -> {seq_append, From, _Prefix, _Chunk, _CSum, _Extra} when Wedged_p ->
@ -257,10 +262,26 @@ append_server_loop(FluPid, #state{data_dir=DataDir,wedged=Wedged_p}=S) ->
Chunk, CSum, Extra, Chunk, CSum, Extra,
DataDir, AppendServerPid) end), DataDir, AppendServerPid) end),
append_server_loop(FluPid, S); append_server_loop(FluPid, S);
{wedge_state_change, Boolean, EpochId} -> {wedge_myself, WedgeEpochId} ->
true = ets:insert(S#state.etstab, {epoch, {Boolean, EpochId}}), if WedgeEpochId == OldEpochId ->
append_server_loop(FluPid, S#state{wedged=Boolean, true = ets:insert(S#state.etstab,
epoch_id=EpochId}); {epoch, {true, OldEpochId}}),
append_server_loop(FluPid, S#state{wedged=true});
true ->
append_server_loop(FluPid, S)
end;
{wedge_state_change, Boolean, {NewEpoch, _}=NewEpochId} ->
OldEpoch = case OldEpochId of {OldE, _} -> OldE;
undefined -> -1
end,
if NewEpoch >= OldEpoch ->
true = ets:insert(S#state.etstab,
{epoch, {Boolean, NewEpochId}}),
append_server_loop(FluPid, S#state{wedged=Boolean,
epoch_id=NewEpochId});
true ->
append_server_loop(FluPid, S)
end;
{wedge_status, FromPid} -> {wedge_status, FromPid} ->
#state{wedged=Wedged_p, epoch_id=EpochId} = S, #state{wedged=Wedged_p, epoch_id=EpochId} = S,
FromPid ! {wedge_status_reply, Wedged_p, EpochId}, FromPid ! {wedge_status_reply, Wedged_p, EpochId},
@ -350,8 +371,9 @@ do_pb_ll_request2(EpochID, CMD, S) ->
true -> true ->
%% We're at same epoch # but different checksum, or %% We're at same epoch # but different checksum, or
%% we're at a newer/bigger epoch #. %% we're at a newer/bigger epoch #.
io:format(user, "\n\nTODO: wedge myself!\n\n", []), io:format(user, "\n\nTODO/monitor: wedging myself!\n\n",[]),
todo_wedge_myself wedge_myself(S#state.flu_name, CurrentEpochID),
ok
end, end,
{{error, bad_epoch}, S}; {{error, bad_epoch}, S};
true -> true ->