Skip to content

Instantly share code, notes, and snippets.

@rnewson
Created March 21, 2013 23:39
Show Gist options
  • Save rnewson/5217822 to your computer and use it in GitHub Desktop.
Save rnewson/5217822 to your computer and use it in GitHub Desktop.
commit d59a596838ff94c01e17a1a0c7164727e2638169
Author: Robert Newson <robert.newson@cloudant.com>
Date: 2012-08-09 14:05:02 +0100
Don't always require exactly N replies for an mp attachment PUT
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
diff --git a/apps/couch/src/couch_doc.erl b/apps/couch/src/couch_doc.erl
index f24f031..f3f1af6 100644
--- a/apps/couch/src/couch_doc.erl
+++ b/apps/couch/src/couch_doc.erl
@@ -541,7 +541,7 @@ mp_parse_atts({body, Bytes}, {DataList, Offset, Counters, Waiting}) ->
NewAcc = maybe_send_data({DataList++[Bytes], Offset, Counters, Waiting}),
fun(Next) -> mp_parse_atts(Next, NewAcc) end;
mp_parse_atts(eof, {DataList, Offset, Counters, Waiting}) ->
- N = list_to_integer(couch_config:get("cluster", "n", "3")),
+ N = n(),
M = length(Counters),
case (M == N) andalso DataList == [] of
true ->
@@ -581,7 +581,7 @@ maybe_send_data({ChunkList, Offset, Counters, Waiting}) ->
SmallestIndex = lists:min(element(2, lists:unzip(Counters)))
end,
Size = length(Counters),
- N = list_to_integer(couch_config:get("cluster", "n", "3")),
+ N = n(),
if Size == N andalso SmallestIndex == (Offset+1) ->
NewChunkList = tl(ChunkList),
NewOffset = Offset+1;
@@ -619,3 +619,11 @@ abort_multi_part_stream(Parser, MonRef) ->
false ->
erlang:demonitor(MonRef, [flush])
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).
➜ bigcouchplus git:(master) ✗
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment