Skip to content

Commit 8760e72

Browse files
Merge pull request #8043 from SimonUnge/oper_policy_sync_mode
Add ha-sync-mode as an operator policy
2 parents 8079cf3 + 367b1f0 commit 8760e72

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,10 @@ end}.
776776
{datatype, [integer, {list, string}]}
777777
]}.
778778

779+
{mapping, "default_policies.operator.$id.classic_queues.ha_sync_mode", "rabbit.default_policies.operator", [
780+
{datatype, string}
781+
]}.
782+
779783
{translation, "rabbit.default_policies.operator", fun(Conf) ->
780784
Props = rabbit_cuttlefish:aggregate_props(
781785
Conf,

deps/rabbit/src/rabbit_mirror_queue_misc.erl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@
5454
[operator_policy_validator, <<"ha-mode">>, ?MODULE]}},
5555
{mfa, {rabbit_registry, register,
5656
[operator_policy_validator, <<"ha-params">>, ?MODULE]}},
57+
{mfa, {rabbit_registry, register,
58+
[operator_policy_validator, <<"ha-sync-mode">>, ?MODULE]}},
5759
{mfa, {rabbit_registry, register,
5860
[policy_merge_strategy, <<"ha-mode">>, ?MODULE]}},
5961
{mfa, {rabbit_registry, register,
6062
[policy_merge_strategy, <<"ha-params">>, ?MODULE]}},
63+
{mfa, {rabbit_registry, register,
64+
[policy_merge_strategy, <<"ha-sync-mode">>, ?MODULE]}},
6165
{requires, rabbit_registry},
6266
{enables, recovery}]}).
6367

@@ -870,6 +874,8 @@ merge_policy_value(<<"ha-mode">>, <<"exactly">> = Val, _OpVal) ->
870874
Val;
871875
merge_policy_value(<<"ha-mode">>, _Val, <<"exactly">> = OpVal) ->
872876
OpVal;
877+
merge_policy_value(<<"ha-sync-mode">>, _Val, OpVal) ->
878+
OpVal;
873879
%% Both values are integers, both are ha-mode 'exactly'
874880
merge_policy_value(<<"ha-params">>, Val, OpVal) when is_integer(Val)
875881
andalso

deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,14 @@ ssl_options.fail_if_no_peer_cert = true",
142142
default_policies.operator.a.vhost_pattern = banana
143143
default_policies.operator.a.classic_queues.ha_mode = exactly
144144
default_policies.operator.a.classic_queues.ha_params = 2
145+
default_policies.operator.a.classic_queues.ha_sync_mode = automatic
146+
145147
",
146148
[{rabbit, [{default_policies, [{operator, [
147149
{<<"a">>, [{<<"expires">>, 3600000},
148150
{<<"ha_mode">>, "exactly"},
149151
{<<"ha_params">>, 2},
152+
{<<"ha_sync_mode">>, "automatic"},
150153
{<<"queue_pattern">>, "apple"},
151154
{<<"vhost_pattern">>, "banana"}]}]}]}]}],
152155
[]},

deps/rabbit/test/policy_SUITE.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,13 @@ target_count_policy(Config) ->
168168
{<<"ha-params">>, BNodes}],
169169
NodesPolicyOne = [{<<"ha-mode">>, <<"nodes">>},
170170
{<<"ha-params">>, [hd(BNodes)]}],
171+
SyncModePolicyAuto = [{<<"ha-mode">>, <<"all">>}, {<<"ha-sync-mode">>, <<"automatic">>}],
172+
SyncModePolicyMan = [{<<"ha-mode">>, <<"all">>}, {<<"ha-sync-mode">>, <<"manual">>}],
171173

172174
%% ALL has precedence
173175
Opts = #{config => Config,
174176
server => Server,
175177
qname => QName},
176-
177178
verify_policies(AllPolicy, ExactlyPolicyTwo, [{<<"ha-mode">>, <<"all">>}], Opts),
178179

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

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

186+
%% %% Sync mode OperPolicy has precedence
187+
verify_policies(SyncModePolicyMan, SyncModePolicyAuto, [{<<"ha-sync-mode">>, <<"automatic">>}], Opts),
188+
verify_policies(SyncModePolicyAuto, SyncModePolicyMan, [{<<"ha-sync-mode">>, <<"manual">>}], Opts),
189+
185190
%% exactly has precedence over nodes
186191
verify_policies(ExactlyPolicyTwo, NodesPolicyAll,[{<<"ha-mode">>, <<"exactly">>}, {<<"ha-params">>, 2}], Opts),
187192

0 commit comments

Comments
 (0)