couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r663113 - in /incubator/couchdb/branches/runtimeconfig: etc/Makefile.am etc/couchdb/Makefile.am src/couchdb/couch_config.erl src/couchdb/couch_config_writer.erl src/couchdb/couch_httpd.erl src/couchdb/couch_server.erl
Date Wed, 04 Jun 2008 14:18:16 GMT
Author: jan
Date: Wed Jun  4 07:18:16 2008
New Revision: 663113

URL: http://svn.apache.org/viewvc?rev=663113&view=rev
Log:
The runtimeconfig branch is now equipped with everything that it needs to be merged back,
it just needs a bit of a clean-up. I'm committing this as an intermediate stage.

Modified:
    incubator/couchdb/branches/runtimeconfig/etc/Makefile.am
    incubator/couchdb/branches/runtimeconfig/etc/couchdb/Makefile.am
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config_writer.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl

Modified: incubator/couchdb/branches/runtimeconfig/etc/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/etc/Makefile.am?rev=663113&r1=663112&r2=663113&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/etc/Makefile.am (original)
+++ incubator/couchdb/branches/runtimeconfig/etc/Makefile.am Wed Jun  4 07:18:16 2008
@@ -46,7 +46,7 @@
 	        mkdir default; \
 	    fi \
 	fi
-	sed -r -e "s|%configure_input%|$@. Generated from $< by configure.|" \
+	sed -E -e "s|%configure_input%|$@. Generated from $< by configure.|" \
 	       -e "s|%pkgconfdir%|$(abs_pkgconfdir)|g" \
 	       -e "s|%sysconfdir%|$(abs_sysconfdir)|" \
 	       -e "s|%localstatedir%|$(abs_localstatedir)|" \
@@ -60,7 +60,7 @@
 	        mkdir init; \
 	    fi \
 	fi
-	sed -r -e "s|%configure_input%|$@. Generated from $< by configure.|" \
+	sed -E -e "s|%configure_input%|$@. Generated from $< by configure.|" \
 	       -e "s|%bindir%|$(abs_bindir)|" \
 	       -e "s|%sysconfdir%|$(abs_sysconfdir)|" \
 	       -e "s|%erlangbindir%|$(abs_erlangbindir)|" \
@@ -78,7 +78,7 @@
 	        mkdir launchd; \
 	    fi \
 	fi
-	sed -r -e "s|%configure_input%|$@. Generated from $< by configure.|" \
+	sed -E -e "s|%configure_input%|$@. Generated from $< by configure.|" \
 	       -e "s|%bindir%|$(abs_bindir)|" \
 	       -e "s|%couchdb_command_name%|$(couchdb_command_name)|" \
 	< $< > $@

Modified: incubator/couchdb/branches/runtimeconfig/etc/couchdb/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/etc/couchdb/Makefile.am?rev=663113&r1=663112&r2=663113&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/etc/couchdb/Makefile.am (original)
+++ incubator/couchdb/branches/runtimeconfig/etc/couchdb/Makefile.am Wed Jun  4 07:18:16 2008
@@ -28,7 +28,7 @@
 abs_pkgstatelogdir = $(abspath $(pkgstatelogdir))
 
 couch.ini: couch.ini.tpl
-	sed -r -e "s|%bindir%|$(abs_bindir)|g" \
+	sed -E -e "s|%bindir%|$(abs_bindir)|g" \
 	       -e "s|%pkgconfdir%|$(abs_pkgconfdir)|g" \
 	       -e "s|%pkgdatadir%|$(abs_pkgdatadir)|g" \
 	       -e "s|%pkgstatelibdir%|$(abs_pkgstatelibdir)|g" \

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=663113&r1=663112&r2=663113&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl Wed Jun  4 07:18:16
2008
@@ -16,29 +16,34 @@
 -define(DEFAULT_INI, "couch.ini").
 
 -behaviour(gen_server).
--export([start_link/0, init/1   , 
+-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, 
+-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, 
     load_ini_files/1]).
 
 start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).    
 
+stop() ->
+    ok.
+
 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_match(Key) -> gen_server:call(?MODULE, {lookup_match, Key}).
 lookup_match(Key, Default) -> gen_server:call(?MODULE, {lookup_match, Key, Default}).
 dump() -> gen_server:call(?MODULE, {dump, []}).
+register(Key, Fun) -> gen_server:call(?MODULE, {register, Key, Fun}).
 
 unset(Key) -> gen_server:call(?MODULE, {unset, Key}).
 
 init([]) ->     
-    Tap = ets:new(?MODULE, []),
-    {ok, Tap}.
+    Tab = ets:new(?MODULE, [set]),
+    {ok, Tab}.
 
 handle_call({store, Config}, _From, Tab) ->
     [insert_and_commit(Tab, Config2) || Config2 <- Config],
@@ -54,10 +59,14 @@
 
 handle_call({lookup, Key}, _From, Tab) ->
     lookup(Key, fun(Tab_, Key_) -> ets:lookup(Tab_, Key_) end, null, Tab);
-
+    
 handle_call({lookup, Key, Default}, _From, Tab) ->
     lookup(Key, fun(Tab_, Key_) -> ets:lookup(Tab_, Key_) end, Default, Tab);
 
+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_match, Key}, _From, Tab) ->
     lookup(Key, fun(Tab_, Key_) -> ets:match(Tab_, Key_) end, null, Tab);
 
@@ -66,8 +75,30 @@
 
 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]),
