Skip to content

Commit 635412b

Browse files
committed
"formatting"
1 parent bdca316 commit 635412b

9 files changed

+408
-314
lines changed

deps/rabbitmq_stream/src/Elixir.RabbitMQ.CLI.Ctl.Commands.AddSuperStreamCommand.erl

+20-21
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ validate([], _Opts) ->
5656
validate([_Name], #{partitions := _, routing_keys := _}) ->
5757
{validation_failure,
5858
"Specify --partitions or routing-keys, not both."};
59-
validate([_Name], #{exchange_type := <<"x-super-stream">>, routing_keys := _}) ->
59+
validate([_Name],
60+
#{exchange_type := <<"x-super-stream">>, routing_keys := _}) ->
6061
{validation_failure,
6162
"Exchange type x-super-stream cannot be used with routing-keys."};
6263
validate([_Name], #{partitions := Partitions}) when Partitions < 1 ->
@@ -153,8 +154,7 @@ usage() ->
153154
"s <partitions>] [--routing-keys <routing-keys>]">>.
154155

155156
usage_additional() ->
156-
[[<<"<name>">>,
157-
<<"The name of the super stream.">>],
157+
[[<<"<name>">>, <<"The name of the super stream.">>],
158158
[<<"--vhost <vhost>">>,
159159
<<"The virtual host the super stream is added to.">>],
160160
[<<"--partitions <partitions>">>,
@@ -180,33 +180,33 @@ run([SuperStream],
180180
timeout := Timeout,
181181
partitions := Partitions} =
182182
Opts) ->
183-
Spec0 = maps:with([vhost,
184-
exchange_type], Opts),
185-
Spec = Spec0#{username => cli_acting_user(),
186-
name => SuperStream,
187-
partitions_source => {partition_count, Partitions},
188-
arguments => stream_arguments(Opts)},
183+
Spec0 = maps:with([vhost, exchange_type], Opts),
184+
Spec =
185+
Spec0#{username => cli_acting_user(),
186+
name => SuperStream,
187+
partitions_source => {partition_count, Partitions},
188+
arguments => stream_arguments(Opts)},
189189
create_super_stream(NodeName, Timeout, Spec);
190190
run([SuperStream],
191191
#{node := NodeName,
192192
timeout := Timeout,
193193
routing_keys := RoutingKeysStr} =
194194
Opts) ->
195-
Spec0 = maps:with([vhost,
196-
exchange_type], Opts),
197-
RoutingKeys =
198-
[K || K <- string:lexemes(RoutingKeysStr, ", ")],
199-
Spec = Spec0#{username => cli_acting_user(),
200-
name => SuperStream,
201-
partitions_source => {routing_keys, RoutingKeys},
202-
arguments => stream_arguments(Opts)},
195+
Spec0 = maps:with([vhost, exchange_type], Opts),
196+
RoutingKeys = [K || K <- string:lexemes(RoutingKeysStr, ", ")],
197+
Spec =
198+
Spec0#{username => cli_acting_user(),
199+
name => SuperStream,
200+
partitions_source => {routing_keys, RoutingKeys},
201+
arguments => stream_arguments(Opts)},
203202
create_super_stream(NodeName, Timeout, Spec).
204203

205204
stream_arguments(Opts) ->
206205
stream_arguments(#{}, Opts).
207206

208207
%% Something strange, dialyzer infers that map_size/1 returns positive_integer()
209208
-dialyzer({no_match, stream_arguments/2}).
209+
210210
stream_arguments(Acc, Arguments) when map_size(Arguments) =:= 0 ->
211211
Acc;
212212
stream_arguments(Acc, #{max_length_bytes := Value} = Arguments) ->
@@ -245,13 +245,12 @@ duration_to_seconds([{sign, _},
245245
{seconds, S}]) ->
246246
Y * 365 * 86400 + M * 30 * 86400 + D * 86400 + H * 3600 + Mn * 60 + S.
247247

248-
create_super_stream(NodeName,
249-
Timeout,
250-
Spec) ->
248+
create_super_stream(NodeName, Timeout, Spec) ->
251249
case rabbit_misc:rpc_call(NodeName,
252250
rabbit_stream_manager,
253251
create_super_stream,
254-
[Spec], Timeout)
252+
[Spec],
253+
Timeout)
255254
of
256255
ok ->
257256
{ok,

deps/rabbitmq_stream/src/rabbit_exchange_type_super_stream.erl

+25-9
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,41 @@ route(#exchange{name = Name},
6060
end
6161
end.
6262

63-
info(_) -> [].
64-
info(_, _) -> [].
65-
validate(_X) -> ok.
63+
info(_) ->
64+
[].
65+
66+
info(_, _) ->
67+
[].
68+
69+
validate(_X) ->
70+
ok.
6671

6772
validate_binding(_X, #binding{key = K}) ->
6873
try
6974
%% just check the Key is an integer
7075
_ = binary_to_integer(K),
7176
ok
72-
catch error:badarg ->
77+
catch
78+
error:badarg ->
7379
{error,
7480
{binding_invalid, "The binding key must be an integer: ~tp", [K]}}
7581
end.
7682

77-
create(_Serial, _X) -> ok.
78-
delete(_Serial, _X) -> ok.
79-
policy_changed(_X1, _X2) -> ok.
80-
add_binding(_Serial, _X, _B) -> ok.
81-
remove_bindings(_Serial, _X, _Bs) -> ok.
83+
create(_Serial, _X) ->
84+
ok.
85+
86+
delete(_Serial, _X) ->
87+
ok.
88+
89+
policy_changed(_X1, _X2) ->
90+
ok.
91+
92+
add_binding(_Serial, _X, _B) ->
93+
ok.
94+
95+
remove_bindings(_Serial, _X, _Bs) ->
96+
ok.
97+
8298
assert_args_equivalence(X, Args) ->
8399
rabbit_exchange:assert_args_equivalence(X, Args).
84100

deps/rabbitmq_stream/src/rabbit_stream.erl

+5-4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040

4141
start(_Type, _Args) ->
4242
rabbit_stream_metrics:init(),
43-
rabbit_global_counters:init([{protocol, stream}],
44-
?PROTOCOL_COUNTERS),
43+
rabbit_global_counters:init([{protocol, stream}], ?PROTOCOL_COUNTERS),
4544
rabbit_global_counters:init([{protocol, stream},
4645
{queue_type, ?STREAM_QUEUE_TYPE}]),
4746
rabbit_stream_sup:start_link().
@@ -130,8 +129,10 @@ kill_connection(ConnectionName) ->
130129
{ConnectionPid,
131130
#{<<"connection_name">> := ConnectionNameBin}} ->
132131
exit(ConnectionPid, kill);
133-
{ConnectionPid, _ClientProperties} -> ok
134-
after 1000 -> ok
132+
{ConnectionPid, _ClientProperties} ->
133+
ok
134+
after 1000 ->
135+
ok
135136
end
136137
end,
137138
pg_local:get_members(rabbit_stream_connections)).

deps/rabbitmq_stream/src/rabbit_stream_manager.erl

+47-46
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
create/4,
3131
delete/3,
3232
create_super_stream/1,
33-
%% obsolete use create_super_stream/1
34-
% create_super_stream/3,
35-
%% obsolete use create_super_stream/1
3633
create_super_stream/6,
3734
delete_super_stream/3,
3835
lookup_leader/2,
@@ -43,17 +40,22 @@
4340
partitions/2,
4441
partition_index/3]).
4542

43+
%% obsolete use create_super_stream/1
44+
% create_super_stream/3,
45+
%% obsolete use create_super_stream/1
46+
4647
-record(state, {configuration}).
4748

4849
-type super_stream_spec() ::
49-
#{name := binary(),
50-
vhost := binary(),
51-
username := binary(),
52-
partitions_source := {partition_count, pos_integer()} |
53-
{routing_keys, [binary()]},
54-
arguments => map(),
55-
exchange_type => binary() %<<"direct">> | <<"x-super-stream">>,
56-
}.
50+
#{name := binary(),
51+
vhost := binary(),
52+
username := binary(),
53+
partitions_source :=
54+
{partition_count, pos_integer()} | {routing_keys, [binary()]},
55+
arguments => map(),
56+
exchange_type => binary()}.
57+
58+
%<<"direct">> | <<"x-super-stream">>,
5759

5860
start_link(Conf) ->
5961
gen_server:start_link({local, ?MODULE}, ?MODULE, [Conf], []).
@@ -88,19 +90,16 @@ create_super_stream(VirtualHost,
8890
Arguments,
8991
RoutingKeys,
9092
Username) ->
91-
Options = #{partitions => Partitions,
92-
args => Arguments,
93-
routing_keys => RoutingKeys,
94-
username => Username},
93+
Options =
94+
#{partitions => Partitions,
95+
args => Arguments,
96+
routing_keys => RoutingKeys,
97+
username => Username},
9598
create_super_stream(VirtualHost, Name, Options).
9699

