anchor.diff:          twig:log(debug, "adding ~s -> ~p to mem3_sync queue", [DbName, Node]),
           State#state{
               dict = dict:store({DbName,Node}, ok, D),
  -            waiting = Waiting ++ [{DbName,Node}]
  +            waiting = Waiting ++ [Job]
           }
       end.
   
  
positive.code:     {noreply, State}.
  
  terminate(_Reason, State) ->
      [exit(Pid, shutdown) || {_,_,Pid} <- State#state.active],
      ok.
  
  code_change(_OldVsn, State, _Extra) ->
      {ok, State}.
  
  handle_replication_exit(#state{waiting=[]} = State, Pid) ->
      NewActive = lists:keydelete(Pid, 3, State#state.active),
      {noreply, State#state{active=NewActive, count=length(NewActive)}};
  handle_replication_exit(State, Pid) ->
      #state{active=Active, limit=Limit, dict=D, waiting=Waiting} = State,
      Active1 = lists:keydelete(Pid, 3, Active),
      Count = length(Active1),
      NewState = if Count < Limit ->
          case next_replication(Active1, Waiting) of
          nil -> % all waiting replications are also active
              State#state{active = Active1, count = Count};
          {DbName, Node, StillWaiting} ->
              NewPid = start_push_replication(DbName, Node),
              State#state{
                  active = [{DbName, Node, NewPid} | Active1],
                  count = Count+1,
                  dict = dict:erase({DbName,Node}, D),
                  waiting = StillWaiting
  
negative.code:     end,
      {noreply, NewState}.
  
  start_push_replication(#job{name=Name, node=Node}) ->
      spawn_link(mem3_rep, go, [Name, Node]).
  
  add_to_queue(State, #job{name=DbName, node=Node} = Job) ->
      #state{dict=D, waiting=Waiting} = State,
      case dict:is_key({DbName, Node}, D) of
      true ->
  