anchor.diff:                        true
                 end
         end, NonPendingNodes).
  +
  +%% @doc Save the current state in ns_config
  +-spec make_state_persistent(State::#state{}) -> ok.
  +make_state_persistent(State) ->
  +    Enabled = case State#state.tick_ref of
  +        nil -> false;
  +        _ -> true
  +    end,
  +    ns_config:set(auto_failover_cfg,
  +                  [{enabled, Enabled},
  +                   {timeout, State#state.timeout},
  +                   {count, State#state.count}]).
  +
  +note_reported(Flag, State) ->
  +    false = element(Flag, State),
  +    setelement(Flag, State, true).
  +
  +should_report(Flag, State) ->
  +    not(element(Flag, State)).
  +
  +init_reported(State) ->
  +    State#state{reported_autofailover_unsafe=false}.
  +
  +update_reported_flags_by_actions(Actions, State) ->
  +    case lists:keymember(failover, 1, Actions) of
  +        false ->
  +            init_reported(State);
  +        true ->
  +            State
  +    end.
  +
  +
  +-ifdef(EUNIT).
   
   actual_down_nodes_inner_test() ->
       PList0 = [{a, ["bucket1", "bucket2"]},
  
positive.code:     ?log_debug("init auto_failover.", []),
      Timeout = proplists:get_value(timeout, Config),
      Count = proplists:get_value(count, Config),
      State = #state{timeout=Timeout,
                     count=Count,
                     auto_failover_logic_state = undefined},
      case proplists:get_value(enabled, Config) of
          true ->
              {reply, ok, State2} = handle_call(
                                      {enable_auto_failover, Timeout, 1},
                                      self(), State),
              {ok, State2};
          false ->
              {ok, State}
      end.
  
  init_logic_state(Timeout) ->
  
negative.code:                                {"bucket2", [{servers, [a, b, c]}]}])),
      ok.
  
  -define(FLAG, #state.reported_autofailover_unsafe).
  reported_test() ->
      %% nothing reported initially
      State = init_reported(#state{}),
  
      %% we correctly instructed to report the condition for the first time
      ?assertEqual(should_report(?FLAG, State), true),
      State1 = note_reported(?FLAG, State),
      State2 = update_reported_flags_by_actions([{failover, some_node}], State1),
  
      %% we don't report it second time
      ?assertEqual(should_report(?FLAG, State2), false),
  
      %% we report the condition again for the other "instance" of failover
      %% (i.e. failover is not needed for some time, but the it's needed again)
      State3 = update_reported_flags_by_actions([], State2),
      ?assertEqual(should_report(?FLAG, State3), true),
  
      %% we report the condition after we explicitly drop it (note that we use
      %% State2)
      State4 = init_reported(State2),
      ?assertEqual(should_report(?FLAG, State4), true),
  
      ok.
  
  -endif.
  