Skip to content

Commit 4e35046

Browse files
SimonUngemergify[bot]
authored andcommitted
Add ha-sync-mode as an operator policy
(cherry picked from commit 367b1f0) (cherry picked from commit 530a7f6)
1 parent 16ca37b commit 4e35046

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
@@ -52,10 +52,14 @@
5252
[operator_policy_validator, <<"ha-mode">>, ?MODULE]}},
5353
{mfa, {rabbit_registry, register,
5454
[operator_policy_validator, <<"ha-params">>, ?MODULE]}},
55+
{mfa, {rabbit_registry, register,
56+
[operator_policy_validator, <<"ha-sync-mode">>, ?MODULE]}},
5557
{mfa, {rabbit_registry, register,
5658
[policy_merge_strategy, <<"ha-mode">>, ?MODULE]}},
5759
{mfa, {rabbit_registry, register,
5860
[policy_merge_strategy, <<"ha-params">>, ?MODULE]}},
61+
{mfa, {rabbit_registry, register,
62+
[policy_merge_strategy, <<"ha-sync-mode">>, ?MODULE]}},
5963
{requires, rabbit_registry},
6064
{enables, recovery}]}).
6165

@@ -809,6 +813,8 @@ merge_policy_value(<<"ha-mode">>, <<"exactly">> = Val, _OpVal) ->
809813
Val;
810814
merge_policy_value(<<"ha-mode">>, _Val, <<"exactly">> = OpVal) ->
811815
OpVal;
816+
merge_policy_value(<<"ha-sync-mode">>, _Val, OpVal) ->
817+
OpVal;
812818
%% Both values are integers, both are ha-mode 'exactly'
813819
merge_policy_value(<<"ha-params">>, Val, OpVal) when is_integer(Val)
814820
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
@@ -167,12 +167,13 @@ target_count_policy(Config) ->
167167
{<<"ha-params">>, BNodes}],
168168
NodesPolicyOne = [{<<"ha-mode">>, <<"nodes">>},
169169
{<<"ha-params">>, [hd(BNodes)]}],
170+
SyncModePolicyAuto = [{<<"ha-mode">>, <<"all">>}, {<<"ha-sync-mode">>, <<"automatic">>}],
171+
SyncModePolicyMan = [{<<"ha-mode">>, <<"all">>}, {<<"ha-sync-mode">>, <<"manual">>}],
170172

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

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

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

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

0 commit comments

Comments
 (0)