You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2011/09/02 06:34:04 UTC
svn commit: r1164351 - in /couchdb/branches/1.1.x: ./ etc/default/couchdb
share/www/script/test/recreate_doc.js src/couchdb/couch_doc.erl
src/couchdb/couch_key_tree.erl
Author: davisp
Date: Fri Sep 2 04:34:04 2011
New Revision: 1164351
URL: http://svn.apache.org/viewvc?rev=1164351&view=rev
Log:
Fixes COUCHDB-1265
Backport of 1164350 from trunk. Slightly modified for an export
declaration conflict and removing a clause that only applies to
trunk.
Modified:
couchdb/branches/1.1.x/ (props changed)
couchdb/branches/1.1.x/etc/default/couchdb (props changed)
couchdb/branches/1.1.x/share/www/script/test/recreate_doc.js
couchdb/branches/1.1.x/src/couchdb/couch_doc.erl
couchdb/branches/1.1.x/src/couchdb/couch_key_tree.erl
Propchange: couchdb/branches/1.1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep 2 04:34:04 2011
@@ -6,4 +6,4 @@
/couchdb/branches/list-iterator:782292-784593
/couchdb/branches/tail_header:775760-778477
/couchdb/tags/0.10.0:825400
-/couchdb/trunk:1045203,1064417,1081107-1083320,1083714,1095523,1095557,1095569,1095581,1096098,1097300,1099479,1102006,1156506-1156509,1156610
+/couchdb/trunk:1045203,1064417,1081107-1083320,1083714,1095523,1095557,1095569,1095581,1096098,1097300,1099479,1102006,1156506-1156509,1156610,1164350
Propchange: couchdb/branches/1.1.x/etc/default/couchdb
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep 2 04:34:04 2011
@@ -6,5 +6,5 @@
/couchdb/branches/list-iterator/etc/default/couchdb:782292-784593
/couchdb/branches/tail_header/etc/default/couchdb:775760-778477
/couchdb/tags/0.10.0/etc/default/couchdb:825400
-/couchdb/trunk/etc/default/couchdb:1045203,1064417,1081107-1083320,1083714,1095523,1095557,1095569,1095581,1096098,1097300,1099479,1102006,1156506-1156509,1156610
+/couchdb/trunk/etc/default/couchdb:1045203,1064417,1081107-1083320,1083714,1095523,1095557,1095569,1095581,1096098,1097300,1099479,1102006,1156506-1156509,1156610,1164350
/incubator/couchdb/trunk/etc/default/couchdb:642419-694440
Modified: couchdb/branches/1.1.x/share/www/script/test/recreate_doc.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/www/script/test/recreate_doc.js?rev=1164351&r1=1164350&r2=1164351&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/www/script/test/recreate_doc.js (original)
+++ couchdb/branches/1.1.x/share/www/script/test/recreate_doc.js Fri Sep 2 04:34:04 2011
@@ -77,4 +77,45 @@ couchTests.recreate_doc = function(debug
} catch (e) {
T(e.error == "conflict");
}
+
+ db.deleteDb();
+ db.createDb();
+
+ // COUCHDB-1265
+ // Resuscitate an unavailable old revision and make sure that it
+ // doesn't introduce duplicates into the _changes feed.
+
+ var doc = {_id: "bar", count: 0};
+ T(db.save(doc).ok);
+ var ghost = {_id: "bar", _rev: doc._rev, count: doc.count};
+ for(var i = 0; i < 2; i++) {
+ doc.count += 1;
+ T(db.save(doc).ok);
+ }
+
+ // Compact so that the old revision to be resuscitated will be
+ // in the rev_tree as ?REV_MISSING
+ db.compact();
+ while(db.info().compact_running) {}
+
+ // Saving the ghost here puts it back in the rev_tree in such
+ // a way as to create a new update_seq but without changing a
+ // leaf revision. This would cause the #full_doc_info{} and
+ // #doc_info{} records to diverge in their idea of what the
+ // doc's update_seq is and end up introducing a duplicate in
+ // the _changes feed the next time this doc is updated.
+ T(db.save(ghost, {new_edits: false}).ok);
+
+ // The duplicate would have been introduce here becuase the #doc_info{}
+ // would not have been removed correctly.
+ T(db.save(doc).ok);
+
+ // And finally assert that there are no duplicates in _changes.
+ var req = CouchDB.request("GET", "/test_suite_db/_changes");
+ var resp = JSON.parse(req.responseText);
+ var docids = {};
+ for(var i = 0; i < resp.results.length; i++) {
+ T(docids[resp.results[i].id] === undefined, "Duplicates in _changes feed.");
+ docids[resp.results[i].id] = true;
+ }
};
Modified: couchdb/branches/1.1.x/src/couchdb/couch_doc.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_doc.erl?rev=1164351&r1=1164350&r2=1164351&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_doc.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_doc.erl Fri Sep 2 04:34:04 2011
@@ -302,10 +302,16 @@ to_doc_info(FullDocInfo) ->
{DocInfo, _Path} = to_doc_info_path(FullDocInfo),
DocInfo.
-max_seq([], Max) ->
- Max;
-max_seq([#rev_info{seq=Seq}|Rest], Max) ->
- max_seq(Rest, if Max > Seq -> Max; true -> Seq end).
+max_seq(Tree) ->
+ FoldFun = fun({_Pos, _Key}, Value, _Type, MaxOldSeq) ->
+ case Value of
+ {_Deleted, _DiskPos, OldTreeSeq} ->
+ erlang:max(MaxOldSeq, OldTreeSeq);
+ _ ->
+ MaxOldSeq
+ end
+ end,
+ couch_key_tree:fold(FoldFun, 0, Tree).
to_doc_info_path(#full_doc_info{id=Id,rev_tree=Tree}) ->
RevInfosAndPath =
@@ -320,7 +326,7 @@ to_doc_info_path(#full_doc_info{id=Id,re
end, RevInfosAndPath),
[{_RevInfo, WinPath}|_] = SortedRevInfosAndPath,
RevInfos = [RevInfo || {RevInfo, _Path} <- SortedRevInfosAndPath],
- {#doc_info{id=Id, high_seq=max_seq(RevInfos, 0), revs=RevInfos}, WinPath}.
+ {#doc_info{id=Id, high_seq=max_seq(Tree), revs=RevInfos}, WinPath}.
Modified: couchdb/branches/1.1.x/src/couchdb/couch_key_tree.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_key_tree.erl?rev=1164351&r1=1164350&r2=1164351&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_key_tree.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_key_tree.erl Fri Sep 2 04:34:04 2011
@@ -49,7 +49,7 @@
-export([merge/3, find_missing/2, get_key_leafs/2, get_full_key_paths/2, get/2]).
-export([map/2, get_all_leafs/1, count_leafs/1, remove_leafs/2,
- get_all_leafs_full/1,stem/2,map_leafs/2]).
+ get_all_leafs_full/1,stem/2,map_leafs/2, fold/3]).
-include("couch_db.hrl").
@@ -325,6 +325,21 @@ count_leafs_simple([{_Key, _Value, SubTr
count_leafs_simple(SubTree) + count_leafs_simple(RestTree).
+fold(_Fun, Acc, []) ->
+ Acc;
+fold(Fun, Acc0, [{Pos, Tree}|Rest]) ->
+ Acc1 = fold_simple(Fun, Acc0, Pos, [Tree]),
+ fold(Fun, Acc1, Rest).
+
+fold_simple(_Fun, Acc, _Pos, []) ->
+ Acc;
+fold_simple(Fun, Acc0, Pos, [{Key, Value, SubTree} | RestTree]) ->
+ Type = if SubTree == [] -> leaf; true -> branch end,
+ Acc1 = Fun({Pos, Key}, Value, Type, Acc0),
+ Acc2 = fold_simple(Fun, Acc1, Pos+1, SubTree),
+ fold_simple(Fun, Acc2, Pos, RestTree).
+
+
map(_Fun, []) ->
[];
map(Fun, [{Pos, Tree}|Rest]) ->