97-
98-
99-
-spec create_super_stream(binary(),
100-
binary(),
101-
map()) -> ok | {error, term()}.
102-
create_super_stream(VirtualHost,
103-
Name,
100+
-spec create_super_stream(binary(), binary(), map()) ->
101+
ok | {error, term()}.
102+
create_super_stream(VirtualHost, Name,
104103
#{username := Username} = Options) ->
105104
Type = maps:get(exchange_type, Options, <<"direct">>),
106105
Partitions = maps:get(partitions, Options, []),
@@ -116,30 +115,29 @@ create_super_stream(VirtualHost,
116115
RoutingKeys,
117116
Username}).
118117

119-
120118
-spec create_super_stream(super_stream_spec()) ->
121-
ok | {error, term()}.
119+
ok | {error, term()}.
122120
create_super_stream(#{exchange_type := <<"x-super-stream">>,
123121
partitions_source := {routing_keys, _}}) ->
124122
{error, unsupported_specification};
125123
create_super_stream(#{name := Name,
126124
vhost := VHost,
127125
username := Username,
128-
partitions_source := PartitionSource} = Spec) ->
126+
partitions_source := PartitionSource} =
127+
Spec) ->
129128
Type = maps:get(exchange_type, Spec, <<"direct">>),
130129
Arguments = maps:get(arguments, Spec, #{}),
131130
{Partitions, RoutingKeys} =
132131
case PartitionSource of
133132
{partition_count, Count} ->
134-
Streams = [rabbit_stream_utils:partition_name(Name, K)
135-
|| K <- lists:seq(0, Count - 1)],
136-
Keys = [integer_to_binary(K) ||
137-
K <- lists:seq(0, Count - 1)],
133+
Streams =
134+
[rabbit_stream_utils:partition_name(Name, K)
135+
|| K <- lists:seq(0, Count - 1)],
136+
Keys = [integer_to_binary(K) || K <- lists:seq(0, Count - 1)],
138137
{Streams, Keys};
139138
{routing_keys, Keys} ->
140139
Streams =
141-
[rabbit_stream_utils:partition_name(Name, K)
142-
|| K <- Keys],
140+
[rabbit_stream_utils:partition_name(Name, K) || K <- Keys],
143141
{Streams, Keys}
144142
end,
145143

@@ -825,15 +823,16 @@ add_super_stream_binding(VirtualHost,
825823
ExchangeName = rabbit_misc:r(VirtualHost, exchange, ExchangeNameBin),
826824
QueueName = rabbit_misc:r(VirtualHost, queue, QueueNameBin),
827825
Pid = self(),
828-
Arguments = case ExchangeType of
829-
<<"direct">> ->
830-
rabbit_misc:set_table_value([],
831-
<<"x-stream-partition-order">>,
832-
long,
833-
Order);
834-
_ ->
835-
[]
836-
end,
826+
Arguments =
827+
case ExchangeType of
828+
<<"direct">> ->
829+
rabbit_misc:set_table_value([],
830+
<<"x-stream-partition-order">>,
831+
long,
832+
Order);
833+
_ ->
834+
[]
835+
end,
837836
case rabbit_binding:add(#binding{source = ExchangeName,
838837
destination = QueueName,
839838
key = RoutingKey,
@@ -952,22 +951,24 @@ is_resource_stream_queue(#resource{kind = queue} = Resource) ->
952951
is_resource_stream_queue(_) ->
953952
false.
954953

955-
partition_index(#exchange{name = ExchangeName,
956-
type = ExchangeType} = Exchange, Stream) ->
954+
partition_index(#exchange{name = ExchangeName, type = ExchangeType} =
955+
Exchange,
956+
Stream) ->
957957
UnorderedBindings =
958958
[Binding
959959
|| Binding = #binding{destination = #resource{name = Q} = D}
960-
<- rabbit_binding:list_for_source(ExchangeName),
960+
<- rabbit_binding:list_for_source(ExchangeName),
961961
is_resource_stream_queue(D), Q == Stream],
962962
case UnorderedBindings of
963963
[] ->
964964
{error, stream_not_found};
965965
_ when ExchangeType =:= direct ->
966-
Bindings = rabbit_stream_utils:sort_partitions(Exchange, UnorderedBindings),
966+
Bindings =
967+
rabbit_stream_utils:sort_partitions(Exchange,
968+
UnorderedBindings),
967969
Binding = lists:nth(1, Bindings),
968970
#binding{args = Args} = Binding,
969-
case rabbit_misc:table_lookup(Args,
970-
<<"x-stream-partition-order">>)
971+
case rabbit_misc:table_lookup(Args, <<"x-stream-partition-order">>)
971972
of
972973
{_, Order} ->
973974
Index = rabbit_data_coercion:to_integer(Order),

0 commit comments

Comments
 (0)