anchor.diff:  -export([cleanup/3, current_states/2, graphviz/1]).
   
   cleanup(Bucket, Map, Servers) ->
  -    sanify(Bucket, Map, Servers),
  +    case sanify(Bucket, Map, Servers) of
  +        Map -> ok;
  +        Map1 ->
  +            error_logger:info_msg("~p:sanify changed map: ~p~n", [?MODULE, Map1]),
  +            ns_bucket:set_map(Bucket, Map1)
  +    end,
       Replicas = lists:keysort(1, map_to_replicas(Map)),
       ReplicaGroups = lists:ukeymerge(1, misc:keygroup(1, Replicas),
                                       [{N, []} || N <- lists:sort(Servers)]),
  
positive.code:                               ns_memcached:set_vbucket_state(
                                  N, Bucket, VBucket, dead)
                        end
                end, ExtraStates);
          [{Master, State}|ReplicaStates] ->
              case [N||{N, RState} <- ReplicaStates ++ ExtraStates,
                       lists:member(RState, [active, pending, replica])] of
                  [] ->
                      error_logger:info_msg("~p:sanify: Setting master ~p for (hopefully new) vbucket ~p from ~p to active~n",
                                            [?MODULE, Master, VBucket, State]),
                      ns_memcached:set_vbucket_state(Master, Bucket, VBucket, active);
                  X ->
                      error_logger:error_msg("~p:sanify: Master ~p in state ~p for vbucket ~p but we have extra nodes ~p!~n",
                                             [?MODULE, Master, State, VBucket, X])
              end
      end,
      sanify(Bucket, States, Map, VBucket+1).
  
  %% [{Node, VBucket, State}...]
  -spec current_states(list(atom()), string()) ->
  
negative.code:                     error_logger:info_msg(
                        "~p:sanify: Setting master ~p from ~p to active for vbucket ~p~n",
                        [?MODULE, Master, State, VBucket]),
                      ns_memcached:set_vbucket_state(Master, Bucket, VBucket, active),
                      Chain;
                  [Node] ->
                      %% One active node, but it's not the master
                      case lists:position(Node, Chain) of
                          undefined ->
                              %% It's an extra node
                              error_logger:info_msg(
                                "~p:sanify: Master for vbucket ~p is not active, but ~p is, so making that the master.~n",
                                [?MODULE, VBucket, Node]),
                              [Node|lists:duplicate(length(Chain) - 1,
                                                    undefined)];
                          Pos ->
                              [Node|lists:nthtail(1, Pos)]
                      end;
                  Nodes ->
                      error_logger:error_msg(
                        "~p:sanify: Extra active nodes ~p for vbucket ~p. This should never happen!~n",
                        [?MODULE, Nodes, VBucket]),
                      Chain
              end;
          C = [{_, active}|ReplicaStates] ->
              lists:foreach(
  