fix(ft-fs): move default config to the backend impl

This commit is contained in:
Andrew Mayorov 2023-03-30 11:47:02 +03:00 committed by Ilya Averyanov
parent 258fabbf8b
commit 28d87ca62d
3 changed files with 15 additions and 18 deletions

View File

@ -22,7 +22,6 @@
%% Accessors %% Accessors
-export([storage/0]). -export([storage/0]).
-export([segments_root/1]).
-export([gc_interval/1]). -export([gc_interval/1]).
-export([segments_ttl/1]). -export([segments_ttl/1]).
@ -49,16 +48,6 @@
storage() -> storage() ->
emqx_config:get([file_transfer, storage], disabled). emqx_config:get([file_transfer, storage], disabled).
-spec segments_root(_Storage) -> file:name().
segments_root(_Storage) ->
Conf = assert_storage(local),
case emqx_map_lib:deep_find([segments, root], Conf) of
{ok, Root} ->
Root;
{not_found, _, _} ->
filename:join([emqx:data_dir(), file_transfer, segments])
end.
-spec gc_interval(_Storage) -> milliseconds(). -spec gc_interval(_Storage) -> milliseconds().
gc_interval(_Storage) -> gc_interval(_Storage) ->
Conf = assert_storage(local), Conf = assert_storage(local),

View File

@ -41,6 +41,7 @@
% GC API % GC API
% TODO: This is quickly becomes hairy. % TODO: This is quickly becomes hairy.
-export([get_root/1]).
-export([get_subdir/2]). -export([get_subdir/2]).
-export([get_subdir/3]). -export([get_subdir/3]).
@ -220,7 +221,7 @@ transfers(Storage) ->
% TODO `Continuation` % TODO `Continuation`
% There might be millions of transfers on the node, we need a protocol and % There might be millions of transfers on the node, we need a protocol and
% storage schema to iterate through them effectively. % storage schema to iterate through them effectively.
ClientIds = try_list_dir(get_segments_root(Storage)), ClientIds = try_list_dir(get_root(Storage)),
{ok, {ok,
lists:foldl( lists:foldl(
fun(ClientId, Acc) -> transfers(Storage, ClientId, Acc) end, fun(ClientId, Acc) -> transfers(Storage, ClientId, Acc) end,
@ -229,7 +230,7 @@ transfers(Storage) ->
)}. )}.
transfers(Storage, ClientId, AccIn) -> transfers(Storage, ClientId, AccIn) ->
Dirname = filename:join(get_segments_root(Storage), ClientId), Dirname = filename:join(get_root(Storage), ClientId),
case file:list_dir(Dirname) of case file:list_dir(Dirname) of
{ok, FileIds} -> {ok, FileIds} ->
lists:foldl( lists:foldl(
@ -263,6 +264,16 @@ read_transferinfo(Storage, Transfer, Acc) ->
Acc Acc
end. end.
-spec get_root(storage()) ->
file:name().
get_root(Storage) ->
case emqx_map_lib:deep_find([segments, root], Storage) of
{ok, Root} ->
Root;
{not_found, _, _} ->
filename:join([emqx:data_dir(), file_transfer, segments])
end.
-spec get_subdir(storage(), transfer()) -> -spec get_subdir(storage(), transfer()) ->
file:name(). file:name().
get_subdir(Storage, Transfer) -> get_subdir(Storage, Transfer) ->
@ -307,7 +318,7 @@ break_segment_filename(Filename) ->
mk_filedir(Storage, {ClientId, FileId}, SubDirs) -> mk_filedir(Storage, {ClientId, FileId}, SubDirs) ->
filename:join([ filename:join([
get_segments_root(Storage), get_root(Storage),
emqx_ft_fs_util:escape_filename(ClientId), emqx_ft_fs_util:escape_filename(ClientId),
emqx_ft_fs_util:escape_filename(FileId) emqx_ft_fs_util:escape_filename(FileId)
| SubDirs | SubDirs
@ -325,9 +336,6 @@ try_list_dir(Dirname) ->
{error, _} -> [] {error, _} -> []
end. end.
get_segments_root(Storage) ->
emqx_ft_conf:segments_root(Storage).
-include_lib("kernel/include/file.hrl"). -include_lib("kernel/include/file.hrl").
read_file(Filepath, DecodeFun) -> read_file(Filepath, DecodeFun) ->

View File

@ -374,4 +374,4 @@ register_gcstat_error(Subject, Error, Stats = #gcstats{errors = Errors}) ->
%% %%
get_segments_root(Storage) -> get_segments_root(Storage) ->
emqx_ft_conf:segments_root(Storage). emqx_ft_storage_fs:get_root(Storage).