WIP: hairball, but flu_smoke_test() works!

This commit is contained in:
Scott Lystig Fritchie 2015-06-26 23:03:28 +09:00
parent 920a5c33d7
commit 93f64a20c0
4 changed files with 105 additions and 68 deletions

View file

@ -547,6 +547,8 @@ message Mpb_LL_Request {
optional Mpb_LL_ChecksumListReq checksum_list = 33; optional Mpb_LL_ChecksumListReq checksum_list = 33;
optional Mpb_LL_ListFilesReq list_files = 34; optional Mpb_LL_ListFilesReq list_files = 34;
optional Mpb_LL_WedgeStatusReq wedge_status = 35; optional Mpb_LL_WedgeStatusReq wedge_status = 35;
optional Mpb_LL_DeleteMigrationReq delete_migration = 36;
optional Mpb_LL_TruncHackReq trunc_hack = 37;
} }
message Mpb_LL_Response { message Mpb_LL_Response {
@ -578,4 +580,6 @@ message Mpb_LL_Response {
optional Mpb_LL_ChecksumListResp checksum_list = 33; optional Mpb_LL_ChecksumListResp checksum_list = 33;
optional Mpb_LL_ListFilesResp list_files = 34; optional Mpb_LL_ListFilesResp list_files = 34;
optional Mpb_LL_WedgeStatusResp wedge_status = 35; optional Mpb_LL_WedgeStatusResp wedge_status = 35;
optional Mpb_LL_DeleteMigrationResp delete_migration = 36;
optional Mpb_LL_TruncHackResp trunc_hack = 37;
} }

View file

@ -339,7 +339,11 @@ do_pb_request3({low_checksum_list, _EpochID, File}, S) ->
do_pb_request3({low_list_files, _EpochID}, S) -> do_pb_request3({low_list_files, _EpochID}, S) ->
{do_pb_server_list_files(S), S}; {do_pb_server_list_files(S), S};
do_pb_request3({low_wedge_status, _EpochID}, S) -> do_pb_request3({low_wedge_status, _EpochID}, S) ->
{do_pb_server_wedge_status(S), S}. {do_pb_server_wedge_status(S), S};
do_pb_request3({low_delete_migration, _EpochID, File}, S) ->
{do_pb_server_delete_migration(File, S), S};
do_pb_request3({low_trunc_hack, _EpochID, File}, S) ->
{do_pb_server_trunc_hack(File, S), S}.
do_pb_server_append_chunk(PKey, Prefix, Chunk, CSum_tag, CSum, do_pb_server_append_chunk(PKey, Prefix, Chunk, CSum_tag, CSum,
ChunkExtra, S) -> ChunkExtra, S) ->
@ -540,6 +544,45 @@ do_pb_server_wedge_status(S) ->
{Wedged_p, CurrentEpochID} = ets:lookup_element(S#state.etstab, epoch, 2), {Wedged_p, CurrentEpochID} = ets:lookup_element(S#state.etstab, epoch, 2),
{Wedged_p, CurrentEpochID}. {Wedged_p, CurrentEpochID}.
do_pb_server_delete_migration(File, #state{data_dir=DataDir}=_S) ->
case sanitize_file_string(File) of
ok ->
{_, Path} = machi_util:make_data_filename(DataDir, File),
case file:delete(Path) of
ok ->
ok;
{error, enoent} ->
{error, no_such_file};
_ ->
{error, bad_arg}
end;
_ ->
{error, bad_arg}
end.
do_pb_server_trunc_hack(File, #state{data_dir=DataDir}=_S) ->
case sanitize_file_string(File) of
ok ->
{_, Path} = machi_util:make_data_filename(DataDir, File),
case file:open(Path, [read, write, binary, raw]) of
{ok, FH} ->
try
{ok, ?MINIMUM_OFFSET} = file:position(FH,
?MINIMUM_OFFSET),
ok = file:truncate(FH),
ok
after
file:close(FH)
end;
{error, enoent} ->
{error, no_such_file};
_ ->
{error, bad_arg}
end;
_ ->
{error, bad_arg}
end.
net_server_loop_old(Sock, #state{flu_name=FluName, data_dir=DataDir}=S) -> net_server_loop_old(Sock, #state{flu_name=FluName, data_dir=DataDir}=S) ->
%% TODO: Add testing control knob to adjust this timeout and/or inject %% TODO: Add testing control knob to adjust this timeout and/or inject
%% timeout condition. %% timeout condition.

View file

@ -571,70 +571,16 @@ checksum_list_finish(Chunks) ->
Line /= <<>>]. Line /= <<>>].
delete_migration2(Sock, EpochID, File) -> delete_migration2(Sock, EpochID, File) ->
erase(bad_sock), ReqID = <<"id">>,
try Req = machi_pb_translate:to_pb_request(
{EpochNum, EpochCSum} = EpochID, ReqID, {low_delete_migration, EpochID, File}),
EpochIDHex = machi_util:bin_to_hexstr( do_pb_request_common(Sock, ReqID, Req).
<<EpochNum:(4*8)/big, EpochCSum/binary>>),
Cmd = [<<"DEL-migration ">>, EpochIDHex, File, <<"\n">>],
ok = w_send(Sock, Cmd),
ok = w_setopts(Sock, [{packet, line}]),
case w_recv(Sock, 0) of
{ok, <<"OK\n">>} ->
ok;
{ok, <<"ERROR NO-SUCH-FILE", _/binary>>} ->
{error, no_such_file};
{ok, <<"ERROR BAD-ARG", _/binary>>} ->
{error, bad_arg};
{ok, <<"ERROR WEDGED", _/binary>>} ->
{error, wedged};
{ok, Else} ->
throw({server_protocol_error, Else})
end
catch
throw:Error ->
put(bad_sock, Sock),
Error;
error:{case_clause,_}=Noo ->
put(bad_sock, Sock),
{error, {badmatch, Noo, erlang:get_stacktrace()}};
error:{badmatch,_}=BadMatch ->
put(bad_sock, Sock),
{error, {badmatch, BadMatch}}
end.
trunc_hack2(Sock, EpochID, File) -> trunc_hack2(Sock, EpochID, File) ->
erase(bad_sock), ReqID = <<"id-trunc">>,
try Req = machi_pb_translate:to_pb_request(
{EpochNum, EpochCSum} = EpochID, ReqID, {low_trunc_hack, EpochID, File}),
EpochIDHex = machi_util:bin_to_hexstr( do_pb_request_common(Sock, ReqID, Req).
<<EpochNum:(4*8)/big, EpochCSum/binary>>),
Cmd = [<<"TRUNC-hack--- ">>, EpochIDHex, File, <<"\n">>],
ok = w_send(Sock, Cmd),
ok = w_setopts(Sock, [{packet, line}]),
case w_recv(Sock, 0) of
{ok, <<"OK\n">>} ->
ok;
{ok, <<"ERROR NO-SUCH-FILE", _/binary>>} ->
{error, no_such_file};
{ok, <<"ERROR BAD-ARG", _/binary>>} ->
{error, bad_arg};
{ok, <<"ERROR WEDGED", _/binary>>} ->
{error, wedged};
{ok, Else} ->
throw({server_protocol_error, Else})
end
catch
throw:Error ->
put(bad_sock, Sock),
Error;
error:{case_clause,_}=Noo ->
put(bad_sock, Sock),
{error, {badmatch, Noo, erlang:get_stacktrace()}};
error:{badmatch,_}=BadMatch ->
put(bad_sock, Sock),
{error, {badmatch, BadMatch}}
end.
get_latest_epochid2(Sock, ProjType) -> get_latest_epochid2(Sock, ProjType) ->
ReqID = <<42>>, ReqID = <<42>>,

View file

@ -94,6 +94,20 @@ from_pb_request(#mpb_ll_request{
req_id=ReqID, req_id=ReqID,
wedge_status=#mpb_ll_wedgestatusreq{}}) -> wedge_status=#mpb_ll_wedgestatusreq{}}) ->
{ReqID, {low_wedge_status, undefined}}; {ReqID, {low_wedge_status, undefined}};
from_pb_request(#mpb_ll_request{
req_id=ReqID,
delete_migration=#mpb_ll_deletemigrationreq{
epoch_id=PB_EpochID,
file=File}}) ->
EpochID = conv_to_epoch_id(PB_EpochID),
{ReqID, {low_delete_migration, EpochID, File}};
from_pb_request(#mpb_ll_request{
req_id=ReqID,
trunc_hack=#mpb_ll_trunchackreq{
epoch_id=PB_EpochID,
file=File}}) ->
EpochID = conv_to_epoch_id(PB_EpochID),
{ReqID, {low_trunc_hack, EpochID, File}};
%%qqq %%qqq
from_pb_request(#mpb_request{req_id=ReqID, from_pb_request(#mpb_request{req_id=ReqID,
echo=#mpb_echoreq{message=Msg}}) -> echo=#mpb_echoreq{message=Msg}}) ->
@ -205,6 +219,16 @@ from_pb_response(#mpb_ll_response{
PB_Wedged == 0 -> false PB_Wedged == 0 -> false
end, end,
{ReqID, {ok, {Wedged_p, EpochID}}}; {ReqID, {ok, {Wedged_p, EpochID}}};
from_pb_response(#mpb_ll_response{
req_id=ReqID,
delete_migration=#mpb_ll_deletemigrationresp{
status=Status}}) ->
{ReqID, machi_pb_high_client:convert_general_status_code(Status)};
from_pb_response(#mpb_ll_response{
req_id=ReqID,
trunc_hack=#mpb_ll_trunchackresp{
status=Status}}) ->
{ReqID, machi_pb_high_client:convert_general_status_code(Status)};
%%qqq %%qqq
from_pb_response(#mpb_ll_response{ from_pb_response(#mpb_ll_response{
req_id=ReqID, req_id=ReqID,
@ -309,17 +333,29 @@ to_pb_request(ReqID, {low_read_chunk, EpochID, File, Offset, Size, _Opts}) ->
size=Size}}; size=Size}};
to_pb_request(ReqID, {low_checksum_list, EpochID, File}) -> to_pb_request(ReqID, {low_checksum_list, EpochID, File}) ->
PB_EpochID = conv_from_epoch_id(EpochID), PB_EpochID = conv_from_epoch_id(EpochID),
#mpb_ll_request{ #mpb_ll_request{req_id=ReqID,
req_id=ReqID, checksum_list=#mpb_ll_checksumlistreq{
checksum_list=#mpb_ll_checksumlistreq{epoch_id=PB_EpochID, epoch_id=PB_EpochID,
file=File}}; file=File}};
to_pb_request(ReqID, {low_list_files, EpochID}) -> to_pb_request(ReqID, {low_list_files, EpochID}) ->
PB_EpochID = conv_from_epoch_id(EpochID), PB_EpochID = conv_from_epoch_id(EpochID),
#mpb_ll_request{req_id=ReqID, #mpb_ll_request{req_id=ReqID,
list_files=#mpb_ll_listfilesreq{epoch_id=PB_EpochID}}; list_files=#mpb_ll_listfilesreq{epoch_id=PB_EpochID}};
to_pb_request(ReqID, {low_wedge_status, _BogusEpochID}) -> to_pb_request(ReqID, {low_wedge_status, _BogusEpochID}) ->
#mpb_ll_request{req_id=ReqID, #mpb_ll_request{req_id=ReqID,
wedge_status=#mpb_ll_wedgestatusreq{}}. wedge_status=#mpb_ll_wedgestatusreq{}};
to_pb_request(ReqID, {low_delete_migration, EpochID, File}) ->
PB_EpochID = conv_from_epoch_id(EpochID),
#mpb_ll_request{req_id=ReqID,
delete_migration=#mpb_ll_deletemigrationreq{
epoch_id=PB_EpochID,
file=File}};
to_pb_request(ReqID, {low_trunc_hack, EpochID, File}) ->
PB_EpochID = conv_from_epoch_id(EpochID),
#mpb_ll_request{req_id=ReqID,
trunc_hack=#mpb_ll_trunchackreq{
epoch_id=PB_EpochID,
file=File}}.
%%qqq %%qqq
to_pb_response(ReqID, {low_echo, _BogusEpochID, _Msg}, Resp) -> to_pb_response(ReqID, {low_echo, _BogusEpochID, _Msg}, Resp) ->
@ -400,6 +436,14 @@ to_pb_response(ReqID, {low_wedge_status, _BogusEpochID}, Resp) ->
#mpb_ll_response{req_id=ReqID, #mpb_ll_response{req_id=ReqID,
wedge_status=#mpb_ll_wedgestatusresp{epoch_id=PB_EpochID, wedge_status=#mpb_ll_wedgestatusresp{epoch_id=PB_EpochID,
wedged_flag=PB_Wedged}}; wedged_flag=PB_Wedged}};
to_pb_response(ReqID, {low_delete_migration, _EID, _Fl}, Resp)->
Status = conv_from_status(Resp),
#mpb_ll_response{req_id=ReqID,
delete_migration=#mpb_ll_deletemigrationresp{status=Status}};
to_pb_response(ReqID, {low_trunc_hack, _EID, _Fl}, Resp)->
Status = conv_from_status(Resp),
#mpb_ll_response{req_id=ReqID,
trunc_hack=#mpb_ll_trunchackresp{status=Status}};
%%qqq %%qqq
to_pb_response(ReqID, {high_echo, _Msg}, Resp) -> to_pb_response(ReqID, {high_echo, _Msg}, Resp) ->
Msg = Resp, Msg = Resp,