Skip to content

Commit

Permalink
Merge pull request #8045 from rabbitmq/mergify/bp/v3.11.x/pr-8044
Browse files Browse the repository at this point in the history
Add ha-sync-mode as an operator policy (backport #8043) (backport #8044)
  • Loading branch information
michaelklishin authored Apr 27, 2023
2 parents 16ca37b + 4e35046 commit 57058d2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions deps/rabbit/priv/schema/rabbit.schema
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,10 @@ end}.
{datatype, [integer, {list, string}]}
]}.

{mapping, "default_policies.operator.$id.classic_queues.ha_sync_mode", "rabbit.default_policies.operator", [
{datatype, string}
]}.

{translation, "rabbit.default_policies.operator", fun(Conf) ->
Props = rabbit_cuttlefish:aggregate_props(
Conf,
Expand Down
6 changes: 6 additions & 0 deletions deps/rabbit/src/rabbit_mirror_queue_misc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@
[operator_policy_validator, <<"ha-mode">>, ?MODULE]}},
{mfa, {rabbit_registry, register,
[operator_policy_validator, <<"ha-params">>, ?MODULE]}},
{mfa, {rabbit_registry, register,
[operator_policy_validator, <<"ha-sync-mode">>, ?MODULE]}},
{mfa, {rabbit_registry, register,
[policy_merge_strategy, <<"ha-mode">>, ?MODULE]}},
{mfa, {rabbit_registry, register,
[policy_merge_strategy, <<"ha-params">>, ?MODULE]}},
{mfa, {rabbit_registry, register,
[policy_merge_strategy, <<"ha-sync-mode">>, ?MODULE]}},
{requires, rabbit_registry},
{enables, recovery}]}).

Expand Down Expand Up @@ -809,6 +813,8 @@ merge_policy_value(<<"ha-mode">>, <<"exactly">> = Val, _OpVal) ->
Val;
merge_policy_value(<<"ha-mode">>, _Val, <<"exactly">> = OpVal) ->
OpVal;
merge_policy_value(<<"ha-sync-mode">>, _Val, OpVal) ->
OpVal;
%% Both values are integers, both are ha-mode 'exactly'
merge_policy_value(<<"ha-params">>, Val, OpVal) when is_integer(Val)
andalso
Expand Down
3 changes: 3 additions & 0 deletions deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,14 @@ ssl_options.fail_if_no_peer_cert = true",
default_policies.operator.a.vhost_pattern = banana
default_policies.operator.a.classic_queues.ha_mode = exactly
default_policies.operator.a.classic_queues.ha_params = 2
default_policies.operator.a.classic_queues.ha_sync_mode = automatic
",
[{rabbit, [{default_policies, [{operator, [
{<<"a">>, [{<<"expires">>, 3600000},
{<<"ha_mode">>, "exactly"},
{<<"ha_params">>, 2},
{<<"ha_sync_mode">>, "automatic"},
{<<"queue_pattern">>, "apple"},
{<<"vhost_pattern">>, "banana"}]}]}]}]}],
[]},
Expand Down
7 changes: 6 additions & 1 deletion deps/rabbit/test/policy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ target_count_policy(Config) ->
{<<"ha-params">>, BNodes}],
NodesPolicyOne = [{<<"ha-mode">>, <<"nodes">>},
{<<"ha-params">>, [hd(BNodes)]}],
SyncModePolicyAuto = [{<<"ha-mode">>, <<"all">>}, {<<"ha-sync-mode">>, <<"automatic">>}],
SyncModePolicyMan = [{<<"ha-mode">>, <<"all">>}, {<<"ha-sync-mode">>, <<"manual">>}],

%% ALL has precedence
Opts = #{config => Config,
server => Server,
qname => QName},

verify_policies(AllPolicy, ExactlyPolicyTwo, [{<<"ha-mode">>, <<"all">>}], Opts),

verify_policies(ExactlyPolicyTwo, AllPolicy, [{<<"ha-mode">>, <<"all">>}], Opts),
Expand All @@ -181,6 +182,10 @@ target_count_policy(Config) ->

verify_policies(NodesPolicyAll, AllPolicy, [{<<"ha-mode">>, <<"all">>}], Opts),

%% %% Sync mode OperPolicy has precedence
verify_policies(SyncModePolicyMan, SyncModePolicyAuto, [{<<"ha-sync-mode">>, <<"automatic">>}], Opts),
verify_policies(SyncModePolicyAuto, SyncModePolicyMan, [{<<"ha-sync-mode">>, <<"manual">>}], Opts),

%% exactly has precedence over nodes
verify_policies(ExactlyPolicyTwo, NodesPolicyAll,[{<<"ha-mode">>, <<"exactly">>}, {<<"ha-params">>, 2}], Opts),

Expand Down

0 comments on commit 57058d2

Please sign in to comment.