You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/07 17:37:52 UTC

[30/50] couch commit: updated refs/heads/windsor-merge to 6e60cbe

Dedupe sequence ownership in epochs

We don't increase the update_seq when a node claims ownership of a
shard. This means that if a shard moves between nodes without a write we
can end up with two nodes claiming the same sequence. This just replaces
any duplicates with the more recent claim.


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

Branch: refs/heads/windsor-merge
Commit: 131322194d0809705be7f8d5a1a51e20ab6f9e07
Parents: 2ca323c
Author: Paul J. Davis <pa...@gmail.com>
Authored: Thu Oct 3 12:14:45 2013 -0500
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Aug 6 11:53:34 2014 +0100

----------------------------------------------------------------------
 src/couch_db_header.erl | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/13132219/src/couch_db_header.erl
----------------------------------------------------------------------
diff --git a/src/couch_db_header.erl b/src/couch_db_header.erl
index 1d743ef..c23cf38 100644
--- a/src/couch_db_header.erl
+++ b/src/couch_db_header.erl
@@ -236,7 +236,35 @@ upgrade_epochs(#db_header{}=Header) ->
             % and marking the update sequence where it happened.
             [{node(), Header#db_header.update_seq} | Epochs1]
     end,
-    Header#db_header{epochs=NewEpochs}.
+    % Its possible for a node to open a db and claim
+    % ownership but never make a write to the db. This
+    % removes nodes that claimed ownership but never
+    % changed the database.
+    DedupedEpochs = remove_dup_epochs(NewEpochs),
+    Header#db_header{epochs=DedupedEpochs}.
+
+
+% This is slightly relying on the udpate_seq's being sorted
+% in epochs due to how we only ever push things onto the
+% front. Although if we ever had a case where the update_seq
+% is not monotonically increasing I don't know that we'd
+% want to remove dupes (by calling a sort on the input to this
+% function). So for now we don't sort but are relying on the
+% idea that epochs is always sorted.
+remove_dup_epochs([_]=Epochs) ->
+    Epochs;
+remove_dup_epochs([{N1, S}, {_N2, S}]) ->
+    % Seqs match, keep the most recent owner
+    remove_dup_epochs([{N1, S}]);
+remove_dup_epochs([_, _]=Epochs) ->
+    % Seqs don't match.
+    Epochs;
+remove_dup_epochs([{N1, S}, {_N2, S} | Rest]) ->
+    % Seqs match, keep the most recent owner
+    remove_dup_epochs([{N1, S} | Rest]);
+remove_dup_epochs([{N1, S1}, {N2, S2} | Rest]) ->
+    % Seqs don't match, recurse to check others
+    remove_dup_epochs([{N1, S1} | remove_dup_epochs([{N2, S2} | Rest])]).
 
 
 -ifdef(TEST).