Skip to content

Commit

Permalink
Crash if duplicates are detected during view compaction, COUCHDB-999
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.0.x@1054784 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
kocolosk committed Jan 3, 2011
1 parent 08d7184 commit 50ee63a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/couchdb/couch_view_compactor.erl
Expand Up @@ -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}) ->
Expand Down

0 comments on commit 50ee63a

Please sign in to comment.