Fix Dialyzer complaints, derp!

This commit is contained in:
Scott Lystig Fritchie 2015-12-04 15:21:44 +09:00
parent 37f33fae7b
commit 35c48300a5
4 changed files with 30 additions and 23 deletions

View file

@ -30,6 +30,7 @@
-type chunk_pos() :: {file_offset(), chunk_size(), file_name_s()}.
-type chunk_size() :: non_neg_integer().
-type coc_namespace() :: string().
-type coc_nl() :: {coc, coc_namespace(), coc_locator()}.
-type coc_locator() :: non_neg_integer().
-type error_general() :: 'bad_arg' | 'wedged' | 'bad_checksum'.
-type epoch_csum() :: binary().
@ -61,6 +62,7 @@
chunk_pos/0,
chunk_size/0,
coc_namespace/0,
coc_nl/0,
coc_locator/0,
error_general/0,
epoch_csum/0,

View file

@ -52,7 +52,7 @@
child_spec/2,
start_link/2,
find_or_make_filename_from_prefix/4,
increment_prefix_sequence/2,
increment_prefix_sequence/3,
list_files_by_prefix/2
]).
@ -90,7 +90,7 @@ start_link(FluName, DataDir) when is_atom(FluName) andalso is_list(DataDir) ->
-spec find_or_make_filename_from_prefix( FluName :: atom(),
EpochId :: pv1_epoch_n(),
Prefix :: {prefix, string()},
{coc, riak_dt:coc_namespace(), riak_dt:coc_locator()}) ->
machi_dt:coc_nl()) ->
{file, Filename :: string()} | {error, Reason :: term() } | timeout.
% @doc Find the latest available or make a filename from a prefix. A prefix
% should be in the form of a tagged tuple `{prefix, P}'. Returns a tagged
@ -105,13 +105,13 @@ find_or_make_filename_from_prefix(_FluName, _EpochId, Other, Other2) ->
lager:error("~p is not a valid prefix/CoC ~p", [Other, Other2]),
error(badarg).
-spec increment_prefix_sequence( FluName :: atom(), Prefix :: {prefix, string()} ) ->
-spec increment_prefix_sequence( FluName :: atom(), CoC_NL :: machi_dt:coc_nl(), Prefix :: {prefix, string()} ) ->
ok | {error, Reason :: term() } | timeout.
% @doc Increment the sequence counter for a given prefix. Prefix should
% be in the form of `{prefix, P}'.
increment_prefix_sequence(FluName, {prefix, Prefix}) when is_atom(FluName) ->
gen_server:call(make_filename_mgr_name(FluName), {increment_sequence, Prefix}, ?TIMEOUT);
increment_prefix_sequence(_FluName, Other) ->
increment_prefix_sequence(FluName, {coc,_CoC_Namespace,_CoC_Locator}=CoC_NL, {prefix, Prefix}) when is_atom(FluName) ->
gen_server:call(make_filename_mgr_name(FluName), {increment_sequence, CoC_NL, Prefix}, ?TIMEOUT);
increment_prefix_sequence(_FluName, _CoC_NL, Other) ->
lager:error("~p is not a valid prefix.", [Other]),
error(badarg).
@ -157,8 +157,8 @@ handle_call({find_filename, EpochId, CoC_NL, Prefix}, _From, S = #state{ datadir
File = increment_and_cache_filename(Tid, DataDir, CoC_NL, Prefix),
{reply, {file, File}, S#state{epoch = EpochId}};
handle_call({increment_sequence, Prefix}, _From, S = #state{ datadir = DataDir }) ->
ok = machi_util:increment_max_filenum(DataDir, Prefix),
handle_call({increment_sequence, {coc,CoC_Namespace,CoC_Locator}=_CoC_NL, Prefix}, _From, S = #state{ datadir = DataDir }) ->
ok = machi_util:increment_max_filenum(DataDir, CoC_Namespace,CoC_Locator, Prefix),
{reply, ok, S};
handle_call({list_files, Prefix}, From, S = #state{ datadir = DataDir }) ->
spawn(fun() ->
@ -198,7 +198,7 @@ find_file(DataDir, {coc,CoC_Namespace,CoC_Locator}=_CoC_NL, Prefix, N) ->
filelib:wildcard(Path).
list_files(DataDir, Prefix) ->
{F_bin, Path} = machi_util:make_data_filename(DataDir, Prefix, "*", "*"),
{F_bin, Path} = machi_util:make_data_filename(DataDir, "*^" ++ Prefix ++ "^*"),
filelib:wildcard(binary_to_list(F_bin), filename:dirname(Path)).
make_filename_mgr_name(FluName) when is_atom(FluName) ->

View file

@ -185,14 +185,17 @@ handle_info({'DOWN', Mref, process, Pid, file_rollover}, State = #state{ fluname
tid = Tid }) ->
lager:info("file proxy ~p shutdown because of file rollover", [Pid]),
R = get_md_record_by_mref(Tid, Mref),
[Prefix | _Rest] = machi_util:parse_filename(R#md.filename),
{Prefix, CoC_Namespace, CoC_Locator, _, _} =
machi_util:parse_filename(R#md.filename),
%% CoC_Namespace = list_to_binary(CoC_Namespace_str),
%% CoC_Locator = list_to_integer(CoC_Locator_str),
%% We only increment the counter here. The filename will be generated on the
%% next append request to that prefix and since the filename will have a new
%% sequence number it probably will be associated with a different metadata
%% manager. That's why we don't want to generate a new file name immediately
%% and use it to start a new file proxy.
ok = machi_flu_filename_mgr:increment_prefix_sequence(FluName, {prefix, Prefix}),
ok = machi_flu_filename_mgr:increment_prefix_sequence(FluName, {coc, CoC_Namespace, CoC_Locator}, {prefix, Prefix}),
%% purge our ets table of this entry completely since it is likely the
%% new filename (whenever it comes) will be in a different manager than

View file

@ -68,7 +68,7 @@ make_regname(Prefix) when is_list(Prefix) ->
%% @doc Calculate a config file path, by common convention.
-spec make_config_filename(string(), riak_dt:coc_namespace(), riak_dt:coc_locator(), string()) ->
-spec make_config_filename(string(), machi_dt:coc_namespace(), machi_dt:coc_locator(), string()) ->
string().
make_config_filename(DataDir, CoC_Namespace, CoC_Locator, Prefix) ->
Locator_str = int_to_hexstr(CoC_Locator, 32),
@ -102,7 +102,7 @@ make_checksum_filename(DataDir, FileName) ->
%% @doc Calculate a file data file path, by common convention.
-spec make_data_filename(string(), riak_dt:coc_namespace(), riak_dt:coc_locator(), string(), atom()|string()|binary(), integer()|string()) ->
-spec make_data_filename(string(), machi_dt:coc_namespace(), machi_dt:coc_locator(), string(), atom()|string()|binary(), integer()|string()) ->
{binary(), string()}.
make_data_filename(DataDir, CoC_Namespace, CoC_Locator, Prefix, SequencerName, FileNum)
when is_integer(FileNum) ->
@ -146,40 +146,42 @@ make_projection_filename(DataDir, File) ->
-spec is_valid_filename( Filename :: string() ) -> true | false.
is_valid_filename(Filename) ->
case parse_filename(Filename) of
[] -> false;
_ -> true
{} -> false;
{_,_,_,_,_} -> true
end.
%% @doc Given a machi filename, return a set of components in a list.
%% The components will be:
%% <ul>
%% <li>Prefix</li>
%% <li>CoC Namespace</li>
%% <li>CoC locator</li>
%% <li>UUID</li>
%% <li>Sequence number</li>
%% </ul>
%%
%% Invalid filenames will return an empty list.
-spec parse_filename( Filename :: string() ) -> [ string() ].
-spec parse_filename( Filename :: string() ) -> {} | {string(), machi_dt:coc_namespace(), machi_dt:coc_locator(), string(), string() }.
parse_filename(Filename) ->
case string:tokens(Filename, "^") of
[_Prefix, _CoC_NS, _CoC_Loc, _UUID, _SeqNo] = L ->
L;
[Prefix, CoC_NS, CoC_Loc, UUID, SeqNo] ->
{Prefix, CoC_NS, list_to_integer(CoC_Loc), UUID, SeqNo};
[Prefix, CoC_Loc, UUID, SeqNo] ->
%% string:tokens() doesn't consider "foo^^bar" as 3 tokens {sigh}
case re:replace(Filename, "[^^]+", "x", [global,{return,binary}]) of
<<"x^^x^x^x">> ->
[Prefix, "", CoC_Loc, UUID, SeqNo];
{Prefix, <<"">>, list_to_integer(CoC_Loc), UUID, SeqNo};
_ ->
[]
{}
end;
_ -> []
_ -> {}
end.
%% @doc Read the file size of a config file, which is used as the
%% basis for a minimum sequence number.
-spec read_max_filenum(string(), riak_dt:coc_namespace(), riak_dt:coc_locator(), string()) ->
-spec read_max_filenum(string(), machi_dt:coc_namespace(), machi_dt:coc_locator(), string()) ->
non_neg_integer().
read_max_filenum(DataDir, CoC_Namespace, CoC_Locator, Prefix) ->
case file:read_file_info(make_config_filename(DataDir, CoC_Namespace, CoC_Locator, Prefix)) of
@ -192,7 +194,7 @@ read_max_filenum(DataDir, CoC_Namespace, CoC_Locator, Prefix) ->
%% @doc Increase the file size of a config file, which is used as the
%% basis for a minimum sequence number.
-spec increment_max_filenum(string(), riak_dt:coc_namespace(), riak_dt:coc_locator(), string()) ->
-spec increment_max_filenum(string(), machi_dt:coc_namespace(), machi_dt:coc_locator(), string()) ->
ok | {error, term()}.
increment_max_filenum(DataDir, CoC_Namespace, CoC_Locator, Prefix) ->
try