anchor.diff:      end.
   
   apply_map(Bucket, DDocs, OldMap, NewMap) ->
  -    ?log_debug("Applying map ~p to bucket ~s", [NewMap, Bucket]),
  -
  -    Active = proplists:get_value(active, NewMap),
  -    Passive = proplists:get_value(passive, NewMap),
  -    Ignore = proplists:get_value(ignore, NewMap),
  -
  -    ToRemove =
  -        case OldMap of
  -            undefined ->
  -                [];
  -            _ ->
  -                OldActive = proplists:get_value(active, OldMap),
  -                OldPassive = proplists:get_value(passive, OldMap),
  -                OldIgnore = proplists:get_value(ignore, OldMap),
  -
  -                (OldActive ++ OldPassive ++ OldIgnore) --
  -                    (Active ++ Passive ++ Ignore)
  -        end,
  -
  -    ?log_debug("Partitions to remove: ~p", [ToRemove]),
  +    ?log_info("Applying map to bucket ~s:~n~p", [Bucket, NewMap]),
  +
  +    {Active, Passive, Cleanup, Replica, ReplicaCleanup} =
  +        classify_vbuckets(OldMap, NewMap),
  +
  +    ?log_info("Classified vbuckets for ~s:~n"
  +              "Active: ~p~n"
  +              "Passive: ~p~n"
  +              "Cleanup: ~p~n"
  +              "Replica: ~p~n"
  +              "ReplicaCleanup: ~p",
  +              [Bucket, Active, Passive, Cleanup, Replica, ReplicaCleanup]),
   
       sets:fold(
         fun (DDocId, _) ->
  -              apply_ddoc_map(Bucket, DDocId, Active, Passive, ToRemove)
  +              apply_ddoc_map(Bucket, DDocId,
  +                             Active, Passive, Cleanup, Replica, ReplicaCleanup)
         end, undefined, DDocs).
   
   get_vbucket_state(Bucket, VBucket) ->
  
positive.code:             ok
      end.
  
  apply_ddoc_map(Bucket, DDocId, Active, Passive, ToRemove) ->
      SetName = list_to_binary(Bucket),
  
      try
          ok = couch_set_view:set_partition_states(SetName, DDocId,
                                                   Active, Passive, ToRemove)
      catch
          throw:{not_found, deleted} ->
              %% The document has been deleted but we still think it's
  
negative.code:          handle_info/2, terminate/2, code_change/3]).
  
  -define(SYNC_INTERVAL, 5000).
  -define(EMPTY_MAP, [{active, []}, {passive, []}, {replica, []}, {ignore, []}]).
  
  %% API
  -export([start_link/1, wait_until_added/3]).
  