You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2017/03/01 16:38:15 UTC

[17/50] fabric commit: updated refs/heads/2971-count-distinct to 5d18415

Update all shards with stale=update_after
Trigger an update for all the shards. Will send a message to trigger
an update to shards that won't participate in the response due to not
being a ushard.

COUCHDB-3150


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/commit/bea6b00e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/tree/bea6b00e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/diff/bea6b00e

Branch: refs/heads/2971-count-distinct
Commit: bea6b00ef5d15ddc5f062a09dacecb1d4d52a6ce
Parents: b534034
Author: brkolla <bk...@cloudant.com>
Authored: Wed Sep 21 14:29:15 2016 -0400
Committer: brkolla <bk...@cloudant.com>
Committed: Fri Sep 23 11:31:32 2016 -0400

----------------------------------------------------------------------
 src/fabric_rpc.erl         | 10 +++++++++-
 src/fabric_view.erl        |  9 ++++++++-
 src/fabric_view_map.erl    |  4 +++-
 src/fabric_view_reduce.erl |  4 +++-
 4 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/bea6b00e/src/fabric_rpc.erl
----------------------------------------------------------------------
diff --git a/src/fabric_rpc.erl b/src/fabric_rpc.erl
index b7f4fec..2079ae8 100644
--- a/src/fabric_rpc.erl
+++ b/src/fabric_rpc.erl
@@ -22,7 +22,7 @@
 -export([compact/1, compact/2]).
 
 -export([get_db_info/2, get_doc_count/2, get_update_seq/2,
-         changes/4, map_view/5, reduce_view/5, group_info/3]).
+         changes/4, map_view/5, reduce_view/5, group_info/3, update_mrview/4]).
 
 -include_lib("fabric/include/fabric.hrl").
 -include_lib("couch/include/couch_db.hrl").
@@ -99,6 +99,14 @@ all_docs(DbName, Options, #mrargs{keys=undefined} = Args0) ->
     VAcc0 = #vacc{db=Db},
     couch_mrview:query_all_docs(Db, Args, fun view_cb/2, VAcc0).
 
+update_mrview(DbName, {DDocId, Rev}, ViewName, Args0) ->
+    {ok, DDoc} = ddoc_cache:open_doc(mem3:dbname(DbName), DDocId, Rev),
+    couch_util:with_db(DbName, fun(Db) ->
+        UpdateSeq = couch_db:get_update_seq(Db),
+        {ok, Pid, _} = couch_mrview:get_view_index_pid(Db, DDoc, ViewName,                                                Args0),
+        couch_index:get_state(Pid, UpdateSeq)
+    end).
+
 %% @equiv map_view(DbName, DDoc, ViewName, Args0, [])
 map_view(DbName, DDocInfo, ViewName, Args0) ->
     map_view(DbName, DDocInfo, ViewName, Args0, []).

http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/bea6b00e/src/fabric_view.erl
----------------------------------------------------------------------
diff --git a/src/fabric_view.erl b/src/fabric_view.erl
index 50896cf..b86d7dc 100644
--- a/src/fabric_view.erl
+++ b/src/fabric_view.erl
@@ -15,7 +15,7 @@
 -export([is_progress_possible/1, remove_overlapping_shards/2, maybe_send_row/1,
     transform_row/1, keydict/1, extract_view/4, get_shards/2,
     check_down_shards/2, handle_worker_exit/3,
-    get_shard_replacements/2]).
+    get_shard_replacements/2, maybe_update_others/5]).
 
 -include_lib("fabric/include/fabric.hrl").
 -include_lib("mem3/include/mem3.hrl").
@@ -308,6 +308,13 @@ get_shards(DbName, #mrargs{stale=Stale})
 get_shards(DbName, #mrargs{stale=false}) ->
     mem3:shards(DbName).
 
+maybe_update_others(DbName, DDoc, ShardsInvolved, ViewName,
+    #mrargs{stale=update_after} = Args) ->
+    ShardsNeedUpdated = mem3:shards(DbName) -- ShardsInvolved,
+    lists:foreach(fun(#shard{node=Node, name=ShardName}) ->
+        rpc:cast(Node, fabric_rpc, update_mrview, [ShardName, DDoc, ViewName, Args])
+    end, ShardsNeedUpdated).
+
 get_shard_replacements(DbName, UsedShards0) ->
     % We only want to generate a replacements list from shards
     % that aren't already used.

http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/bea6b00e/src/fabric_view_map.erl
----------------------------------------------------------------------
diff --git a/src/fabric_view_map.erl b/src/fabric_view_map.erl
index a71e01a..63215e1 100644
--- a/src/fabric_view_map.erl
+++ b/src/fabric_view_map.erl
@@ -25,8 +25,10 @@ go(DbName, GroupId, View, Args, Callback, Acc, VInfo) when is_binary(GroupId) ->
 
 go(DbName, DDoc, View, Args, Callback, Acc, VInfo) ->
     Shards = fabric_view:get_shards(DbName, Args),
+    DocIdAndRev = fabric_util:doc_id_and_rev(DDoc),
+    fabric_view:maybe_update_others(DbName, DocIdAndRev, Shards, View, Args),
     Repls = fabric_view:get_shard_replacements(DbName, Shards),
-    RPCArgs = [fabric_util:doc_id_and_rev(DDoc), View, Args],
+    RPCArgs = [DocIdAndRev, View, Args],
     StartFun = fun(Shard) ->
         hd(fabric_util:submit_jobs([Shard], fabric_rpc, map_view, RPCArgs))
     end,

http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/bea6b00e/src/fabric_view_reduce.erl
----------------------------------------------------------------------
diff --git a/src/fabric_view_reduce.erl b/src/fabric_view_reduce.erl
index a638ff7..e6146b0 100644
--- a/src/fabric_view_reduce.erl
+++ b/src/fabric_view_reduce.erl
@@ -24,8 +24,10 @@ go(DbName, GroupId, View, Args, Callback, Acc0, VInfo) when is_binary(GroupId) -
     go(DbName, DDoc, View, Args, Callback, Acc0, VInfo);
 
 go(DbName, DDoc, VName, Args, Callback, Acc, VInfo) ->
-    RPCArgs = [fabric_util:doc_id_and_rev(DDoc), VName, Args],
+    DocIdAndRev = fabric_util:doc_id_and_rev(DDoc),
+    RPCArgs = [DocIdAndRev, VName, Args],
     Shards = fabric_view:get_shards(DbName, Args),
+    fabric_view:maybe_update_others(DbName, DocIdAndRev, Shards, VName, Args),
     Repls = fabric_view:get_shard_replacements(DbName, Shards),
     StartFun = fun(Shard) ->
         hd(fabric_util:submit_jobs([Shard], fabric_rpc, reduce_view, RPCArgs))