You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2017/08/03 19:03:28 UTC

[couchdb] branch allow-database-disabling updated (45db886 -> fd2e4f1)

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a change to branch allow-database-disabling
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


 discard 45db886  Allow operators to disable databases
     new fd2e4f1  Allow operators to disable databases

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (45db886)
            \
             N -- N -- N   refs/heads/allow-database-disabling (fd2e4f1)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/couch/src/couch_server.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].

[couchdb] 01/01: Allow operators to disable databases

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch allow-database-disabling
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit fd2e4f1809ee6b0f425ec0b83a8fb42ab8bbdd92
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Aug 3 13:55:17 2017 -0500

    Allow operators to disable databases
    
    This is to disable the Erlang VM from attempting to open files when an
    operator is undeleting a database. Obviously, the nodes must have been
    configured for database recovery for this to be useful.
---
 src/couch/src/couch_server.erl | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl
index 24016e0..7ccee2d 100644
--- a/src/couch/src/couch_server.erl
+++ b/src/couch/src/couch_server.erl
@@ -227,6 +227,10 @@ handle_config_change("couchdb", "max_dbs_open", _, _, _) ->
 handle_config_change("admins", _, _, Persist, _) ->
     % spawn here so couch event manager doesn't deadlock
     {ok, spawn(fun() -> hash_admin_passwords(Persist) end)};
+handle_config_change("disabled_dbs", _DbName, "", _, _) ->
+    {ok, nil};
+handle_config_change("disabled_dbs", DbName, _, _, _) ->
+    {ok, gen_server:call(couch_server, {close_db, list_to_binary(DbName)})};
 handle_config_change("httpd", "authentication_handlers", _, _, _) ->
     {ok, couch_httpd:stop()};
 handle_config_change("httpd", "bind_address", _, _, _) ->
@@ -302,6 +306,15 @@ open_async(Server, From, DbName, Filepath, Options) ->
     Parent = self(),
     T0 = os:timestamp(),
     Opener = spawn_link(fun() ->
+        case config:get("disabled_dbs", binary_to_list(DbName), "false") of
+            "false" ->
+                ok;
+            _ ->
+                Msg = {open_result, T0, DbName, disabled},
+                gen_server:call(Parent, Msg, infinity),
+                unlink(Parent),
+                exit(normal)
+        end,
         Res = couch_db:start_link(DbName, Filepath, Options),
         case {Res, lists:member(create, Options)} of
             {{ok, _Db}, true} ->
@@ -512,7 +525,25 @@ handle_call({db_updated, #db{}=Db}, _From, Server0) ->
     catch _:_ ->
         Server0
     end,
-    {reply, ok, Server}.
+    {reply, ok, Server};
+handle_call({close_db, DbName}, _From, Server0) ->
+    Server1 = case ets:lookup(couch_dbs, DbName) of
+        [] ->
+            Server0;
+        [#db{main_pid=Pid, compactor_pid=Froms} = Db] when is_list(Froms) ->
+            % icky hack of field values - compactor_pid used to store clients
+            true = ets:delete(couch_dbs, DbName),
+            true = ets:delete(couch_dbs_pid_to_name, Pid),
+            exit(Pid, kill),
+            [gen_server:reply(F, disabled) || F <- Froms],
+            db_closed(Server0, Db#db.options);
+        [#db{main_pid=Pid} = Db] ->
+            true = ets:delete(couch_dbs, DbName),
+            true = ets:delete(couch_dbs_pid_to_name, Pid),
+            exit(Pid, kill),
+            db_closed(Server0, Db#db.options)
+    end,
+    {reply, ok, Server1}.
 
 handle_cast({update_lru, DbName}, #server{lru = Lru, update_lru_on_read=true} = Server) ->
     {noreply, Server#server{lru = couch_lru:update(DbName, Lru)}};

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.