Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Don't always require exactly N replies for an mp attachment PUT
Browse files Browse the repository at this point in the history
It's not safe to assume we require, or will receive, exactly N replies
(where N is read from the "n" key of the "cluster" section of the
configuaration). This needs proper fabric-ification.

This commit will at least allow replication tests with clusters of
less than N nodes where the documents have attachments (which triggers
the multipart code).

BugzID: 14258
  • Loading branch information
Robert Newson committed Aug 9, 2012
1 parent 90dcfeb commit 1cea79d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/couch/src/couch_doc.erl
Expand Up @@ -541,7 +541,7 @@ mp_parse_atts({body, Bytes}, {DataList, Offset, Counters, Waiting}) ->
NewAcc = maybe_send_data({DataList++[Bytes], Offset, Counters, Waiting}), NewAcc = maybe_send_data({DataList++[Bytes], Offset, Counters, Waiting}),
fun(Next) -> mp_parse_atts(Next, NewAcc) end; fun(Next) -> mp_parse_atts(Next, NewAcc) end;
mp_parse_atts(eof, {DataList, Offset, Counters, Waiting}) -> mp_parse_atts(eof, {DataList, Offset, Counters, Waiting}) ->
N = list_to_integer(couch_config:get("cluster", "n", "3")), N = n(),
M = length(Counters), M = length(Counters),
case (M == N) andalso DataList == [] of case (M == N) andalso DataList == [] of
true -> true ->
Expand Down Expand Up @@ -581,7 +581,7 @@ maybe_send_data({ChunkList, Offset, Counters, Waiting}) ->
SmallestIndex = lists:min(element(2, lists:unzip(Counters))) SmallestIndex = lists:min(element(2, lists:unzip(Counters)))
end, end,
Size = length(Counters), Size = length(Counters),
N = list_to_integer(couch_config:get("cluster", "n", "3")), N = n(),
if Size == N andalso SmallestIndex == (Offset+1) -> if Size == N andalso SmallestIndex == (Offset+1) ->
NewChunkList = tl(ChunkList), NewChunkList = tl(ChunkList),
NewOffset = Offset+1; NewOffset = Offset+1;
Expand Down Expand Up @@ -619,3 +619,11 @@ abort_multi_part_stream(Parser, MonRef) ->
false -> false ->
erlang:demonitor(MonRef, [flush]) erlang:demonitor(MonRef, [flush])
end. end.

% This exists to permit testing in small clusters (<3). A better fix
% would use the database's own N value and would consider only the
% nodes which hold at least one shard of the database.
n() ->
N = list_to_integer(couch_config:get("cluster", "n", "3")),
NodeCount = length(nodes()) + 1,
erlang:min(N, NodeCount).

0 comments on commit 1cea79d

Please sign in to comment.