You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by gi...@git.apache.org on 2017/05/05 19:27:48 UTC

[GitHub] nickva commented on a change in pull request #484: Apply random jitter during initial _replicator shard discovery

nickva commented on a change in pull request #484: Apply random jitter during initial _replicator shard discovery
URL: https://github.com/apache/couchdb/pull/484#discussion_r115071338
 
 

 ##########
 File path: src/couch/src/couch_multidb_changes.erl
 ##########
 @@ -257,40 +257,54 @@ scan_all_dbs(Server, DbSuffix) when is_pid(Server) ->
     {ok, Db} = mem3_util:ensure_exists(
         config:get("mem3", "shards_db", "_dbs")),
     ChangesFun = couch_changes:handle_changes(#changes_args{}, nil, Db, nil),
-    ChangesFun(fun({change, {Change}, _}, _) ->
-        DbName = couch_util:get_value(<<"id">>, Change),
-        case DbName of
-            <<"_design/", _/binary>> ->
-                ok;
-            _Else ->
-                case couch_replicator_utils:is_deleted(Change) of
-                    true ->
-                        ok;
-                    false ->
-                        [gen_server:cast(Server, {resume_scan, ShardName})
-                         || ShardName <- filter_shards(DbName, DbSuffix)],
-                        ok
-                end
-        end;
-        (_, _) -> ok
-    end),
+    ChangesFun({fun scan_changes_cb/3, {Server, DbSuffix, 1}}),
     couch_db:close(Db).
 
 
-filter_shards(DbName, DbSuffix) ->
-    case DbSuffix =:= couch_db:dbname_suffix(DbName) of
-    false ->
-        [];
-    true ->
-        try
-            [ShardName || #shard{name = ShardName} <- mem3:local_shards(DbName)]
-        catch
-            error:database_does_not_exist ->
-                []
+scan_changes_cb({change, {Change}, _}, _, {_Server, DbSuffix, _Count} = Acc) ->
+    DbName = couch_util:get_value(<<"id">>, Change),
+    case DbName of <<"_design/", _/binary>> -> Acc; _Else ->
+        NameMatch = DbSuffix =:= couch_db:dbname_suffix(DbName),
+        case {NameMatch, couch_replicator_utils:is_deleted(Change)} of
+            {false, _} ->
+                Acc;
+            {true, true} ->
+                Acc;
+            {true, false} ->
+                Shards = local_shards(DbName),
+                lists:foldl(fun notify_fold/2, Acc, Shards)
         end
+    end;
+scan_changes_cb(_, _, Acc) ->
+    Acc.
+
+
+local_shards(DbName) ->
+    try
+        [ShardName || #shard{name = ShardName} <- mem3:local_shards(DbName)]
+    catch
+        error:database_does_not_exist ->
+            []
     end.
 
 
+notify_fold(DbName, {Server, DbSuffix, Count}) ->
+    Jitter = jitter(Count),
+    spawn_link(fun() ->
 
 Review comment:
   In this case we don't see it because it runs in the main server process. If it was running in side the spawned process we'd need to seed it.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services