anchor.diff:      catch
           throw:stopped ->
               fixup_replicas(Bucket, KeepNodes, EjectNodes),
  -            exit(stopped)
  +            exit(stopped);
  +        E:R ->
  +            fixup_replicas(Bucket, KeepNodes, EjectNodes),
  +            erlang:E(R)
       end.
   
   
  
positive.code:     end.
  
  
  %% @doc Ensure there are replicas for any unreplicated buckets if we stop.
  fixup_replicas(Bucket, KeepNodes, EjectNodes) ->
      {_, _, Map, _} = ns_bucket:config(Bucket),
  
negative.code:     DeactivateNodes = EjectNodes ++ FailedNodes,
      BucketConfigs = ns_bucket:get_buckets(),
      NumBuckets = length(BucketConfigs),
      try
          %% Eject failed nodes first so they don't cause trouble
          eject_nodes(FailedNodes -- [node()]),
          lists:foreach(fun ({I, {BucketName, BucketConfig}}) ->
                                BucketCompletion = I / NumBuckets,
                                ns_orchestrator:update_progress(
                                  dict:from_list([{N, BucketCompletion}
                                                  || N <- AllNodes])),
                                case proplists:get_value(type, BucketConfig) of
                                    memcached ->
                                        ns_bucket:set_servers(BucketName, KeepNodes);
                                    membase ->
                                        %% Only start one bucket at a time to avoid
                                        %% overloading things
                                        ns_bucket:set_servers(BucketName, LiveNodes),
                                        wait_for_memcached(LiveNodes, BucketName),
                                        ns_janitor:cleanup(BucketName),
                                        rebalance(BucketName, KeepNodes,
                                                  DeactivateNodes, BucketCompletion,
                                                  NumBuckets)
                                end
                        end, misc:enumerate(BucketConfigs, 0))
      catch
          E:R ->
              %% Eject this node since the orchestrator can still be running on a
              %% failed node (should be fixed)
              case lists:member(node(), FailedNodes) of
                  true ->
                      eject_nodes([node()]);
                  false ->
                      ok
              end,
              erlang:E(R)
      end,
      eject_nodes(DeactivateNodes).
  
  
  
  