couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r735875 - in /couchdb/trunk: etc/couchdb/ share/www/script/ src/couchdb/
Date Mon, 19 Jan 2009 23:31:51 GMT
Author: damien
Date: Mon Jan 19 15:31:51 2009
New Revision: 735875

URL: http://svn.apache.org/viewvc?rev=735875&view=rev
Log:
tests for fix to COUCHDB-215, and changing of how max_dbs_open setting is handled at runtime.

Modified:
    couchdb/trunk/etc/couchdb/default.ini.tpl.in
    couchdb/trunk/share/www/script/couch_tests.js
    couchdb/trunk/src/couchdb/couch_db.hrl
    couchdb/trunk/src/couchdb/couch_file_stats.erl
    couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl
    couchdb/trunk/src/couchdb/couch_server.erl
    couchdb/trunk/src/couchdb/couch_view.erl

Modified: couchdb/trunk/etc/couchdb/default.ini.tpl.in
URL: http://svn.apache.org/viewvc/couchdb/trunk/etc/couchdb/default.ini.tpl.in?rev=735875&r1=735874&r2=735875&view=diff
==============================================================================
--- couchdb/trunk/etc/couchdb/default.ini.tpl.in (original)
+++ couchdb/trunk/etc/couchdb/default.ini.tpl.in Mon Jan 19 15:31:51 2009
@@ -7,6 +7,7 @@
 util_driver_dir = %couchprivlibdir%
 max_document_size = 4294967296 ; 4 GB
 view_timeout = 5000 ; 5 seconds
+max_dbs_open = 100
 
 [httpd]
 port = 5984
@@ -39,6 +40,7 @@
 
 _utils = {couch_httpd_misc_handlers, handle_utils_dir_req, "%localdatadir%/www"}
 _all_dbs = {couch_httpd_misc_handlers, handle_all_dbs_req}
+_stats = {couch_httpd_misc_handlers, handle_stats_req}
 _config = {couch_httpd_misc_handlers, handle_config_req}
 _replicate = {couch_httpd_misc_handlers, handle_replicate_req}
 _uuids = {couch_httpd_misc_handlers, handle_uuids_req}

Modified: couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=735875&r1=735874&r2=735875&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Mon Jan 19 15:31:51 2009
@@ -2860,7 +2860,38 @@
         // Now delete document
         T(user2Db.deleteDoc(doc).ok);
       });
-  }
+  },
+  
+  
+  max_dbs_open : function(debug) {
+    if (debug) debugger;
+    restartServer();
+    var max = 5;
+    run_on_modified_server(
+      [{section: "couchdb",
+        key: "max_dbs_open",
+        value: max.toString()}],
+        
+      function () {
+        for(var i=0; i<max*2; i++) {
+          var db = new CouchDB("test_suite_db"+ i);
+          db.deleteDb();
+          db.createDb();
+        }
+        
+        var stats = JSON.parse(CouchDB.request("GET", "/_stats").responseText);
+        T(stats.dbs_open == max);
+        
+        
+        for(var i=0; i<max*2; i++) {
+          var db = new CouchDB("test_suite_db"+ i);
+          db.deleteDb();
+        }
+        
+        var stats = JSON.parse(CouchDB.request("GET", "/_stats").responseText);
+        T(stats.dbs_open == 0);
+      })
+  },
 };
 
 function makeDocs(start, end, templateDoc) {

Modified: couchdb/trunk/src/couchdb/couch_db.hrl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_db.hrl?rev=735875&r1=735874&r2=735875&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db.hrl (original)
+++ couchdb/trunk/src/couchdb/couch_db.hrl Mon Jan 19 15:31:51 2009
@@ -177,14 +177,6 @@
     reduce_funs=[]
     }).
 
