Pass epoch id to append operations

Needed to handle a filename change when epoch changes.
This commit is contained in:
Mark Allen 2015-10-13 21:08:48 -05:00
parent 85e1e5a26d
commit 161e6cd9f9

View file

@ -237,7 +237,7 @@ append_server_loop(FluPid, #state{wedged=Wedged_p,
case OldEpochId == EpochID of case OldEpochId == EpochID of
true -> true ->
spawn(fun() -> spawn(fun() ->
append_server_dispatch(From, Prefix, Chunk, CSum, Extra, FluName) append_server_dispatch(From, Prefix, Chunk, CSum, Extra, FluName, EpochID)
end); end);
false -> false ->
From ! {error, bad_epoch} From ! {error, bad_epoch}
@ -636,8 +636,8 @@ do_server_trunc_hack(File, #state{data_dir=DataDir}=_S) ->
{error, bad_arg} {error, bad_arg}
end. end.
append_server_dispatch(From, Prefix, Chunk, CSum, Extra, FluName) -> append_server_dispatch(From, Prefix, Chunk, CSum, Extra, FluName, EpochId) ->
Result = case handle_append(Prefix, Chunk, CSum, Extra, FluName) of Result = case handle_append(Prefix, Chunk, CSum, Extra, FluName, EpochId) of
{ok, File, Offset} -> {ok, File, Offset} ->
{assignment, Offset, File}; {assignment, Offset, File};
Other -> Other ->
@ -646,10 +646,10 @@ append_server_dispatch(From, Prefix, Chunk, CSum, Extra, FluName) ->
From ! Result, From ! Result,
exit(normal). exit(normal).
handle_append(_Prefix, <<>>, _Csum, _Extra, _FluName) -> handle_append(_Prefix, <<>>, _Csum, _Extra, _FluName, _EpochId) ->
{error, bad_arg}; {error, bad_arg};
handle_append(Prefix, Chunk, Csum, Extra, FluName) -> handle_append(Prefix, Chunk, Csum, Extra, FluName, EpochId) ->
Res = machi_flu_filename_mgr:find_or_make_filename_from_prefix(FluName, {prefix, Prefix}), Res = machi_flu_filename_mgr:find_or_make_filename_from_prefix(FluName, EpochId, {prefix, Prefix}),
case Res of case Res of
{file, F} -> {file, F} ->
{ok, Pid} = machi_flu_metadata_mgr:start_proxy_pid(FluName, {file, F}), {ok, Pid} = machi_flu_metadata_mgr:start_proxy_pid(FluName, {file, F}),
@ -661,11 +661,17 @@ handle_append(Prefix, Chunk, Csum, Extra, FluName) ->
end. end.
sanitize_file_string(Str) -> sanitize_file_string(Str) ->
case has_no_prohibited_chars(Str) andalso machi_util:is_valid_filename(Str) of
true -> ok;
false -> error
end.
has_no_prohibited_chars(Str) ->
case re:run(Str, "/") of case re:run(Str, "/") of
nomatch -> nomatch ->
ok; true;
_ -> _ ->
error true
end. end.
sanitize_prefix(Prefix) -> sanitize_prefix(Prefix) ->