couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r686899 - in /incubator/couchdb/branches/runtimeconfig: share/www/script/ src/couchdb/
Date Mon, 18 Aug 2008 23:51:51 GMT
Author: damien
Date: Mon Aug 18 16:51:50 2008
New Revision: 686899

URL: http://svn.apache.org/viewvc?rev=686899&view=rev
Log:
More refactoring work.

Modified:
    incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_db_update_notifier.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_ft_query.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.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_sup.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl

Modified: incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js?rev=686899&r1=686898&r2=686899&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js [utf-8] (original)
+++ incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js [utf-8] Mon Aug
18 16:51:50 2008
@@ -1441,35 +1441,31 @@
     if(debug) debugger;
     var xhr;
 
-    xhr = CouchDB.request("GET", "/_config/CouchDB/MaximumDocumentSize");
-    T(xhr.status == 200);
-    var res = JSON.parse(xhr.responseText);
-    T(res.ok);
-    var original_value = res.value
-
-    xhr = CouchDB.request("POST", "/_config/CouchDB/MaximumDocumentSize", {"body":"1024"});
+    xhr = CouchDB.request("POST", "/_config/CouchDBTest/Test", {"body":"1024"});
     T(xhr.status == 200);
     var res = JSON.parse(xhr.responseText);
     T(res.ok);
     T(res.value == "1024");
+    
+    restartServer();
 
-    xhr = CouchDB.request("GET", "/_config/CouchDB/MaximumDocumentSize");
+    xhr = CouchDB.request("GET", "/_config/CouchDBTest/Test");
     T(xhr.status == 200);
     var res = JSON.parse(xhr.responseText);
     T(res.ok);
     T(res.value == "1024");
 
-    xhr = CouchDB.request("DELETE", "/_config/CouchDB/MaximumDocumentSize");
+    xhr = CouchDB.request("DELETE", "/_config/CouchDBTest/Test");
     T(xhr.status == 200);
     var res = JSON.parse(xhr.responseText);
     T(res.ok);
     T(res.old_value == "1024");
 
-    xhr = CouchDB.request("PUT", "/_config/CouchDB/MaximumDocumentSize", {"body": original_value});
+    xhr = CouchDB.request("PUT", "/_config/CouchDBTest/Test", {"body": "1024"});
     T(xhr.status == 200);
     var res = JSON.parse(xhr.responseText);
     T(res.ok);
