Restructure the way we create/merge default configuration setttings
with user supplied settings. Move cache estimate to its own function.
This commit is contained in:
parent
e6dc7a5936
commit
0ec817ae9f
3 changed files with 53 additions and 46 deletions
|
@ -2,7 +2,7 @@
|
|||
%%
|
||||
%% riak_kv_wiredtiger_backend: Use WiredTiger for Riak/KV storage
|
||||
%%
|
||||
%% Copyright (c) 2012-2013 Basho Technologies, Inc. All Rights Reserved.
|
||||
%% Copyright (c) 2012 Basho Technologies, Inc. All Rights Reserved.
|
||||
%%
|
||||
%% This file is provided to you under the Apache License,
|
||||
%% Version 2.0 (the "License"); you may not use this file
|
||||
|
@ -83,31 +83,11 @@ capabilities(_, _) ->
|
|||
start(Partition, Config0) ->
|
||||
%% Get the data root directory
|
||||
case app_helper:get_prop_or_env(data_root, Config0, wt) of
|
||||
<<"">> ->
|
||||
lager:error("Failed to startup WiredTiger: data_root is not valid"),
|
||||
{error, data_root_unset};
|
||||
[] ->
|
||||
lager:error("Failed to startup WiredTiger: data_root is empty"),
|
||||
{error, data_root_unset};
|
||||
undefined ->
|
||||
lager:error("Failed to startup WiredTiger: data_root is not set"),
|
||||
{error, data_root_unset};
|
||||
DataRoot ->
|
||||
Config = lists:keydelete(data_root, 1, Config0),
|
||||
CacheSize =
|
||||
case proplists:get_value(cache_size, Config) of
|
||||
undefined ->
|
||||
case application:get_env(wt, cache_size) of
|
||||
{ok, Value} ->
|
||||
Value;
|
||||
_ ->
|
||||
SizeEst = best_guess_at_a_reasonable_cache_size(64),
|
||||
%% lager:warning("Using estimated best cache size of ~p for WiredTiger backend.", [SizeEst]),
|
||||
SizeEst
|
||||
end;
|
||||
Value ->
|
||||
Value
|
||||
end,
|
||||
AppStarted =
|
||||
case application:start(wt) of
|
||||
ok ->
|
||||
|
@ -120,6 +100,7 @@ start(Partition, Config0) ->
|
|||
end,
|
||||
case AppStarted of
|
||||
ok ->
|
||||
CacheSize = size_cache(64, Config),
|
||||
ConnectionOpts =
|
||||
[Config,
|
||||
{create, true},
|
||||
|
@ -475,6 +456,21 @@ fetch_status(Cursor, {ok, Stat}, Acc) ->
|
|||
[What,Val|_] = [binary_to_list(B) || B <- binary:split(Stat, [<<0>>], [global])],
|
||||
fetch_status(Cursor, wt:cursor_next_value(Cursor), [{What,Val}|Acc]).
|
||||
|
||||
size_cache(ChunkSize, Config) ->
|
||||
case proplists:get_value(cache_size, Config) of
|
||||
undefined ->
|
||||
case application:get_env(wt, cache_size) of
|
||||
{ok, Value} ->
|
||||
Value;
|
||||
_ ->
|
||||
SizeEst = best_guess_at_a_reasonable_cache_size(ChunkSize),
|
||||
%% lager:warning("Using estimated best cache size of ~p for WiredTiger backend.", [SizeEst]),
|
||||
SizeEst
|
||||
end;
|
||||
Value ->
|
||||
Value
|
||||
end.
|
||||
|
||||
best_guess_at_a_reasonable_cache_size(ChunkSizeInMB) ->
|
||||
RunningApps = application:which_applications(),
|
||||
case proplists:is_defined(sasl, RunningApps) andalso
|
||||
|
|
|
@ -272,7 +272,7 @@ empty_check({Backend, State}) ->
|
|||
}.
|
||||
|
||||
setup({BackendMod, Config}) ->
|
||||
{ok, S} = BackendMod:start(0, Config),
|
||||
{ok, S} = BackendMod:start(42, Config),
|
||||
{BackendMod, S}.
|
||||
|
||||
cleanup({BackendMod, S}) ->
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
%%
|
||||
%% wt_conn: manage a connection to WiredTiger
|
||||
%%
|
||||
%% Copyright (c) 2012-2013 Basho Technologies, Inc. All Rights Reserved.
|
||||
%% Copyright (c) 2012 Basho Technologies, Inc. All Rights Reserved.
|
||||
%%
|
||||
%% This file is provided to you under the Apache License,
|
||||
%% Version 2.0 (the "License"); you may not use this file
|
||||
|
@ -26,6 +26,7 @@
|
|||
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-compile(export_all).
|
||||
-endif.
|
||||
|
||||
%% API
|
||||
|
@ -83,26 +84,7 @@ init([]) ->
|
|||
{ok, #state{}}.
|
||||
|
||||
handle_call({open, Dir, Config, Caller}, _From, #state{conn=undefined}=State) ->
|
||||
OptsA =
|
||||
case proplists:get_bool(create, Config) of
|
||||
false -> [{create, false}];
|
||||
_ -> [{create, true}]
|
||||
end,
|
||||
OptsB =
|
||||
case proplists:is_defined(shared_cache, Config) of
|
||||
true ->
|
||||
[];
|
||||
false ->
|
||||
[config_value(cache_size, Config, "512MB")]
|
||||
end,
|
||||
OptsC =
|
||||
case proplists:is_defined(session_max, Config) of
|
||||
true ->
|
||||
[];
|
||||
false ->
|
||||
[config_value(session_max, Config, 100)]
|
||||
end,
|
||||
Opts = lists:merge([OptsA, OptsB, OptsC, Config]),
|
||||
Opts = tailor_config(Config),
|
||||
{Reply, NState} =
|
||||
case wt:conn_open(Dir, wt:config_to_bin(Opts)) of
|
||||
{ok, ConnRef}=OK ->
|
||||
|
@ -192,6 +174,35 @@ do_close(ConnRef) ->
|
|||
config_value(Key, Config, Default) ->
|
||||
{Key, app_helper:get_prop_or_env(Key, Config, wt, Default)}.
|
||||
|
||||
%% @private
|
||||
map_cfg([], Acc) ->
|
||||
Acc;
|
||||
map_cfg([Fun|T], Acc) ->
|
||||
map_cfg(T, Fun(Acc)).
|
||||
|
||||
tailor_config(Config) ->
|
||||
map_cfg([fun (Acc) ->
|
||||
case proplists:is_defined(create, Acc) of
|
||||
false -> [{create, true} | Acc];
|
||||
true -> Acc
|
||||
end
|
||||
end,
|
||||
fun (Acc) ->
|
||||
case proplists:is_defined(shared_cache, Acc) of
|
||||
false ->
|
||||
[config_value(cache_size, Acc, "512MB") | Acc];
|
||||
true ->
|
||||
Acc
|
||||
end
|
||||
end,
|
||||
fun (Acc) ->
|
||||
case proplists:is_defined(session_max, Acc) of
|
||||
false ->
|
||||
[config_value(session_max, Acc, 100) | Acc];
|
||||
true ->
|
||||
Acc
|
||||
end
|
||||
end], Config).
|
||||
|
||||
-ifdef(TEST).
|
||||
|
||||
|
|
Loading…
Reference in a new issue