refactor(ds): Factor out configuration to a separate module
This commit is contained in:
parent
0bbc5ecb32
commit
120d4e66ae
|
@ -0,0 +1,46 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2023 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
-module(emqx_replay_conf).
|
||||
|
||||
%% TODO: make a proper HOCON schema and all...
|
||||
|
||||
%% API:
|
||||
-export([zone_config/1, db_options/0]).
|
||||
|
||||
%%================================================================================
|
||||
%% API funcions
|
||||
%%================================================================================
|
||||
|
||||
-define(APP, emqx_replay).
|
||||
|
||||
-spec zone_config(emqx_types:zone()) ->
|
||||
{module(), term()}.
|
||||
zone_config(Zone) ->
|
||||
DefaultConf =
|
||||
#{
|
||||
timestamp_bits => 64,
|
||||
topic_bits_per_level => [8, 8, 8, 32, 16],
|
||||
max_tau => 5
|
||||
},
|
||||
DefaultZoneConfig = application:get_env(
|
||||
?APP, default_zone_config, {emqx_replay_message_storage, DefaultConf}
|
||||
),
|
||||
Zones = application:get_env(?APP, zone_config, #{}),
|
||||
maps:get(Zone, Zones, DefaultZoneConfig).
|
||||
|
||||
-spec db_options() -> emqx_replay_local_store:db_options().
|
||||
db_options() ->
|
||||
application:get_env(?APP, db_options, []).
|
|
@ -168,7 +168,7 @@ ensure_current_generation(S = #s{zone = Zone, db = DBHandle, column_families = C
|
|||
create_new_generation_schema(
|
||||
GenId, S = #s{zone = Zone, db = DBHandle, column_families = CFs}
|
||||
) ->
|
||||
{Module, Options} = new_generation_config(Zone),
|
||||
{Module, Options} = emqx_replay_conf:zone_config(Zone),
|
||||
{NewGenData, NewCFs} = Module:create_new(DBHandle, GenId, Options),
|
||||
NewGen = #generation{
|
||||
module = Module,
|
||||
|
@ -178,23 +178,10 @@ create_new_generation_schema(
|
|||
ok = schema_put_gen(DBHandle, GenId, NewGen),
|
||||
S#s{column_families = NewCFs ++ CFs}.
|
||||
|
||||
-spec new_generation_config(emqx_types:zone()) ->
|
||||
{module(), term()}.
|
||||
new_generation_config(Zone) ->
|
||||
%% TODO: make a proper HOCON schema and all...
|
||||
Zones = application:get_env(emqx_replay, zone_config, #{}),
|
||||
DefaultConf =
|
||||
#{
|
||||
timestamp_bits => 64,
|
||||
topic_bits_per_level => [8, 8, 8, 32, 16],
|
||||
max_tau => 5
|
||||
},
|
||||
maps:get(Zone, Zones, {emqx_replay_message_storage, DefaultConf}).
|
||||
|
||||
-spec open_db(emqx_types:zone()) -> {ok, rocksdb:db_handle(), cf_refs()} | {error, _TODO}.
|
||||
open_db(Zone) ->
|
||||
Filename = atom_to_list(Zone),
|
||||
DBOptions = application:get_env(emqx_replay, db_options, []),
|
||||
DBOptions = emqx_replay_conf:db_options(),
|
||||
ColumnFamiles =
|
||||
case rocksdb:list_column_families(Filename, DBOptions) of
|
||||
{ok, ColumnFamiles0} ->
|
||||
|
|
Loading…
Reference in New Issue