-    T(res.value == original_value);
+    T(res.value == "1024");
   }
 };
 

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=686899&r1=686898&r2=686899&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl Mon Aug 18 16:51:50
2008
@@ -26,7 +26,7 @@
 -export([store/2, register/1, register/2, 
     get/1, get/2,
     lookup_match/1, lookup_match/2,
-    dump/0, unset/1, load_ini_file/1]).
+    all/0, unset/1, load_ini_file/1]).
     
 -record(config,
     {notify_funs=[],
@@ -66,10 +66,7 @@
 %%      to ets::match(). Returns Default::any() if no Key is found
 lookup_match(Key, Default) -> gen_server:call(?MODULE, {lookup_match, Key, Default}).
 
-%% @spec dump() -> ok:atom()
-%% @doc Dumps the current ets table with all configuration data.
-dump() -> gen_server:call(?MODULE, {dump, []}).
-
+all() -> gen_server:call(?MODULE, all).
 
 register(Fun) -> gen_server:call(?MODULE, {register, Fun, self()}).
 
@@ -88,13 +85,6 @@
 init(IniFiles) ->
     ets:new(?MODULE, [named_table, set, protected]),
     [ok = load_ini_file(IniFile) || IniFile <- IniFiles],
-    
-    % announce startup
-    io:format("Apache CouchDB ~s (LogLevel=~s) is starting.~n", [
-        couch_server:get_version(),
-        ?MODULE:get({"Log", "Level"}, "info")
-    ]),
-    
     {ok, #config{writeback_filename=lists:last(IniFiles)}}.
 
 %% @doc see store/2
@@ -118,12 +108,8 @@
 handle_call({lookup_match, Key, Default}, _From, Config) ->
     {reply, fix_lookup_result(ets:match(?MODULE, Key), Default), Config};
 
-%% @doc See dump/0
-handle_call({dump, []}, _From, Config) ->
-    KVs = lists:sort(ets:tab2list(?MODULE)),
-    [io:format("[~s] ~s=~p~n", [Module, Variable, Value])
-            || {{Module, Variable}, Value} <- KVs],
-    {reply, ok, Config};
+handle_call(all, _From, Config) ->
+    {reply, lists:sort(ets:tab2list(?MODULE)), Config};
 
 %% @doc See register/2
 handle_call({register, Fun, Pid}, _From, #config{notify_funs=PidFuns}=Config) ->

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_db_update_notifier.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_db_update_notifier.erl?rev=686899&r1=686898&r2=686899&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_db_update_notifier.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_db_update_notifier.erl Mon
Aug 18 16:51:50 2008
@@ -25,8 +25,6 @@
 -export([start_link/1, notify/1]).
 -export([init/1, terminate/2, handle_event/2, handle_call/2, handle_info/2, code_change/3,stop/1]).
 
--define(ERR_HANDLE, {Port, {exit_status, Status}} -> {stop, {unknown_error, Status}, {unknown_error,
Status}, Port}).
-
 start_link(Exec) ->
     couch_event_sup:start_link(couch_db_update, {couch_db_update_notifier, make_ref()}, Exec).
 

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_ft_query.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_ft_query.erl?rev=686899&r1=686898&r2=686899&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_ft_query.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_ft_query.erl Mon Aug 18 16:51:50
2008
@@ -13,14 +13,12 @@
 -module(couch_ft_query).
 -behaviour(gen_server).
 
--export([start_link/1, execute/2]).
+-export([start_link/0, execute/2]).
 
 -export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,code_change/3,
stop/0]).
 
--define(ERR_HANDLE, {Port, {exit_status, Status}} -> {stop, {unknown_error, Status}, {unknown_error,
Status}, Port}).
-
-start_link(QueryExec) ->
-    gen_server:start_link({local, couch_ft_query}, couch_ft_query, QueryExec, []).
+start_link() ->
+    gen_server:start_link({local, couch_ft_query}, couch_ft_query, [], []).
 
 stop() ->
     exit(whereis(couch_ft_query), close).
@@ -28,13 +26,25 @@
 execute(DatabaseName, QueryString) ->
     gen_server:call(couch_ft_query, {ft_query, DatabaseName, QueryString}).
 
-init(QueryExec) ->
-    Port = open_port({spawn, QueryExec}, [{line, 1000}, exit_status, hide]),
-    {ok, Port}.
+init([]) ->
+    ok = couch_config:register(
+        fun({"Search", "QueryServer"}) ->
+            ?MODULE:stop()
+        end),
+    
+    case couch_config:get({"Search", "QueryServer"}, none) of
+    none ->
+        {ok, none};
+    QueryExec ->
+        Port = open_port({spawn, QueryExec}, [{line, 1000}, exit_status, hide]),
+        {ok, Port}
+    end.
 
 terminate(_Reason, _Server) ->
     ok.
 
+handle_call({ft_query, _Database, _QueryText}, _From, none) ->
+    {reply, {error, no_full_test_query_specified_in_config}, none};
 handle_call({ft_query, Database, QueryText}, _From, Port) ->
     % send the database name
     true = port_command(Port, Database ++ "\n"),

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=686899&r1=686898&r2=686899&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl Mon Aug 18 16:51:50
2008
@@ -39,13 +39,12 @@
 }).
 
 start_link() ->
-
     % 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.
     
-    BindAddress = couch_config:get({"HTTPd", "BindAddress"}, "127.0.0.1"),
+    BindAddress = couch_config:get({"HTTPd", "BindAddress"}, any),
     Port = couch_config:get({"HTTPd", "Port"}, "5984"),
     DocumentRoot = couch_config:get({"HTTPd", "DocumentRoot"}, "../../share/www"),
     
