couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [1/2] git commit: Assert that index sig never changes in the lifetime of a couch index process
Date Thu, 09 Aug 2012 16:20:27 GMT
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 <rnewson@apache.org>
Authored: Thu Aug 9 16:06:57 2012 +0100
Committer: Robert Newson <rnewson@apache.org>
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.


Mime
View raw message