diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2014-05-09 14:56:49 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2014-05-09 14:56:49 +0100 |
| commit | 335d4e7bbe641e6e1112f6b89899fade9c251b90 (patch) | |
| tree | 113a894894f606eed4ca786f2aa7963648edb5df | |
| parent | a68bfc34e544ce0fb66088f5c0ad6e213dbe2528 (diff) | |
| download | rabbitmq-server-git-335d4e7bbe641e6e1112f6b89899fade9c251b90.tar.gz | |
Add a policy for this thing
| -rw-r--r-- | src/rabbit_mirror_queue_master.erl | 15 | ||||
| -rw-r--r-- | src/rabbit_mirror_queue_misc.erl | 26 |
2 files changed, 28 insertions, 13 deletions
diff --git a/src/rabbit_mirror_queue_master.erl b/src/rabbit_mirror_queue_master.erl index e8819bfa9c..792cebd129 100644 --- a/src/rabbit_mirror_queue_master.erl +++ b/src/rabbit_mirror_queue_master.erl @@ -176,13 +176,14 @@ terminate(Reason, %% Backing queue termination. The queue is going down but %% shouldn't be deleted. Most likely safe shutdown of this %% node. - {ok, #amqqueue{sync_slave_pids = SSPids}} = rabbit_amqqueue:lookup(QName), - %% TODO there should be a policy for this - case SSPids of - [] -> %% Remove the whole queue to avoid data loss - stop_all_slaves(Reason, nodelete, State); - _ -> %% Just let some other slave take over. - ok + {ok, Q = #amqqueue{sync_slave_pids = SSPids}} = + rabbit_amqqueue:lookup(QName), + case SSPids =:= [] andalso + rabbit_policy:get(<<"ha-promote-on-shutdown">>, Q) =/= <<"always">> of + true -> %% Remove the whole queue to avoid data loss + stop_all_slaves(Reason, State); + false -> %% Just let some other slave take over. + ok end, State #state { backing_queue_state = BQ:terminate(Reason, BQS) }. diff --git a/src/rabbit_mirror_queue_misc.erl b/src/rabbit_mirror_queue_misc.erl index b0f092a9a0..8ba6968c26 100644 --- a/src/rabbit_mirror_queue_misc.erl +++ b/src/rabbit_mirror_queue_misc.erl @@ -374,16 +374,21 @@ validate_policy(KeyList) -> Mode = proplists:get_value(<<"ha-mode">>, KeyList, none), Params = proplists:get_value(<<"ha-params">>, KeyList, none), SyncMode = proplists:get_value(<<"ha-sync-mode">>, KeyList, none), - case {Mode, Params, SyncMode} of - {none, none, none} -> + PromoteOnShutdown = proplists:get_value( + <<"ha-promote-on-shutdown">>, KeyList, none), + case {Mode, Params, SyncMode, PromoteOnShutdown} of + {none, none, none, none} -> ok; - {none, _, _} -> - {error, "ha-mode must be specified to specify ha-params or " - "ha-sync-mode", []}; + {none, _, _, _} -> + {error, "ha-mode must be specified to specify ha-params, " + "ha-sync-mode or ha-promote-on-shutdown", []}; _ -> case module(Mode) of {ok, M} -> case M:validate_policy(Params) of - ok -> validate_sync_mode(SyncMode); + ok -> case validate_sync_mode(SyncMode) of + ok -> validate_pos(PromoteOnShutdown); + E -> E + end; E -> E end; _ -> {error, "~p is not a valid ha-mode value", [Mode]} @@ -398,3 +403,12 @@ validate_sync_mode(SyncMode) -> Mode -> {error, "ha-sync-mode must be \"manual\" " "or \"automatic\", got ~p", [Mode]} end. + +validate_pos(PromoteOnShutdown) -> + case PromoteOnShutdown of + <<"always">> -> ok; + <<"when-synced">> -> ok; + none -> ok; + Mode -> {error, "ha-promote-on-shutdown must be " + "\"always\" or \"when-synced\", got ~p", [Mode]} + end. |
