You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2008/06/05 22:27:04 UTC
svn commit: r663724 - in /incubator/couchdb/branches/runtimeconfig:
etc/couchdb/ src/couchdb/ src/couchdb/test/
Author: jan
Date: Thu Jun 5 13:27:04 2008
New Revision: 663724
URL: http://svn.apache.org/viewvc?rev=663724&view=rev
Log:
clean up of code
have modules register for config value changes with a callback function
add basic test suite
Added:
incubator/couchdb/branches/runtimeconfig/src/couchdb/test/
incubator/couchdb/branches/runtimeconfig/src/couchdb/test/couch_config_test.erl
Modified:
incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch.ini.tpl.in
incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl
incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl
incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl
incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl
incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl
incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl
incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_view.erl
Modified: incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch.ini.tpl.in
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch.ini.tpl.in?rev=663724&r1=663723&r2=663724&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch.ini.tpl.in (original)
+++ incubator/couchdb/branches/runtimeconfig/etc/couchdb/couch.ini.tpl.in Thu Jun 5 13:27:04 2008
@@ -3,6 +3,7 @@
[CouchDB]
RootDirectory=%pkgstatelibdir%
UtilDriverDir=%couchprivlibdir%
+MaximumDocumentSize=4294967296 ; 4 GB
[HTTPd]
Port=5984
@@ -15,3 +16,6 @@
[CouchDB Query Servers]
javascript=%bindir%/%couchjs_command_name% %pkgdatadir%/server/main.js
+
+[CouchDB Query Server Options]
+QueryTimeout=5000 ; 5 seconds
\ No newline at end of file
Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl?rev=663724&r1=663723&r2=663724&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl Thu Jun 5 13:27:04 2008
@@ -19,9 +19,12 @@
-export([start_link/0, init/1, stop/0,
handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
--export([store/2, register/2, lookup_and_register/2,
- lookup/1, lookup/2, lookup_match/1, lookup_match/2, dump/0,
- init_value/2, unset/1, load_ini_file/1,
+-export([store/2, register/2,
+ lookup/1, lookup/2,
+ lookup_match/1, lookup_match/2,
+ lookup_and_register/2, lookup_and_register/3,
+ lookup_match_and_register/2, lookup_match_and_register/3,
+ dump/0, init_value/2, unset/1, load_ini_file/1,
load_ini_files/1]).
start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
@@ -31,11 +34,26 @@
init_value(Key, Value) -> gen_server:call(?MODULE, {init_value, Key, Value}).
store(Key, Value) -> gen_server:call(?MODULE, {store, [{Key, Value}]}).
+
lookup(Key) -> gen_server:call(?MODULE, {lookup, Key}).
lookup(Key, Default) -> gen_server:call(?MODULE, {lookup, Key, Default}).
-lookup_and_register(Key, CallbackFunction) -> gen_server:call(?MODULE, {lookup_and_register, Key, CallbackFunction}).
+
+lookup_and_register(Key, CallbackFunction) ->
+ gen_server:call(?MODULE, {lookup_and_register, Key, CallbackFunction}).
+
+lookup_and_register(Key, Default, CallbackFunction) ->
+ gen_server:call(?MODULE, {lookup_and_register, Key, Default, CallbackFunction}).
+
lookup_match(Key) -> gen_server:call(?MODULE, {lookup_match, Key}).
+
lookup_match(Key, Default) -> gen_server:call(?MODULE, {lookup_match, Key, Default}).
+
+lookup_match_and_register(Key, CallbackFunction) ->
+ gen_server:call(?MODULE, {lookup_match_and_register, Key, CallbackFunction}).
+
+lookup_match_and_register(Key, Default, CallbackFunction) ->
+ gen_server:call(?MODULE, {lookup_match_and_register, Key, Default, CallbackFunction}).
+
dump() -> gen_server:call(?MODULE, {dump, []}).
register(Key, Fun) -> gen_server:call(?MODULE, {register, Key, Fun}).
@@ -66,6 +84,10 @@
handle_call({lookup_and_register, Key, CallbackFunction}, _From, Tab) ->
?MODULE:handle_call({register, Key, CallbackFunction}, _From, Tab),
lookup(Key, fun(Tab_, Key_) -> ets:lookup(Tab_, Key_) end, null, Tab);
+
+handle_call({lookup_and_register, Key, Default, CallbackFunction}, _From, Tab) ->
+ ?MODULE:handle_call({register, Key, CallbackFunction}, _From, Tab),
+ lookup(Key, fun(Tab_, Key_) -> ets:lookup(Tab_, Key_) end, Default, Tab);
handle_call({lookup_match, Key}, _From, Tab) ->
lookup(Key, fun(Tab_, Key_) -> ets:match(Tab_, Key_) end, null, Tab);
@@ -73,31 +95,46 @@
handle_call({lookup_match, Key, Default}, _From, Tab) ->
lookup(Key, fun(Tab_, Key_) -> ets:match(Tab_, Key_) end, Default, Tab);
+handle_call({lookup_match_and_register, Key = {{Module, '$1'}, '$2'}, CallbackFunction}, _From, Tab) ->
+ ?MODULE:handle_call({register, {Module, ""}, CallbackFunction}, _From, Tab),
+ lookup(Key, fun(Tab_, Key_) -> ets:match(Tab_, Key_) end, null, Tab);
+
+handle_call({lookup_match_and_register, Key = {{Module, '$1'}, '$2'}, Default, CallbackFunction}, _From, Tab) ->
+ ?MODULE:handle_call({register, {Module, ""}, CallbackFunction}, _From, Tab),
+ lookup(Key, fun(Tab_, Key_) -> ets:match(Tab_, Key_) end, Default, Tab);
+
handle_call({dump, []}, _From, Tab) ->
io:format("~p~n", [ets:match(Tab, '$1')]),
{reply, ok, Tab};
handle_call({register, Key, Fun}, From, Tab) ->
- io:format("registered for '~p' '", [Key]),
+ % io:format("registered for '~p' '", [Key]),
ets:insert(Tab, {{"_CouchDB", Key}, {From, Fun}}),
{reply, ok, Tab}.
notify_registered_modules(Tab, {{Module, Variable}, _Value}) ->
- % ModuleName = atom_to_list(Module),
- % VariableName = atom_to_list(Variable),
- Look = ets:lookup(Tab, {"_CouchDB", {Module, Variable}}),
- io:format("looked for '~p' and got '~p'~n", [{Module, Variable}, Look]),
-
- case Look of
+ % look for processes that registered for notifications for
+ % specific configuration variables
+ case ets:lookup(Tab, {"_CouchDB", {Module, Variable}}) of
% found
[{{"_CouchDB", {Module, Variable}}, {_From, Fun}}] ->
- io:format("got it '~p'~n", [ets:lookup(Tab, {Module, Variable})]),
+ % io:format("got it '~p'~n", [ets:lookup(Tab, {Module, Variable})]),
Fun();
_ -> % not found
- io:format("not it~n", []),
+ % io:format("not it~n", []),
+ ok
+ end,
+
+ % look for processes that registerd for notifications for
+ % entire modules. Their "Variable" value will be the empty string
+ case ets:lookup(Tab, {"_CouchDB", {Module, ""}}) of
+ % found
+ [{{"_CouchDB", {Module, _Variable}}, {_From2, Fun2}}] ->
+ Fun2();
+ _ -> % not found
ok
end.
-
+
lookup(Key, Fun, Default, Tab) ->
Reply = case Fun(Tab, Key) of
@@ -112,15 +149,15 @@
insert_and_commit(Tab, Config) ->
ets:insert(Tab, Config),
- {Key, _Value} = Config,
- io:format("just inserted '~p' and now it is '~p~n", [Config, ets:lookup(Tab, Key)]),
+ % {Key, _Value} = Config,
+ % io:format("just inserted '~p' and now it is '~p~n", [Config, ets:lookup(Tab, Key)]),
{reply, File, _Tab} =
lookup({"_CouchDB", "ConfigurationStorageFile"},
fun(Tab_, Key_) -> ets:lookup(Tab_, Key_) end,
null, Tab
),
- io:format("got it '~p' but stored '~p'~n", [ets:lookup(Tab, {"HTTPd", "Port"}), Config]),
+ % io:format("got it '~p' but stored '~p'~n", [ets:lookup(Tab, {"HTTPd", "Port"}), Config]),
notify_registered_modules(Tab, Config),
commit(Config, File).
Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl?rev=663724&r1=663723&r2=663724&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl Thu Jun 5 13:27:04 2008
@@ -35,8 +35,16 @@
start_link() ->
- Filename = couch_config:lookup({"Log", "File"}),
- Level = couch_config:lookup({"Log", "Level"}),
+ % read config and register for configuration changes
+
+ % just stop if one of the config settings change. couch_server_sup
+ % will restart us and then we will pick up the new settings.
+ ConfigChangeCallbackFunction = fun() -> ?MODULE:stop() end,
+ Filename = couch_config:lookup_and_register(
+ {"Log", "File"}, ConfigChangeCallbackFunction),
+ Level = couch_config:lookup_and_register(
+ {"Log", "Level"}, ConfigChangeCallbackFunction),
+
couch_event_sup:start_link({local, couch_log}, error_logger, couch_log, {Filename, Level}).
stop() ->
Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl?rev=663724&r1=663723&r2=663724&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl Thu Jun 5 13:27:04 2008
@@ -23,11 +23,22 @@
-include("couch_db.hrl").
timeout() ->
- % hardcoded 5 sec timeout per document
- 5000.
+ list_to_integer(couch_config:lookup({"CouchDB Query Server Options", "QueryTimeout"})).
start_link() ->
- QueryServerList = couch_config:lookup_match({{"CouchDB Query Servers", '$1'}, '$2'}, []),
+ % read config and register for configuration changes
+
+ % just stop if one of the config settings change. couch_server_sup
+ % will restart us and then we will pick up the new settings.
+ ConfigChangeCallbackFunction = fun() -> ?MODULE:stop() end,
+
+ QueryServerList = couch_config:lookup_match_and_register(
+ {{"CouchDB Query Servers", '$1'}, '$2'}, [],
+ ConfigChangeCallbackFunction),
+ couch_config:register(
+ {"CouchDB Query Server Options", "QueryTimeout"},
+ ConfigChangeCallbackFunction),
+
gen_server:start_link({local, couch_query_servers}, couch_query_servers, QueryServerList, []).
stop() ->
Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl?rev=663724&r1=663723&r2=663724&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl Thu Jun 5 13:27:04 2008
@@ -62,8 +62,17 @@
end.
sup_start_link() ->
- RootDir = couch_config:lookup({"CouchDB", "RootDirectory"}),
- Options = couch_config:lookup({"CouchDB", "ServerOptions"}),
+ % read config and register for configuration changes
+
+ % just stop if one of the config settings change. couch_server_sup
+ % will restart us and then we will pick up the new settings.
+ ConfigChangeCallbackFunction = fun() -> ?MODULE:stop() end,
+
+ RootDir = couch_config:lookup_and_register(
+ {"CouchDB", "RootDirectory"}, ConfigChangeCallbackFunction),
+ Options = couch_config:lookup_and_register(
+ {"CouchDB", "ServerOptions"}, ConfigChangeCallbackFunction),
+
gen_server:start_link({local, couch_server}, couch_server, {RootDir, Options}, []).
open(Filename) ->
Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl?rev=663724&r1=663723&r2=663724&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl Thu Jun 5 13:27:04 2008
@@ -41,8 +41,19 @@
_ -> ok
end,
+ % read config and register for configuration changes
+
+ % just stop if one of the config settings change. couch_server_sup
+ % will restart us and then we will pick up the new settings.
+ ConfigChangeCallbackFunction = fun() -> ?MODULE:stop() end,
UpdateNotificationProcesses = couch_config:lookup({"CouchDB", "UpdateNotificationProcesses"}, []),
- FtSearchQueryServer = couch_config:lookup({"Fulltext", "QueryServer"}, []),
+ FtSearchQueryServer = couch_config:lookup({"Search", "QueryServer"}, []),
+
+ couch_config:register(
+ {"CouchDB", "UpdateNotificationProcesses"}, ConfigChangeCallbackFunction),
+ couch_config:register(
+ {"Search", "QueryServer"}, ConfigChangeCallbackFunction),
+
ChildProcesses =
[{couch_log,
{couch_log, start_link, []},
Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl?rev=663724&r1=663723&r2=663724&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl Thu Jun 5 13:27:04 2008
@@ -23,7 +23,14 @@
-define(FLUSH_MAX_MEM, 10000000).
start_driver() ->
- LibDir1 = couch_config:lookup({"CouchDB", "UtilDriverDir"}),
+ % read config and register for configuration changes
+
+ % just stop if one of the config settings change. couch_server_sup
+ % will restart us and then we will pick up the new settings.
+ ConfigChangeCallbackFunction = fun() -> couch_server:stop(couch_config_change) end,
+
+ LibDir1 = couch_config:lookup_and_register(
+ {"CouchDB", "UtilDriverDir"}, ConfigChangeCallbackFunction),
case LibDir1 of
null ->
LibDir = filename:join(code:priv_dir(couch), "lib");
Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_view.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_view.erl?rev=663724&r1=663723&r2=663724&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_view.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_view.erl Thu Jun 5 13:27:04 2008
@@ -16,7 +16,7 @@
-behaviour(gen_server).
-export([start_link/0,fold/4,fold/5,less_json/2, start_update_loop/3, start_temp_update_loop/5]).
--export([init/1,terminate/2,handle_call/3,handle_cast/2,handle_info/2,code_change/3]).
+-export([init/1,terminate/1,terminate/2,handle_call/3,handle_cast/2,handle_info/2,code_change/3]).
-export([get_reduce_view/1, get_map_view/1,get_row_count/1,reduce_to_count/1, fold_reduce/7]).
-include("couch_db.hrl").
@@ -46,11 +46,13 @@
}).
start_link() ->
- RootDir = couch_config:lookup({"CouchDB", "RootDirectory"}),
+
+ % read configuration settings and register for configuration changes
+ RootDir = couch_config:lookup_and_register(
+ {"CouchDB", "RootDirectory"}, fun() -> terminate(config_change) end),
+
gen_server:start_link({local, couch_view}, couch_view, RootDir, []).
-
-
get_temp_updater(DbName, Type, MapSrc, RedSrc) ->
{ok, Pid} = gen_server:call(couch_view, {start_temp_updater, DbName, Type, MapSrc, RedSrc}),
Pid.
@@ -217,7 +219,10 @@
process_flag(trap_exit, true),
{ok, #server{root_dir=RootDir}}.
-terminate(_Reason, _) ->
+terminate(Reason, _) ->
+ terminate(Reason).
+
+terminate(_Reason) ->
catch ets:delete(couch_views_by_name),
catch ets:delete(couch_views_by_updater),
catch ets:delete(couch_views_by_db),
Added: incubator/couchdb/branches/runtimeconfig/src/couchdb/test/couch_config_test.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/test/couch_config_test.erl?rev=663724&view=auto
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/test/couch_config_test.erl (added)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/test/couch_config_test.erl Thu Jun 5 13:27:04 2008
@@ -0,0 +1,40 @@
+% couch_config module test suote
+
+% Set up test suite
+% ?MODULE_test() returns a list of functions
+% that run the actual tests.
+couch_config_test() ->
+ [
+ fun() -> store_tuples() end,
+ fun() -> store_strings() end,
+ fun() -> store_numbers() end,
+ fun() -> store_tuple_key() end
+ ].
+
+
+% test functions
+
+% test storing different types and see if they come back
+% the same way there put in.
+store_tuples() ->
+ basic_store(key, value).
+
+store_strings() ->
+ basic_store("key", "value").
+
+store_numbers() ->
+ basic_store("number_key", 12345).
+
+store_tuple_key() ->
+ basic_store({key, subkey}, value).
+
+
+basic_store(Key, Value) ->
+ couch_config:start_link(),
+
+ couch_config:init_value(Key, Value),
+ Result = couch_config:lookup(Key),
+ couch_config:unset(Key),
+
+ couch_config:stop(),
+ Value = Result.
\ No newline at end of file