diff options
author | Adam Kocoloski <kocolosk@apache.org> | 2011-01-03 21:45:47 +0000 |
---|---|---|
committer | Adam Kocoloski <kocolosk@apache.org> | 2011-01-03 21:45:47 +0000 |
commit | 50ee63aa35b3d7a180cfeacc190924bb7fac3273 (patch) | |
tree | e3b870a919f1b3b10de4beb2b1d376299e459735 | |
parent | 08d71849464a8e1cc869b385591fa00b3ad0f843 (diff) |
Crash if duplicates are detected during view compaction, COUCHDB-999
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.0.x@1054784 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/couchdb/couch_view_compactor.erl | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/couchdb/couch_view_compactor.erl b/src/couchdb/couch_view_compactor.erl index 895556bf..9a47f5f8 100644 --- a/src/couchdb/couch_view_compactor.erl +++ b/src/couchdb/couch_view_compactor.erl @@ -48,18 +48,22 @@ compact_group(Group, EmptyGroup) -> TaskName = <<DbName/binary, ShortName/binary>>, couch_task_status:add_task(<<"View Group Compaction">>, TaskName, <<"">>), - Fun = fun(KV, {Bt, Acc, TotalCopied}) -> + Fun = fun({DocId, _ViewIdKeys} = KV, {Bt, Acc, TotalCopied, LastId}) -> + if DocId =:= LastId -> % COUCHDB-999 + Msg = "Duplicates of ~s detected in ~s ~s - rebuild required", + exit(io_lib:format(Msg, [DocId, DbName, GroupId])); + true -> ok end, if TotalCopied rem 10000 =:= 0 -> couch_task_status:update("Copied ~p of ~p Ids (~p%)", [TotalCopied, Count, (TotalCopied*100) div Count]), {ok, Bt2} = couch_btree:add(Bt, lists:reverse([KV|Acc])), - {ok, {Bt2, [], TotalCopied+1}}; + {ok, {Bt2, [], TotalCopied+1, DocId}}; true -> - {ok, {Bt, [KV|Acc], TotalCopied+1}} + {ok, {Bt, [KV|Acc], TotalCopied+1, DocId}} end end, - {ok, _, {Bt3, Uncopied, _Total}} = couch_btree:foldl(IdBtree, Fun, - {EmptyIdBtree, [], 0}), + {ok, _, {Bt3, Uncopied, _Total, _LastId}} = couch_btree:foldl(IdBtree, Fun, + {EmptyIdBtree, [], 0, nil}), {ok, NewIdBtree} = couch_btree:add(Bt3, lists:reverse(Uncopied)), NewViews = lists:map(fun({View, EmptyView}) -> |