--record(server,{
-    root_dir = [],
-    dbname_regexp,
-    max_dbs_open=100,
-    current_dbs_open=0,
-    start_time=""
-    }).
-
 -record(index_header,
     {seq=0,
     purge_seq=0,

Modified: couchdb/trunk/src/couchdb/couch_file_stats.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_file_stats.erl?rev=735875&r1=735874&r2=735875&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_file_stats.erl (original)
+++ couchdb/trunk/src/couchdb/couch_file_stats.erl Mon Jan 19 15:31:51 2009
@@ -30,7 +30,7 @@
 
 get_stats() ->
     #stats{opened=Opened,closed=Closed}=gen_server:call(couch_file_stats,get),
-    {ok, [{opened,Opened}, {closed,Closed}]}.
+    [{files_open,Opened-Closed}, {files_closed,Closed}].
 
 
 start_link() ->

Modified: couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl?rev=735875&r1=735874&r2=735875&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl Mon Jan 19 15:31:51 2009
@@ -12,9 +12,9 @@
 
 -module(couch_httpd_misc_handlers).
 
--export([handle_welcome_req/2,handle_favicon_req/2,handle_utils_dir_req/2,handle_all_dbs_req/1,
-    handle_replicate_req/1,handle_restart_req/1,handle_uuids_req/1,
-    handle_config_req/1]).
+-export([handle_welcome_req/2,handle_favicon_req/2,handle_utils_dir_req/2,
+    handle_all_dbs_req/1,handle_replicate_req/1,handle_restart_req/1,
+    handle_uuids_req/1,handle_config_req/1,handle_stats_req/1]).
     
 -export([increment_update_seq_req/2]).
 
@@ -31,8 +31,7 @@
 handle_welcome_req(#httpd{method='GET'}=Req, WelcomeMessage) ->
     send_json(Req, {[
         {couchdb, WelcomeMessage},
-        {version, list_to_binary(couch_server:get_version())},
-        {start_time, list_to_binary(couch_server:get_start_time())}
+        {version, list_to_binary(couch_server:get_version())}
     ]});
 handle_welcome_req(Req, _) ->
     send_method_not_allowed(Req, "GET,HEAD").
@@ -62,6 +61,11 @@
 handle_all_dbs_req(Req) ->
     send_method_not_allowed(Req, "GET,HEAD").
 
+handle_stats_req(#httpd{method='GET'}=Req) ->
+    ok = couch_httpd:verify_is_server_admin(Req),
+    send_json(Req, {couch_server:get_stats() ++ couch_file_stats:get_stats()});
+handle_stats_req(Req) ->
+    send_method_not_allowed(Req, "GET,HEAD").
 
 handle_replicate_req(#httpd{user_ctx=UserCtx,method='POST'}=Req) ->
     {Props} = couch_httpd:json_body(Req),

Modified: couchdb/trunk/src/couchdb/couch_server.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_server.erl?rev=735875&r1=735874&r2=735875&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_server.erl (original)
+++ couchdb/trunk/src/couchdb/couch_server.erl Mon Jan 19 15:31:51 2009
@@ -18,10 +18,18 @@
 -export([open/2,create/2,delete/2,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]).
--export([dev_start/0,is_admin/2,has_admins/0,get_start_time/0]).
+-export([dev_start/0,is_admin/2,has_admins/0,get_stats/0]).
 
 -include("couch_db.hrl").
 
+-record(server,{
+    root_dir = [],
+    dbname_regexp,
+    max_dbs_open=100,
+    dbs_open=0,
+    start_time=""
+    }).
+
 start() ->
     start(["default.ini"]).
 
@@ -55,9 +63,10 @@
         "0.0.0"
     end.
 
-get_start_time() ->
-    {ok, #server{start_time=Time}} = gen_server:call(couch_server, get_server),
-    Time.
+get_stats() ->
+    {ok, #server{start_time=Time,dbs_open=Open}} =
+            gen_server:call(couch_server, get_server),
+    [{start_time, ?l2b(Time)}, {dbs_open, Open}].
 
 sup_start_link() ->
     gen_server:start_link({local, couch_server}, couch_server, [], []).
@@ -124,16 +133,19 @@
 
     RootDir = couch_config:get("couchdb", "database_dir", "."),
     MaxDbsOpen = list_to_integer(
-            couch_config:get("couchdb", "max_open_databases", "100")),
+            couch_config:get("couchdb", "max_dbs_open")),
     Self = self(),
     ok = couch_config:register(
         fun("couchdb", "database_dir") ->
-            exit(Self, config_change);
-        ("couchdb", "server_options") ->
             exit(Self, config_change)
         end),
     ok = couch_config:register(
-        fun("admins", _) ->
+        fun("couchdb", "max_dbs_open", Max) ->
+            gen_server:call(couch_server,
+                    {set_max_dbs_open, list_to_integer(Max)})
+        end),
+    ok = couch_config:register(
+        fun("admins") ->
             hash_admin_passwords()
         end),
     hash_admin_passwords(),
@@ -164,13 +176,13 @@
     {ok, Filenames}.
 
 
-maybe_close_lru_db(#server{current_dbs_open=NumOpen, max_dbs_open=MaxOpen}=Server)
+maybe_close_lru_db(#server{dbs_open=NumOpen, max_dbs_open=MaxOpen}=Server)
         when NumOpen < MaxOpen ->
     {ok, Server};
-maybe_close_lru_db(#server{current_dbs_open=NumOpen}=Server) ->
+maybe_close_lru_db(#server{dbs_open=NumOpen}=Server) ->
     % must free up the lru db.
     case try_close_lru(now()) of
-    ok -> {ok, Server#server{current_dbs_open=NumOpen-1}};
+    ok -> {ok, Server#server{dbs_open=NumOpen-1}};
     Error -> Error
     end.
 
@@ -203,6 +215,8 @@
         end
     end.
 
+handle_call({set_max_dbs_open, Max}, _From, Server) ->
+    {reply, ok, Server#server{max_dbs_open=Max}};
 handle_call(get_server, _From, Server) ->
     {reply, {ok, Server}, Server};
 handle_call({open, DbName, Options}, _From, Server) ->
@@ -220,9 +234,9 @@
                     true = ets:insert(couch_dbs_by_name, {DbName, {MainPid, LruTime}}),
                     true = ets:insert(couch_dbs_by_pid, {MainPid, DbName}),
                     true = ets:insert(couch_dbs_by_lru, {LruTime, DbName}),
-                    DbsOpen = Server2#server.current_dbs_open + 1,
+                    DbsOpen = Server2#server.dbs_open + 1,
                     {reply, {ok, MainPid},
-                            Server2#server{current_dbs_open=DbsOpen}};
+                            Server2#server{dbs_open=DbsOpen}};
                 Error ->
                     {reply, Error, Server2}
                 end;
@@ -255,10 +269,10 @@
                             {DbName, {MainPid, LruTime}}),
                     true = ets:insert(couch_dbs_by_pid, {MainPid, DbName}),
                     true = ets:insert(couch_dbs_by_lru, {LruTime, DbName}),
-                    DbsOpen = Server2#server.current_dbs_open + 1,
+                    DbsOpen = Server2#server.dbs_open + 1,
                     couch_db_update_notifier:notify({created, DbName}),
                     {reply, {ok, MainPid},
-                            Server2#server{current_dbs_open=DbsOpen}};
+                            Server2#server{dbs_open=DbsOpen}};
                 Error ->
                     {reply, Error, Server2}
                 end;
@@ -285,8 +299,7 @@
             true = ets:delete(couch_dbs_by_name, DbName),
             true = ets:delete(couch_dbs_by_pid, Pid),
             true = ets:delete(couch_dbs_by_lru, LruTime),
-            DbsOpen = Server#server.current_dbs_open - 1,
-            Server#server{current_dbs_open=DbsOpen}
+            Server#server{dbs_open=Server#server.dbs_open - 1}
         end,
         case file:delete(FullFilepath) of
         ok ->
@@ -306,13 +319,15 @@
 
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
-
-handle_info({'EXIT', Pid, _Reason}, #server{current_dbs_open=DbsOpen}=Server) ->
+    
+handle_info({'EXIT', _Pid, config_change}, _Server) ->
+    exit(kill);
+handle_info({'EXIT', Pid, _Reason}, #server{dbs_open=DbsOpen}=Server) ->
     [{Pid, DbName}] = ets:lookup(couch_dbs_by_pid, Pid),
     [{DbName, {Pid, LruTime}}] = ets:lookup(couch_dbs_by_name, DbName),
     true = ets:delete(couch_dbs_by_pid, Pid),
     true = ets:delete(couch_dbs_by_name, DbName),
     true = ets:delete(couch_dbs_by_lru, LruTime),
-    {noreply, Server#server{current_dbs_open=DbsOpen-1}};
+    {noreply, Server#server{dbs_open=DbsOpen-1}};
 handle_info(Info, _Server) ->
     exit({unknown_message, Info}).

Modified: couchdb/trunk/src/couchdb/couch_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_view.erl?rev=735875&r1=735874&r2=735875&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_view.erl Mon Jan 19 15:31:51 2009
@@ -20,6 +20,10 @@
     extract_map_view/1]).
 
 -include("couch_db.hrl").
+
+
+-record(server,{
+    root_dir = []}).
     
 start_link() ->
     gen_server:start_link({local, couch_view}, couch_view, [], []).



Mime
View raw message