anchor.diff:                        SafeSeqs
                 end
         end, [], capi_ddoc_replication_srv:fetch_ddoc_ids(BucketName)).
  +
  +spawn_ddoc_replicator(ServerName) ->
  +    proc_lib:spawn_link(
  +      fun () ->
  +              ddoc_replicator_loop(ServerName, [])
  +      end).
  +
  +ddoc_replicator_loop(ServerName, RemoteNodes) ->
  +    NewRemoteNodes =
  +        receive
  +            {replicate_change, Doc} ->
  +                [replicate_change_to_node(ServerName, Node, Doc)
  +                 || Node <- RemoteNodes],
  +                RemoteNodes;
  +            {replicate_newnodes_docs, AllNodes, Docs} ->
  +                ?log_debug("doing replicate_newnodes_docs"),
  +
  +                NewNodes = AllNodes -- RemoteNodes,
  +                case NewNodes of
  +                    [] ->
  +                        ok;
  +                    _ ->
  +                        [monitor(process, {ServerName, Node}) || Node <- NewNodes],
  +                        [replicate_change_to_node(ServerName, S, D)
  +                         || S <- NewNodes,
  +                            D <- Docs]
  +                end,
  +                AllNodes;
  +            {'DOWN', _Ref, _Type, {Server, RemoteNode}, Error} ->
  +                ?log_warning("Remote server node ~p process down: ~p",
  +                             [{Server, RemoteNode}, Error]),
  +                RemoteNodes -- [RemoteNode];
  +            Msg ->
  +                ?log_error("Got unexpected message: ~p", [Msg]),
  +                exit({unexpected_message, Msg})
  +        end,
  +
  +    ddoc_replicator_loop(ServerName, NewRemoteNodes).
  +
  +replicate_change_to_node(ServerName, Node, Doc) ->
  +    ?log_debug("Sending ~s to ~s", [Doc#doc.id, Node]),
  +    gen_server:cast({ServerName, Node}, {replicated_update, Doc}).
  +
  +get_remote_nodes(Bucket) ->
  +    case ns_bucket:get_bucket(Bucket) of
  +        {ok, Conf} ->
  +            proplists:get_value(servers, Conf) -- [node()];
  +        not_present ->
  +            []
  +    end.
  
positive.code:     [{ServerName, N} ! replicate_newnodes_docs ||
          N <- get_remote_nodes(Bucket)],
  
      State = #state{bucket=Bucket,
                     proxy_server_name = ServerName,
                     local_docs = Docs,
                     num_vbuckets = NumVBuckets,
                     use_replica_index=UseReplicaIndex,
                     wanted_states = [],
                     rebalance_states = []},
  
      proc_lib:init_ack({ok, self()}),
  
  
negative.code: -include("ns_common.hrl").
  
  -record(state, {bucket :: bucket_name(),
                  local_docs = [] :: [#doc{}],
                  num_vbuckets :: non_neg_integer(),
                  use_replica_index :: boolean(),
                  master_db_watcher :: pid(),
                  wanted_states :: [missing | active | replica],
                  rebalance_states :: [rebalance_vbucket_state()],
                  ddoc_replicator :: pid()}).
  
  set_vbucket_states(Bucket, WantedStates, RebalanceStates) ->
      gen_server:call(server(Bucket), {set_vbucket_states, WantedStates, RebalanceStates}, infinity).
  