+    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
+        % found
+        [{{"_CouchDB", {Module, Variable}}, {_From, Fun}}] ->
+            io:format("got it '~p'~n", [ets:lookup(Tab, {Module, Variable})]),
+            Fun();
+        _ -> % not found
+            io:format("not it~n", []),
+            ok
+    end.
+            
+
 lookup(Key, Fun, Default, Tab) ->
     Reply = case Fun(Tab, Key) of
         [{Key, Value}] ->
@@ -80,12 +111,18 @@
     {reply, Reply, Tab}.
 
 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)]),
     {reply, File, _Tab} = 
         lookup({"_CouchDB", "ConfigurationStorageFile"}, 
             fun(Tab_, Key_) -> ets:lookup(Tab_, Key_) end, 
             null, Tab
         ),
-    ets:insert(Tab, Config),
+
+    io:format("got it '~p' but stored '~p'~n", [ets:lookup(Tab, {"HTTPd", "Port"}), Config]),
+
+    notify_registered_modules(Tab, Config),
     commit(Config, File).
 
 commit(Config, File) ->
@@ -99,7 +136,7 @@
 load_ini_files(IniFiles) ->
     % store the name of the last ini file for storing changes made at runtime
     [LastIniFile|_] = lists:reverse(IniFiles),
-    couch_config:init_value({"_CouchDB", "ConfigurationStorageFile"}, LastIniFile),
+    ?MODULE:init_value({"_CouchDB", "ConfigurationStorageFile"}, LastIniFile),
 
     % load all ini files in the order they come in.
     lists:foreach(fun(IniFile) -> load_ini_file(IniFile) end, IniFiles).
@@ -145,7 +182,7 @@
         
         lists:foreach(
             fun({Key, Value}) ->
-                couch_config:init_value(Key, Value)
+                ?MODULE:init_value(Key, Value)
             end,
             lists:reverse(ParsedIniValues)
         ),

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config_writer.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config_writer.erl?rev=663113&r1=663112&r2=663113&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config_writer.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config_writer.erl Wed Jun 
4 07:18:16 2008
@@ -19,8 +19,8 @@
     {ok, Lines} = regexp:split(binary_to_list(Stream), "\r\n|\n|\r|\032"),
     
     % prepare input variables
-    ModuleName = "[" ++ atom_to_list(Module) ++ "]",
-    VariableList = atom_to_list(Variable),
+    ModuleName = "[" ++ Module ++ "]",
+    VariableList = Variable,
     
     % produce the contents for the config file
     NewFileContents = save_loop({{ModuleName, VariableList}, Value}, Lines, "", "", []),

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl?rev=663113&r1=663112&r2=663113&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl Wed Jun  4 07:18:16
2008
@@ -13,7 +13,7 @@
 -module(couch_httpd).
 -include("couch_db.hrl").
 
--export([start_link/0, stop/0, handle_request/2]).
+-export([start_link/0, stop/0, handle_request/1, handle_request/2]).
 
 % Maximum size of document PUT request body (4GB)
 -define(MAX_DOC_SIZE, (4*1024*1024*1024)).
@@ -39,11 +39,21 @@
 }).
 
 start_link() ->
-    % read config
-    BindAddress = couch_config:lookup({"HTTPd", "BindAddress"}),
-    Port = couch_config:lookup({"HTTPd", "Port"}),
-    DocumentRoot = couch_config:lookup({"HTTPd", "DocumentRoot"}),
+
+    % 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_httpd:stop() end,
     
+    BindAddress = couch_config:lookup_and_register(
+        {"HTTPd", "BindAddress"}, ConfigChangeCallbackFunction),
+    Port = couch_config:lookup_and_register(
+        {"HTTPd", "Port"}, ConfigChangeCallbackFunction),
+    DocumentRoot = couch_config:lookup_and_register(
+        {"HTTPd", "DocumentRoot"}, ConfigChangeCallbackFunction),
+    
+    % and off we go
     Loop = fun (Req) -> apply(couch_httpd, handle_request, [Req, DocumentRoot]) end,
     mochiweb_http:start([
         {loop, Loop},
@@ -55,6 +65,9 @@
 stop() ->
     mochiweb_http:stop(?MODULE).
 
+handle_request(config_change) ->
+    stop().
+
 handle_request(Req, DocumentRoot) ->
     % alias HEAD to GET as mochiweb takes care of stripping the body
     Method = case Req:get(method) of
@@ -649,7 +662,7 @@
 
 handle_config_request(_Req, Method, {config, Config}) ->
     [Module, Key] = string:tokens(Config, "/"),
-    handle_config_request(_Req, Method, {[list_to_atom(Module), list_to_atom(Key)]});
+    handle_config_request(_Req, Method, {[Module, Key]});
 
 
 % PUT /_config/Module/Key

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=663113&r1=663112&r2=663113&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server.erl Wed Jun  4 07:18:16
2008
@@ -14,7 +14,7 @@
 -behaviour(gen_server).
 -behaviour(application).
 
--export([start/0,start/1,start/2,stop/0,stop/1]).
+-export([start/0,start/1,start/2,stop/0,stop/1,restart/0]).
 -export([open/1,create/2,delete/1,all_databases/0,get_version/0]).
 -export([init/1, handle_call/3,sup_start_link/0]).
 -export([handle_cast/2,code_change/3,handle_info/2,terminate/2]).
@@ -37,6 +37,10 @@
 start(_Type, _Args) ->
     start().
 
+restart() ->
+    stop(),
+    start().
+    
 stop() ->
     couch_server_sup:stop().
 



Mime
View raw message