@@ -65,10 +64,10 @@
         ({"HTTPd", "DocumentRoot"}) ->
             ?MODULE:stop()
         end, Pid),
+    
     {ok, Pid}.
 
 stop() ->
-    io:format("asfasfSZfasdfasdfasfasdf"),
     mochiweb_http:stop(?MODULE).
 
 handle_request(config_change) ->

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=686899&r1=686898&r2=686899&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_log.erl Mon Aug 18 16:51:50
2008
@@ -52,7 +52,7 @@
             ?MODULE:stop()
         end),
     
-    Filename = couch_config:get({"Log", "File"}, "log.txt"),
+    Filename = couch_config:get({"Log", "File"}, "couchdb.log"),
     Level = couch_config:get({"Log", "Level"},"info"),
 
     {ok, Fd} = file:open(Filename, [append]),

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=686899&r1=686898&r2=686899&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_query_servers.erl Mon Aug 18
16:51:50 2008
@@ -176,13 +176,15 @@
     
     % just stop if one of the config settings change. couch_server_sup
     % will restart us and then we will pick up the new settings.
-    QueryServerList = couch_config:lookup_match(
-            {{"CouchDB Query Servers", '$1'}, '$2'}, []),
+    
     ok = couch_config:register(
         fun({"CouchDB Query Server" ++ _, _}) ->
             ?MODULE:stop()
         end),
         
+    QueryServerList = couch_config:lookup_match(
+            {{"CouchDB Query Servers", '$1'}, '$2'}, []),
+        
     {ok, {QueryServerList, []}}.
 
 terminate(_Reason, _Server) ->
@@ -232,9 +234,7 @@
         {noreply, {QueryServerList,  lists:keydelete(Port, 2, LangPorts)}};
     _ ->
         ?LOG_ERROR("Unknown linked port/process crash: ~p", [Port])
-    end;
-handle_info(_Whatever, {Cmd, Ports}) ->
-    {noreply, {Cmd, Ports}}.
+    end.
 
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.

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=686899&r1=686898&r2=686899&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl Mon Aug 18 16:51:50
2008
@@ -14,7 +14,7 @@
 -behaviour(supervisor).
 
 
--export([start_link/1,stop/0,couch_config_start_link_wrapper/2]).
+-export([start_link/1,stop/0,couch_config_start_link_wrapper/2,start_primary_services/0]).
 
 -include("couch_db.hrl").
 
@@ -46,8 +46,23 @@
         end;
     _ -> ok
     end,
+    
     {ok, ConfigPid} = couch_config:start_link(IniFiles),
     
+    LogLevel = couch_config:get({"Log", "Level"}, "info"),
+    % announce startup
+    io:format("Apache CouchDB ~s (LogLevel=~s) is starting.~n", [
+        couch_server:get_version(),
+        LogLevel
+    ]),
+    case LogLevel of
+    "debug" ->
+        io:format("Configuration Settings ~p:~n", [IniFiles]),
+        [io:format("  [~s] ~s=~p~n", [Module, Variable, Value])
+            || {{Module, Variable}, Value} <- couch_config:all()];
+    _ -> ok
+    end,
+    
     LibDir =
     case couch_config:get({"CouchDB", "UtilDriverDir"}, null) of
     null ->
@@ -56,52 +71,22 @@
     end,
     
     ok = couch_util:start_driver(LibDir),
-
     
-    ChildProcesses =
+    BaseServices =
+    {{one_for_all, 10, 3600}, 
         [{couch_config,
             {couch_server_sup, couch_config_start_link_wrapper, [IniFiles, ConfigPid]},
             permanent,
             brutal_kill,
             worker,
-            [couch_config]},
-        {couch_log,
-            {couch_log, start_link, []},
-            permanent,
-            brutal_kill,
-            worker,
-            [couch_server]},
-        {couch_db_update_event,
-            {gen_event, start_link, [{local, couch_db_update}]},
-            permanent,
-            1000,
-            supervisor,
             dynamic},
-        {couch_server,
-            {couch_server, sup_start_link, []},
+        {couch_primary_services,
+            {couch_server_sup, start_primary_services, []},
             permanent,
             brutal_kill,
-            worker,
-            [couch_server]},
-        {couch_query_servers,
-            {couch_query_servers, start_link, []},
-            permanent,
-            brutal_kill,
-            worker,
-            [couch_query_servers]},
-        {couch_view,
-            {couch_view, start_link, []},
-            permanent,
-            brutal_kill,
-            worker,
-            [couch_view]},
-        {couch_httpd,
-            {couch_httpd, start_link, []},
-            permanent,
-            1000,
             supervisor,
-            [couch_httpd]}
-        ],
+            [couch_server_sup]}
+        ]},
    
 
     % ensure these applications are running
