Pass config into connection:open() rather than ignoring it and do a

better job of integrating config options from the app environment as
well as config file while we're at it.
This commit is contained in:
Gregory Burd 2013-03-18 15:32:03 -04:00
parent 24527cf453
commit 39fb4ff710
3 changed files with 22 additions and 28 deletions

View file

@ -80,7 +80,6 @@ capabilities(_, _) ->
%% @doc Start the wterl backend
-spec start(integer(), config()) -> {ok, state()} | {error, term()}.
start(Partition, Config) ->
Table = "lsm:wt" ++ integer_to_list(Partition),
AppStart =
case application:start(wterl) of
ok ->
@ -93,6 +92,7 @@ start(Partition, Config) ->
end,
case AppStart of
ok ->
Table = "lsm:wt" ++ integer_to_list(Partition),
establish_connection(Table, Config);
{error, Reason2} ->
{error, Reason2}
@ -324,6 +324,7 @@ callback(_Ref, _Msg, State) ->
%% Internal functions
%% ===================================================================
%% @private
establish_connection(Table, Config) ->
%% Get the data root directory
case app_helper:get_prop_or_env(data_root, Config, wterl) of
@ -338,17 +339,18 @@ establish_connection(Table, Config) ->
RingSize when RingSize < 512 -> 1024;
RingSize -> RingSize * 2
end,
case wterl_conn:open(DataRoot,
[Config,
{create, true},
{sync, false},
{logging, true},
{transactional, true},
{session_max, SessionMax},
{cache_size, size_cache(Config)},
{checkpoint, [{wait, 1}]}, % sec
{statistics_log, [{wait, 30}]} % sec
]) of
Opts = orddict:from_list(
[ wterl:config_value(create, Config, true),
wterl:config_value(sync, Config, false),
wterl:config_value(logging, Config, true),
wterl:config_value(transactional, Config, true),
wterl:config_value(session_max, Config, SessionMax),
wterl:config_value(cache_size, Config, size_cache(Config)),
wterl:config_value(checkpoint, Config, [{wait, 1}]), % sec
wterl:config_value(statistics_log, Config, [{wait, 30}])]
++ proplists:get_value(wterl, Config, [])), % sec
%% lager:info("WiredTiger connection:open(~s, ~s)", [DataRoot, wterl:config_to_bin(Opts)]),
case wterl_conn:open(DataRoot, Opts) of
{ok, Connection} ->
{ok, #state{table=Table, connection=Connection}};
{error, Reason2} ->
@ -357,6 +359,7 @@ establish_connection(Table, Config) ->
end
end.
%% @private
establish_session(#state{table=Table, session=undefined}=State) ->
{ok, Connection} = wterl_conn:get(),
case wterl:session_open(Connection, wterl:config_to_bin([{isolation, "snapshot"}])) of

View file

@ -272,9 +272,9 @@ fold(Cursor, Fun, Acc, {ok, Key, Value}) ->
config_types() ->
[{block_compressor, string},
{cache_size, string},
{checkpoint, map},
{checkpoint, config},
{create, bool},
{direct_io, map},
{direct_io, list},
{drop, list},
{error_prefix, string},
{eviction_target, integer},
@ -294,11 +294,11 @@ config_types() ->
{multiprocess, bool},
{name, string},
{session_max, integer},
{statistics_log, map},
{statistics_log, config},
{sync, bool},
{target, list},
{transactional, bool},
{verbose, map},
{verbose, list},
{wait, integer}].
config_value(Key, Config, Default) ->
@ -315,8 +315,6 @@ config_encode(config, Value) ->
list_to_binary(["(", config_to_bin(Value, []), ")"]);
config_encode(list, Value) ->
list_to_binary(["(", string:join(Value, ","), ")"]);
config_encode(map, Value) ->
list_to_binary(["[", string:join(Value, ","), "]"]);
config_encode(string, Value) ->
list_to_binary(Value);
config_encode(bool, true) ->

View file

@ -81,10 +81,7 @@ init([]) ->
{ok, #state{}}.
handle_call({open, Dir, Config, Caller}, _From, #state{conn=undefined}=State) ->
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(Config)) of
{ok, ConnRef}=OK ->
Monitor = erlang:monitor(process, Caller),
true = ets:insert(wterl_ets, {Monitor, Caller}),
@ -168,10 +165,6 @@ do_close(undefined) ->
do_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).
@ -213,14 +206,14 @@ simple_test_() ->
end}]}.
open_one() ->
{ok, Ref} = open("test/wterl-backend", [{session_max, 20},{cache_size, "1MB"}]),
{ok, Ref} = open("test/wterl-backend", [{create, true}, {session_max, 20},{cache_size, "1MB"}]),
true = is_open(),
close(Ref),
false = is_open(),
ok.
open_and_wait(Pid) ->
{ok, Ref} = open("test/wterl-backend"),
{ok, Ref} = open("test/wterl-backend", [{create, true}]),
Pid ! open,
receive
close ->