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
|
%% 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,
|
%% This file is provided to you under the Apache License,
|
||||||
%% Version 2.0 (the "License"); you may not use this file
|
%% Version 2.0 (the "License"); you may not use this file
|
||||||
|
@ -83,31 +83,11 @@ capabilities(_, _) ->
|
||||||
start(Partition, Config0) ->
|
start(Partition, Config0) ->
|
||||||
%% Get the data root directory
|
%% Get the data root directory
|
||||||
case app_helper:get_prop_or_env(data_root, Config0, wt) of
|
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 ->
|
undefined ->
|
||||||
lager:error("Failed to startup WiredTiger: data_root is not set"),
|
lager:error("Failed to startup WiredTiger: data_root is not set"),
|
||||||
{error, data_root_unset};
|
{error, data_root_unset};
|
||||||
DataRoot ->
|
DataRoot ->
|
||||||
Config = lists:keydelete(data_root, 1, Config0),
|
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 =
|
AppStarted =
|
||||||
case application:start(wt) of
|
case application:start(wt) of
|
||||||
ok ->
|
ok ->
|
||||||
|
@ -120,6 +100,7 @@ start(Partition, Config0) ->
|
||||||
end,
|
end,
|
||||||
case AppStarted of
|
case AppStarted of
|
||||||
ok ->
|
ok ->
|
||||||
|
CacheSize = size_cache(64, Config),
|
||||||
ConnectionOpts =
|
ConnectionOpts =
|
||||||
[Config,
|
[Config,
|
||||||
{create, true},
|
{create, true},
|
||||||
|
@ -475,6 +456,21 @@ fetch_status(Cursor, {ok, Stat}, Acc) ->
|
||||||
[What,Val|_] = [binary_to_list(B) || B <- binary:split(Stat, [<<0>>], [global])],
|
[What,Val|_] = [binary_to_list(B) || B <- binary:split(Stat, [<<0>>], [global])],
|
||||||
fetch_status(Cursor, wt:cursor_next_value(Cursor), [{What,Val}|Acc]).
|
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) ->
|
best_guess_at_a_reasonable_cache_size(ChunkSizeInMB) ->
|
||||||
RunningApps = application:which_applications(),
|
RunningApps = application:which_applications(),
|
||||||
case proplists:is_defined(sasl, RunningApps) andalso
|
case proplists:is_defined(sasl, RunningApps) andalso
|
||||||
|
|
|
@ -272,7 +272,7 @@ empty_check({Backend, State}) ->
|
||||||
}.
|
}.
|
||||||
|
|
||||||
setup({BackendMod, Config}) ->
|
setup({BackendMod, Config}) ->
|
||||||
{ok, S} = BackendMod:start(0, Config),
|
{ok, S} = BackendMod:start(42, Config),
|
||||||
{BackendMod, S}.
|
{BackendMod, S}.
|
||||||
|
|
||||||
cleanup({BackendMod, S}) ->
|
cleanup({BackendMod, S}) ->
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
%%
|
%%
|
||||||
%% wt_conn: manage a connection to WiredTiger
|
%% 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,
|
%% This file is provided to you under the Apache License,
|
||||||
%% Version 2.0 (the "License"); you may not use this file
|
%% Version 2.0 (the "License"); you may not use this file
|
||||||
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
-compile(export_all).
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
|
@ -83,26 +84,7 @@ init([]) ->
|
||||||
{ok, #state{}}.
|
{ok, #state{}}.
|
||||||
|
|
||||||
handle_call({open, Dir, Config, Caller}, _From, #state{conn=undefined}=State) ->
|
handle_call({open, Dir, Config, Caller}, _From, #state{conn=undefined}=State) ->
|
||||||
OptsA =
|
Opts = tailor_config(Config),
|
||||||
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]),
|
|
||||||
{Reply, NState} =
|
{Reply, NState} =
|
||||||
case wt:conn_open(Dir, wt:config_to_bin(Opts)) of
|
case wt:conn_open(Dir, wt:config_to_bin(Opts)) of
|
||||||
{ok, ConnRef}=OK ->
|
{ok, ConnRef}=OK ->
|
||||||
|
@ -192,6 +174,35 @@ do_close(ConnRef) ->
|
||||||
config_value(Key, Config, Default) ->
|
config_value(Key, Config, Default) ->
|
||||||
{Key, app_helper:get_prop_or_env(Key, Config, wt, 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).
|
-ifdef(TEST).
|
||||||
|
|
||||||
|
@ -233,14 +244,14 @@ simple_test_() ->
|
||||||
end}]}.
|
end}]}.
|
||||||
|
|
||||||
open_one() ->
|
open_one() ->
|
||||||
{ok, Ref} = open("test/wt-backend", [{create,true},{session_max, 20}]),
|
{ok, Ref} = open("test/wt-backend", [{create, true},{session_max, 20}]),
|
||||||
true = is_open(),
|
true = is_open(),
|
||||||
close(Ref),
|
close(Ref),
|
||||||
false = is_open(),
|
false = is_open(),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
open_and_wait(Pid) ->
|
open_and_wait(Pid) ->
|
||||||
{ok, Ref} = open("test/wt-backend", [{create,true}]),
|
{ok, Ref} = open("test/wt-backend", [{create, true}]),
|
||||||
Pid ! open,
|
Pid ! open,
|
||||||
receive
|
receive
|
||||||
close ->
|
close ->
|
||||||
|
|
Loading…
Reference in a new issue