anchor.diff:  
   handle_cast(leave, State) ->
       ?cluster_log(0001, "Node ~p is leaving cluster.", [node()]),
  +
  +    ok = file:write_file(leave_marker_path(), <<"">>),
   
       %% first thing we do is stopping nearly everything
       ok = ns_server_cluster_sup:stop_cluster(),
  
positive.code: 
      ?cluster_debug("Leaving cluster", []),
      timer:sleep(1000),
      {ok, _} = ns_server_cluster_sup:start_cluster(),
      ns_ports_setup:restart_memcached(),
      {noreply, State}.
  
negative.code: 
  
  init([]) ->
      case file:read_file_info(leave_marker_path()) of
          {ok, _} ->
              ?log_info("found marker of in-flight cluster leave. Looks like previous leave procedure crashed. Going to complete leave cluster procedure"),
              %% we have to do it async because otherwise our parent
              %% supervisor is waiting us to complete init and our call
              %% to terminate ns_server_sup is going to cause deadlock
              gen_server:cast(self(), leave);
          _ ->
              ok
      end,
      {ok, #state{}}.
  
  
  