Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E22F8200C23 for ; Tue, 7 Feb 2017 16:06:00 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id E0CA8160B3E; Tue, 7 Feb 2017 15:06:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 32631160B69 for ; Tue, 7 Feb 2017 16:06:00 +0100 (CET) Received: (qmail 31521 invoked by uid 500); 7 Feb 2017 15:05:59 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 31336 invoked by uid 99); 7 Feb 2017 15:05:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Feb 2017 15:05:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E9553DFE46; Tue, 7 Feb 2017 15:05:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davisp@apache.org To: commits@couchdb.apache.org Date: Tue, 07 Feb 2017 15:06:00 -0000 Message-Id: In-Reply-To: <5d2dd018b19a4ed38ec7f84c952ef9a7@git.apache.org> References: <5d2dd018b19a4ed38ec7f84c952ef9a7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/7] couch commit: updated refs/heads/COUCHDB-3287-pluggable-storage-engines to 872ac77 archived-at: Tue, 07 Feb 2017 15:06:01 -0000 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/3e1c2dad Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/3e1c2dad Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/3e1c2dad Branch: refs/heads/COUCHDB-3287-pluggable-storage-engines Commit: 3e1c2dad546164cce12b63f10333d98b140bc363 Parents: d980aa5 Author: Paul J. Davis Authored: Tue Feb 7 07:25:47 2017 -0600 Committer: Paul J. Davis Committed: Tue Feb 7 09:05:09 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/3e1c2dad/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) ->