Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 26FC3115B9 for ; Tue, 5 Aug 2014 21:17:47 +0000 (UTC) Received: (qmail 24724 invoked by uid 500); 5 Aug 2014 21:17:46 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 24431 invoked by uid 500); 5 Aug 2014 21:17:46 -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 23384 invoked by uid 99); 5 Aug 2014 21:17:46 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Aug 2014 21:17:46 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id EE4109C0697; Tue, 5 Aug 2014 21:17:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rnewson@apache.org To: commits@couchdb.apache.org Date: Tue, 05 Aug 2014 21:18:15 -0000 Message-Id: In-Reply-To: <40437750d2d14db4be991a9bb0e43dc9@git.apache.org> References: <40437750d2d14db4be991a9bb0e43dc9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [32/36] couch commit: updated refs/heads/windsor-merge-211 to b7adb86 Verify that DB is in couch_dbs before updating This patch fixes a bug where there could be a db_updated message in the couch_server message queue, but the updater process could be dead and removed from the couch_dbs ets table. While this patch doesn't change the possibility of that state, it makes the couch_server db_updated function clause to verify that 1) the DB is in the couch_dbs ets table and 2) that the instance_start_time of the updated DB matches the instance_start_time of the couch_dbs entry. If the DB isn't in the couch_dbs ets table it means that it was removed from the LRU. If the two instance_start_times don't match, it means that the old couch_dbs entry was expired from the LRU and re-inserted before the monitor exit message was processed. BugzID: 21179 Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/41b61b9a Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/41b61b9a Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/41b61b9a Branch: refs/heads/windsor-merge-211 Commit: 41b61b9a2f07e62dc20a84be85f328dd225f89c9 Parents: 9f16b07 Author: Benjamin Bastian Authored: Mon Jul 22 15:41:54 2013 -0700 Committer: Robert Newson Committed: Tue Aug 5 17:35:48 2014 +0100 ---------------------------------------------------------------------- src/couch_server.erl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/41b61b9a/src/couch_server.erl ---------------------------------------------------------------------- diff --git a/src/couch_server.erl b/src/couch_server.erl index e741720..fd4691c 100644 --- a/src/couch_server.erl +++ b/src/couch_server.erl @@ -483,13 +483,22 @@ handle_call({delete, DbName, Options}, _From, Server) -> Error -> {reply, Error, Server} end; -handle_call({db_updated, #db{name = DbName} = Db}, _From, Server) -> - true = ets:insert(couch_dbs, Db), - Lru = case couch_db:is_system_db(Db) of - false -> couch_lru:update(DbName, Server#server.lru); - true -> Server#server.lru +handle_call({db_updated, #db{}=Db}, _From, Server0) -> + #db{name = DbName, instance_start_time = StartTime} = Db, + Server = try ets:lookup_element(couch_dbs, DbName, #db.instance_start_time) of + StartTime -> + true = ets:insert(couch_dbs, Db), + Lru = case couch_db:is_system_db(Db) of + false -> couch_lru:update(DbName, Server0#server.lru); + true -> Server0#server.lru + end, + Server0#server{lru = Lru}; + _ -> + Server0 + catch _:_ -> + Server0 end, - {reply, ok, Server#server{lru = Lru}}. + {reply, ok, Server}. handle_cast({update_lru, DbName}, #server{lru = Lru, update_lru_on_read=true} = Server) -> {noreply, Server#server{lru = couch_lru:update(DbName, Lru)}};