You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2018/08/07 14:46:45 UTC

[couchdb] 02/04: Select only the shard containing the partition, if specified

This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch user-partitioned-dbs-4
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 0af921b17b66037b5d742b2e2e00f793a694d92c
Author: Robert Newson <rn...@apache.org>
AuthorDate: Mon Aug 6 19:16:09 2018 +0100

    Select only the shard containing the partition, if specified
---
 src/fabric/src/fabric_util.erl |  1 -
 src/fabric/src/fabric_view.erl | 27 +++++++++++++++++++++++----
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/fabric/src/fabric_util.erl b/src/fabric/src/fabric_util.erl
index dd4b80d..4d2f2c7 100644
--- a/src/fabric/src/fabric_util.erl
+++ b/src/fabric/src/fabric_util.erl
@@ -64,7 +64,6 @@ stream_start(Workers0, Keypos, StartFun, Replacements) ->
     Timeout = request_timeout(),
     case rexi_utils:recv(Workers0, Keypos, Fun, Acc, Timeout, infinity) of
         {ok, #stream_acc{workers=Workers}} ->
-            true = fabric_view:is_progress_possible(Workers),
             AckedWorkers = fabric_dict:fold(fun(Worker, From, WorkerAcc) ->
                 rexi:stream_start(From),
                 [Worker | WorkerAcc]
diff --git a/src/fabric/src/fabric_view.erl b/src/fabric/src/fabric_view.erl
index 69f4290..eae4cd6 100644
--- a/src/fabric/src/fabric_view.erl
+++ b/src/fabric/src/fabric_view.erl
@@ -309,10 +309,29 @@ index_of(X, [X|_Rest], I) ->
 index_of(X, [_|Rest], I) ->
     index_of(X, Rest, I+1).
 
-get_shards(DbName, #mrargs{stable=true}) ->
-    mem3:ushards(DbName);
-get_shards(DbName, #mrargs{stable=false}) ->
-    mem3:shards(DbName).
+
+get_shards(DbName, #mrargs{} = Args) ->
+    Partitioned = couch_mrview_util:get_extra(Args, partitioned),
+    case {Args#mrargs.stable, Partitioned} of
+        {true, false} ->
+            mem3:ushards(DbName);
+        {true, true} ->
+            mem3:ushards(DbName, partition_docid(Args));
+        {false, false} ->
+            mem3:shards(DbName);
+        {false, true} ->
+            mem3:shards(DbName, partition_docid(Args))
+    end.
+
+% create a fake docid within the specified partition.
+partition_docid(Args) ->
+    case couch_mrview_util:get_extra(Args, partition) of
+        undefined ->
+            undefined;
+        Partition when is_binary(Partition) ->
+            <<Partition/binary, ":foo">>
+    end.
+
 
 maybe_update_others(DbName, DDoc, ShardsInvolved, ViewName,
     #mrargs{update=lazy} = Args) ->