allow WiredTiger config to be set in application env
WiredTiger connection options can be set in the wterl application environment. If not set, appropriate defaults are used instead.
This commit is contained in:
parent
509cc92cfc
commit
793c5c7338
2 changed files with 20 additions and 7 deletions
|
@ -99,7 +99,7 @@ start(Partition, Config) ->
|
||||||
case AppStart of
|
case AppStart of
|
||||||
ok ->
|
ok ->
|
||||||
ok = filelib:ensure_dir(filename:join(DataRoot, "x")),
|
ok = filelib:ensure_dir(filename:join(DataRoot, "x")),
|
||||||
case wterl_conn:open(DataRoot) of
|
case wterl_conn:open(DataRoot, Config) of
|
||||||
{ok, ConnRef} ->
|
{ok, ConnRef} ->
|
||||||
Table = "table:wt" ++ integer_to_list(Partition),
|
Table = "table:wt" ++ integer_to_list(Partition),
|
||||||
{ok, SRef} = wterl:session_open(ConnRef),
|
{ok, SRef} = wterl:session_open(ConnRef),
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/0, stop/0,
|
-export([start_link/0, stop/0,
|
||||||
open/1, is_open/0, get/0, close/1]).
|
open/1, open/2, is_open/0, get/0, close/1]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
|
@ -40,6 +40,8 @@
|
||||||
conn :: wterl:connection()
|
conn :: wterl:connection()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
-type config_list() :: [{atom(), any()}].
|
||||||
|
|
||||||
%% ====================================================================
|
%% ====================================================================
|
||||||
%% API
|
%% API
|
||||||
%% ====================================================================
|
%% ====================================================================
|
||||||
|
@ -54,7 +56,11 @@ stop() ->
|
||||||
|
|
||||||
-spec open(string()) -> {ok, wterl:connection()} | {error, term()}.
|
-spec open(string()) -> {ok, wterl:connection()} | {error, term()}.
|
||||||
open(Dir) ->
|
open(Dir) ->
|
||||||
gen_server:call(?MODULE, {open, Dir, self()}, infinity).
|
open(Dir, []).
|
||||||
|
|
||||||
|
-spec open(string(), config_list()) -> {ok, wterl:connection()} | {error, term()}.
|
||||||
|
open(Dir, Config) ->
|
||||||
|
gen_server:call(?MODULE, {open, Dir, Config, self()}, infinity).
|
||||||
|
|
||||||
-spec is_open() -> boolean().
|
-spec is_open() -> boolean().
|
||||||
is_open() ->
|
is_open() ->
|
||||||
|
@ -76,8 +82,10 @@ init([]) ->
|
||||||
true = wterl_ets:table_ready(),
|
true = wterl_ets:table_ready(),
|
||||||
{ok, #state{}}.
|
{ok, #state{}}.
|
||||||
|
|
||||||
handle_call({open, Dir, Caller}, _From, #state{conn=undefined}=State) ->
|
handle_call({open, Dir, Config, Caller}, _From, #state{conn=undefined}=State) ->
|
||||||
Opts = [{create, true}, {cache_size, "100MB"}, {session_max, 100}],
|
Opts = [{create, true},
|
||||||
|
config_value(cache_size, Config, "100MB"),
|
||||||
|
config_value(session_max, Config, 100)],
|
||||||
{Reply, NState} = case wterl:conn_open(Dir, wterl:config_to_bin(Opts)) of
|
{Reply, NState} = case wterl:conn_open(Dir, wterl:config_to_bin(Opts)) of
|
||||||
{ok, ConnRef}=OK ->
|
{ok, ConnRef}=OK ->
|
||||||
Monitor = erlang:monitor(process, Caller),
|
Monitor = erlang:monitor(process, Caller),
|
||||||
|
@ -87,7 +95,7 @@ handle_call({open, Dir, Caller}, _From, #state{conn=undefined}=State) ->
|
||||||
{Error, State}
|
{Error, State}
|
||||||
end,
|
end,
|
||||||
{reply, Reply, NState};
|
{reply, Reply, NState};
|
||||||
handle_call({open, _Dir, Caller}, _From,#state{conn=ConnRef}=State) ->
|
handle_call({open, _Dir, _Config, Caller}, _From,#state{conn=ConnRef}=State) ->
|
||||||
Monitor = erlang:monitor(process, Caller),
|
Monitor = erlang:monitor(process, Caller),
|
||||||
true = ets:insert(wterl_ets, {Monitor, Caller}),
|
true = ets:insert(wterl_ets, {Monitor, Caller}),
|
||||||
{reply, {ok, ConnRef}, State};
|
{reply, {ok, ConnRef}, State};
|
||||||
|
@ -156,11 +164,16 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%% ====================================================================
|
%% ====================================================================
|
||||||
|
|
||||||
|
%% @private
|
||||||
do_close(undefined) ->
|
do_close(undefined) ->
|
||||||
ok;
|
ok;
|
||||||
do_close(ConnRef) ->
|
do_close(ConnRef) ->
|
||||||
wterl:conn_close(ConnRef).
|
wterl:conn_close(ConnRef).
|
||||||
|
|
||||||
|
%% @private
|
||||||
|
config_value(Key, Config, Default) ->
|
||||||
|
{Key, app_helper:get_prop_or_env(Key, Config, wterl, Default)}.
|
||||||
|
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
|
|
||||||
|
@ -202,7 +215,7 @@ simple_test_() ->
|
||||||
end}]}.
|
end}]}.
|
||||||
|
|
||||||
open_one() ->
|
open_one() ->
|
||||||
{ok, Ref} = open("test/wterl-backend"),
|
{ok, Ref} = open("test/wterl-backend", [{session_max, 20},{cache_size, "1MB"}]),
|
||||||
true = is_open(),
|
true = is_open(),
|
||||||
close(Ref),
|
close(Ref),
|
||||||
false = is_open(),
|
false = is_open(),
|
||||||
|
|
Loading…
Reference in a new issue