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 6A1A3D1DC for ; Thu, 9 Aug 2012 16:20:28 +0000 (UTC) Received: (qmail 70917 invoked by uid 500); 9 Aug 2012 16:20:28 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 70741 invoked by uid 500); 9 Aug 2012 16:20:28 -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 70715 invoked by uid 99); 9 Aug 2012 16:20:27 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Aug 2012 16:20:27 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5BF253CCC3; Thu, 9 Aug 2012 16:20:27 +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 X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: Assert that index sig never changes in the lifetime of a couch index process Message-Id: <20120809162027.5BF253CCC3@tyr.zones.apache.org> Date: Thu, 9 Aug 2012 16:20:27 +0000 (UTC) Updated Branches: refs/heads/1.2.x bce1e60dc -> bb8397707 refs/heads/master 5ab712a23 -> bde29bea6 Assert that index sig never changes in the lifetime of a couch index process COUCHDB-1444 demonstrates that #st{} state get out of sync somehow, leading to unexpected 404's (missing_named_view) and 200's. This patch ensures that index sig never changes in the hope that it will lead to the cause of 1444 and prevent other occurrences of the same class of bug. Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/bde29bea Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/bde29bea Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/bde29bea Branch: refs/heads/master Commit: bde29bea6a4bdb5c73966524bd349335071262b5 Parents: 5ab712a Author: Robert Newson Authored: Thu Aug 9 16:06:57 2012 +0100 Committer: Robert Newson Committed: Thu Aug 9 16:49:48 2012 +0100 ---------------------------------------------------------------------- src/couch_index/src/couch_index.erl | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/bde29bea/src/couch_index/src/couch_index.erl ---------------------------------------------------------------------- diff --git a/src/couch_index/src/couch_index.erl b/src/couch_index/src/couch_index.erl index 5086048..5bf322e 100644 --- a/src/couch_index/src/couch_index.erl +++ b/src/couch_index/src/couch_index.erl @@ -171,6 +171,7 @@ handle_call({compacted, NewIdxState}, _From, State) -> updater=Updater, commit_delay=Delay } = State, + assert_signature_match(Mod, OldIdxState, NewIdxState), NewSeq = Mod:get(update_seq, NewIdxState), OldSeq = Mod:get(update_seq, OldIdxState), % For indices that require swapping files, we have to make sure we're @@ -210,7 +211,12 @@ handle_cast({updated, NewIdxState}, State) -> {noreply, NewState} end; handle_cast({new_state, NewIdxState}, State) -> - #st{mod=Mod, commit_delay=Delay} = State, + #st{ + mod=Mod, + idx_state=OldIdxState, + commit_delay=Delay + } = State, + assert_signature_match(Mod, OldIdxState, NewIdxState), CurrSeq = Mod:get(update_seq, NewIdxState), Args = [ Mod:get(db_name, NewIdxState), @@ -323,3 +329,9 @@ send_replies(Waiters, UpdateSeq, IdxState) -> {ToSend, Remaining} = lists:partition(Pred, Waiters), [gen_server:reply(From, {ok, IdxState}) || {From, _} <- ToSend], Remaining. + +assert_signature_match(Mod, OldIdxState, NewIdxState) -> + case {Mod:get(signature, OldIdxState), Mod:get(signature, NewIdxState)} of + {Sig, Sig} -> ok; + _ -> erlang:error(signature_mismatch) + end.