anchor.diff:              end
       end.
   
  -replicate_newnodes_docs(State) ->
  -    #state{bucket=Bucket,
  -           proxy_server_name = ServerName,
  -           remote_nodes=OldNodes,
  -           local_docs = Docs} = State,
  -    AllNodes = get_remote_nodes(Bucket),
  -    NewNodes = AllNodes -- OldNodes,
  -    case NewNodes of
  -        [] ->
  -            ok;
  -        _ ->
  -            [monitor(process, {ServerName, Node}) || Node <- NewNodes],
  -            [replicate_change_to_node(ServerName, S, D)
  -             || S <- NewNodes,
  -                D <- Docs]
  -    end,
  -    State#state{remote_nodes=AllNodes}.
  -
  -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.
  -
   open_local_db(Bucket) ->
       MasterVBucket = iolist_to_binary([Bucket, <<"/master">>]),
       case couch_db:open(MasterVBucket, []) of
  
positive.code:     try
          ?log_debug("Writing interactively saved ddoc ~p", [Doc]),
          SavedDocState = save_doc(NewDoc, State),
          replicate_change(SavedDocState, NewDoc),
          {reply, ok, SavedDocState}
      catch throw:{invalid_design_doc, _} = Error ->
              ?log_debug("Document validation failed: ~p", [Error]),
  
negative.code:                       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.
  