@@ -109,8 +94,8 @@
     application:start(crypto),
 
     {ok, Pid} = supervisor:start_link(
-        {local, couch_server_sup}, couch_server_sup, ChildProcesses),
-    io:format("started"),
+        {local, couch_server_sup}, couch_server_sup, BaseServices),
+
     % launch the icu bridge
     % just restart if one of the config settings change.
 
@@ -119,16 +104,66 @@
             ?MODULE:stop()
         end, Pid),
     
-    % we only get where when startup was successful
-    BindAddress = couch_config:get({"HTTPd", "BindAddress"}),
-    Port = couch_config:get({"HTTPd", "Port"}),
-    io:format("Apache CouchDB has started, see http://~s:~s/_utils/index.html~n",
-            [BindAddress, Port]),
+    unlink(ConfigPid),
+    
+    io:format("Apache CouchDB has started. Time to relax.~n"),
+    
     {ok, Pid}.
 
+start_primary_services() ->
+    supervisor:start_link(couch_server_sup,
+        {{one_for_one, 10, 3600}, 
+            [{couch_log,
+                {couch_log, start_link, []},
+                permanent,
+                brutal_kill,
+                worker,
+                [couch_log]},
+            {couch_db_update_event,
+                {gen_event, start_link, [{local, couch_db_update}]},
+                permanent,
+                brutal_kill,
+                supervisor,
+                dynamic},
+            {couch_server,
+                {couch_server, sup_start_link, []},
+                permanent,
+                brutal_kill,
+                supervisor,
+                [couch_server]},
+            {couch_query_servers,
+                {couch_query_servers, start_link, []},
+                permanent,
+                brutal_kill,
+                supervisor,
+                [couch_query_servers]},
+            {couch_view,
+                {couch_view, start_link, []},
+                permanent,
+                brutal_kill,
+                supervisor,
+                [couch_view]},
+            {couch_httpd,
+                {couch_httpd, start_link, []},
+                permanent,
+                brutal_kill,
+                supervisor,
+                [couch_httpd]},
+            {couch_ft_query,
+                {couch_ft_query, start_link, []},
+                permanent,
+                brutal_kill,
+                supervisor,
+                [couch_ft_query]},
+            {couch_db_update_notifier_sup,
+                {couch_db_update_notifier_sup, start_link, []},
+                permanent,
+                brutal_kill,
+                supervisor,
+                [couch_db_update_notifier_sup]}]}).
 
 stop() ->
     catch exit(whereis(couch_server_sup), normal).
 
-init(ChildProcesses) ->
-    {ok, {{one_for_one, 10, 3600}, ChildProcesses}}.
+init(ChildSpecs) ->
+    {ok, ChildSpecs}.

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=686899&r1=686898&r2=686899&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_util.erl Mon Aug 18 16:51:50
2008
@@ -26,9 +26,12 @@
     % read config and register for configuration changes
     
     case erl_ddll:load_driver(LibDir, "couch_erl_driver") of
-    ok -> ok;
-    {error, already_loaded} -> ok;
-    {error, Error} -> exit(erl_ddll:format_error(Error))
+    ok ->
+        ok;
+    {error, already_loaded} ->
+        ok = erl_ddll:reload_driver(LibDir, "couch_erl_driver");
+    {error, Error} ->
+        exit(erl_ddll:format_error(Error))
     end.
 
 new_uuid() ->



Mime
View raw message