couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [18/22] couch commit: updated refs/heads/COUCHDB-3287-pluggable-storage-engines to 327c053
Date Tue, 21 Feb 2017 17:46:34 GMT
Fix couch_auth_cache reinitialization logic

The couch_auth_cache process was attempting to track its various
monitors and then based on its monitor history decide if a 'DOWN'
message meant it should reinitialize or exit. With the new pluggable
storage engine work there was a subtle change to monitors which ended up
causing couch_auth_cache to receive a monitor from the file descriptor
before it received the monitor from the database's main pid. This
reordering was enough for couch_auth_cache to exit which ended up
causing errors in the test suite with race conditions when the test
tried to open an auth db before couch_auth_cache had restarted and
created the database.

However, if we step back and think harder, we'll never get a monitor
message we didn't ask for so rather than attempt to track specific
monitors we just reinitialize the cache everytime we see a 'DOWN'
message. On the downside this means that we're clearing the cache
multiple times per database exit, however normal operations won't have
this issue since that database never changes and clearing the cache
twice in the test suite is a non issue.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/8ed285b0
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/8ed285b0
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/8ed285b0

Branch: refs/heads/COUCHDB-3287-pluggable-storage-engines
Commit: 8ed285b00847032206834567ffbedc374466cdea
Parents: dd163aa
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Tue Feb 7 07:25:47 2017 -0600
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Tue Feb 21 11:44:58 2017 -0600

----------------------------------------------------------------------
 src/couch_auth_cache.erl | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/8ed285b0/src/couch_auth_cache.erl
----------------------------------------------------------------------
diff --git a/src/couch_auth_cache.erl b/src/couch_auth_cache.erl
index 54a6794..6895992 100644
--- a/src/couch_auth_cache.erl
+++ b/src/couch_auth_cache.erl
@@ -39,8 +39,6 @@
     max_cache_size = 0,
     cache_size = 0,
     db_notifier = nil,
-    db_mon_ref = nil,
-    closed = [],
     event_listener = nil
 }).
 
@@ -236,15 +234,8 @@ handle_info(restart_event_listener, State) ->
     {noreply, State#state{event_listener=NewListener}};
 handle_info({'DOWN', _Ref, _, _, shutdown}, State) ->
     {stop, shutdown, State};
-handle_info({'DOWN', Ref, _, _, _Reason}, #state{db_mon_ref = Ref} = State) ->
+handle_info({'DOWN', Ref, _, _, _}, State) ->
     {noreply, reinit_cache(State)};
-handle_info({'DOWN', Ref, _, _, Reason}, #state{closed = Closed} = State) ->
-    case lists:delete(Ref, Closed) of
-        Closed ->
-            {stop, Reason, State};
-        NewClosed ->
-            {noreply, reinit_cache(State#state{closed = NewClosed})}
-    end;
 handle_info(restart_config_listener, State) ->
     ok = config:listen_for_changes(?MODULE, nil),
     {noreply, State}.
@@ -283,15 +274,14 @@ clear_cache(State) ->
     State#state{cache_size = 0}.
 
 
-reinit_cache(#state{db_mon_ref = Ref, closed = Closed} = State) ->
+reinit_cache(#state{} = State) ->
     NewState = clear_cache(State),
     AuthDbName = ?l2b(config:get("couch_httpd_auth", "authentication_db")),
     true = ets:insert(?STATE, {auth_db_name, AuthDbName}),
     AuthDb = open_auth_db(),
     true = ets:insert(?STATE, {auth_db, AuthDb}),
-    DbPid = couch_db:get_pid(AuthDb),
-    NewState#state{closed = [Ref|Closed],
-                   db_mon_ref = erlang:monitor(process, DbPid)}.
+    couch_db:monitor(AuthDb),
+    NewState.
 
 
 add_cache_entry(_, _, _, #state{max_cache_size = 0} = State) ->


Mime
View raw message