Skip to content

Commit 50e2577

Browse files
committed
Adding missing function specs
1 parent 1f106fc commit 50e2577

12 files changed

+50
-10
lines changed

deps/rabbitmq_mqtt/src/mqtt_machine.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ apply(_Meta, Unknown, State) ->
172172
logger:error("MQTT Raft state machine v1 received unknown command ~tp", [Unknown]),
173173
{State, {error, {unknown_command, Unknown}}, []}.
174174

175+
-spec state_enter(ra_server:ra_state() | eol, state()) ->
176+
ra_machine:effects().
175177
state_enter(leader, State) ->
176178
%% re-request monitors for all known pids, this would clean up
177179
%% records for all connections are no longer around, e.g. right after node restart
@@ -188,6 +190,7 @@ overview(#machine_state{client_ids = ClientIds,
188190
%% ==========================
189191

190192
%% Avoids blocking the Raft leader.
193+
-spec notify_connection(pid(), duplicate_id | decommission_node) -> pid().
191194
notify_connection(Pid, Reason) ->
192195
spawn(fun() -> gen_server2:cast(Pid, Reason) end).
193196

deps/rabbitmq_mqtt/src/mqtt_machine_v0.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ apply(_Meta, Unknown, State) ->
113113
logger:error("MQTT Raft state machine received an unknown command ~tp", [Unknown]),
114114
{State, {error, {unknown_command, Unknown}}, []}.
115115

116+
-spec state_enter(ra_server:ra_state(), state()) ->
117+
ra_machine:effects().
116118
state_enter(leader, State) ->
117119
%% re-request monitors for all known pids, this would clean up
118120
%% records for all connections are no longer around, e.g. right after node restart
@@ -123,6 +125,7 @@ state_enter(_, _) ->
123125
%% ==========================
124126

125127
%% Avoids blocking the Raft leader.
128+
-spec notify_connection(pid(), duplicate_id | decommission_node) -> pid().
126129
notify_connection(Pid, Reason) ->
127130
spawn(fun() -> gen_server2:cast(Pid, Reason) end).
128131

deps/rabbitmq_mqtt/src/rabbit_mqtt.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ start(normal, []) ->
4141
stop(_) ->
4242
rabbit_mqtt_sup:stop_listeners().
4343

44+
-spec emit_connection_info_all([node()], rabbit_types:info_keys(), reference(), pid()) -> term().
4445
emit_connection_info_all(Nodes, Items, Ref, AggregatorPid) ->
4546
case rabbit_mqtt_ff:track_client_id_in_ra() of
4647
true ->
@@ -57,6 +58,7 @@ emit_connection_info_all(Nodes, Items, Ref, AggregatorPid) ->
5758
rabbit_control_misc:await_emitters_termination(Pids)
5859
end.
5960

61+
-spec emit_connection_info_local(rabbit_types:info_keys(), reference(), pid()) -> ok.
6062
emit_connection_info_local(Items, Ref, AggregatorPid) ->
6163
LocalPids = local_connection_pids(),
6264
emit_connection_info(Items, Ref, AggregatorPid, LocalPids).

deps/rabbitmq_mqtt/src/rabbit_mqtt_collector.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ register(ServerId, ClientId, Pid) ->
3636
erlang:send_after(5000, self(), {ra_event, undefined, register_timeout}),
3737
{ok, Corr}.
3838

39+
-spec unregister(binary(), pid()) -> ok.
3940
unregister(ClientId, Pid) ->
4041
{ClusterName, _} = mqtt_node:server_id(),
4142
case ra_leaderboard:lookup_leader(ClusterName) of
@@ -49,6 +50,7 @@ unregister(ClientId, Pid) ->
4950
list_pids() ->
5051
list(fun(#machine_state{pids = Pids}) -> maps:keys(Pids) end).
5152

53+
-spec list() -> term().
5254
list() ->
5355
list(fun(#machine_state{client_ids = Ids}) -> maps:to_list(Ids) end).
5456

@@ -76,6 +78,7 @@ list(QF) ->
7678
end
7779
end.
7880

81+
-spec leave(binary()) -> ok | timeout | nodedown.
7982
leave(NodeBin) ->
8083
Node = binary_to_atom(NodeBin, utf8),
8184
ServerId = mqtt_node:server_id(),

deps/rabbitmq_mqtt/src/rabbit_mqtt_ff.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
callbacks => #{enable => {mqtt_node, delete}}
2525
}}).
2626

27+
-spec track_client_id_in_ra() -> boolean().
2728
track_client_id_in_ra() ->
2829
not rabbit_feature_flags:is_enabled(delete_ra_cluster_mqtt_node).

deps/rabbitmq_mqtt/src/rabbit_mqtt_processor.erl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,9 +1329,13 @@ serialise_and_send_to_client(Packet, #state{cfg = #cfg{proto_ver = ProtoVer,
13291329
[Sock, Error, Packet#mqtt_packet.fixed, Packet#mqtt_packet.variable])
13301330
end.
13311331

1332+
-spec serialise(#mqtt_packet{}, state()) ->
1333+
iodata().
13321334
serialise(Packet, #state{cfg = #cfg{proto_ver = ProtoVer}}) ->
13331335
rabbit_mqtt_packet:serialise(Packet, ProtoVer).
13341336

1337+
-spec terminate(boolean(), binary(), atom(), state()) ->
1338+
ok.
13351339
terminate(SendWill, ConnName, ProtoFamily, State) ->
13361340
maybe_send_will(SendWill, ConnName, State),
13371341
Infos = [{name, ConnName},
@@ -1427,11 +1431,15 @@ delete_queue(QName, Username) ->
14271431
ok
14281432
end).
14291433

1434+
-spec handle_pre_hibernate() -> ok.
14301435
handle_pre_hibernate() ->
14311436
erase(permission_cache),
14321437
erase(topic_permission_cache),
14331438
ok.
14341439

1440+
-spec handle_ra_event(register_timeout
1441+
| {applied, [{reference(), ok}]}
1442+
| {not_leader, term(), reference()}, state()) -> state().
14351443
handle_ra_event({applied, [{Corr, ok}]},
14361444
State = #state{register_state = {pending, Corr}}) ->
14371445
%% success case - command was applied transition into registered state
@@ -1796,6 +1804,7 @@ throttle(Conserve, Connected, #state{queues_soft_limit_exceeded = QSLE,
17961804
not sets:is_empty(QSLE) orelse
17971805
credit_flow:blocked().
17981806

1807+
-spec info(rabbit_types:info_key(), state()) -> any().
17991808
info(host, #state{cfg = #cfg{host = Val}}) -> Val;
18001809
info(port, #state{cfg = #cfg{port = Val}}) -> Val;
18011810
info(peer_host, #state{cfg = #cfg{peer_host = Val}}) -> Val;

deps/rabbitmq_mqtt/src/rabbit_mqtt_retained_msg_store_dets.erl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,37 @@
1717
table
1818
}).
1919

20+
-type store_state() :: #store_state{}.
2021

22+
-spec new(file:name_all(), rabbit_types:vhost()) -> store_state().
2123
new(Dir, VHost) ->
2224
Tid = open_table(Dir, VHost),
2325
#store_state{table = Tid}.
2426

27+
-spec recover(file:name_all(), rabbit_types:vhost()) ->
28+
{error, uninitialized} | {ok, store_state()}.
2529
recover(Dir, VHost) ->
2630
case open_table(Dir, VHost) of
2731
{error, _} -> {error, uninitialized};
2832
{ok, Tid} -> {ok, #store_state{table = Tid}}
2933
end.
3034

35+
-spec insert(binary(), mqtt_msg(), store_state()) -> ok.
3136
insert(Topic, Msg, #store_state{table = T}) ->
3237
ok = dets:insert(T, #retained_message{topic = Topic, mqtt_msg = Msg}).
3338

39+
-spec lookup(binary(), store_state()) -> retained_message() | not_found.
3440
lookup(Topic, #store_state{table = T}) ->
3541
case dets:lookup(T, Topic) of
3642
[] -> not_found;
3743
[Entry] -> Entry
3844
end.
3945

46+
-spec delete(binary(), store_state()) -> ok.
4047
delete(Topic, #store_state{table = T}) ->
4148
ok = dets:delete(T, Topic).
4249

50+
-spec terminate(store_state()) -> ok.
4351
terminate(#store_state{table = T}) ->
4452
ok = dets:close(T).
4553

deps/rabbitmq_mqtt/src/rabbit_mqtt_retained_msg_store_ets.erl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919
filename
2020
}).
2121

22+
-type store_state() :: #store_state{}.
2223

24+
-spec new(file:name_all(), rabbit_types:vhost()) -> store_state().
2325
new(Dir, VHost) ->
2426
Path = rabbit_mqtt_util:path_for(Dir, VHost),
2527
TableName = rabbit_mqtt_util:vhost_name_to_table_name(VHost),
2628
_ = file:delete(Path),
2729
Tid = ets:new(TableName, [set, public, {keypos, #retained_message.topic}]),
2830
#store_state{table = Tid, filename = Path}.
2931

32+
-spec recover(file:name_all(), rabbit_types:vhost()) ->
33+
{error, uninitialized} | {ok, store_state()}.
3034
recover(Dir, VHost) ->
3135
Path = rabbit_mqtt_util:path_for(Dir, VHost),
3236
case ets:file2tab(Path) of
@@ -35,19 +39,23 @@ recover(Dir, VHost) ->
3539
{error, _} -> {error, uninitialized}
3640
end.
3741

42+
-spec insert(binary(), mqtt_msg(), store_state()) -> ok.
3843
insert(Topic, Msg, #store_state{table = T}) ->
3944
true = ets:insert(T, #retained_message{topic = Topic, mqtt_msg = Msg}),
4045
ok.
4146

47+
-spec lookup(binary(), store_state()) -> retained_message() | not_found.
4248
lookup(Topic, #store_state{table = T}) ->
4349
case ets:lookup(T, Topic) of
4450
[] -> not_found;
4551
[Entry] -> Entry
4652
end.
4753

54+
-spec delete(binary(), store_state()) -> ok.
4855
delete(Topic, #store_state{table = T}) ->
4956
true = ets:delete(T, Topic),
5057
ok.
5158

59+
-spec terminate(store_state()) -> ok.
5260
terminate(#store_state{table = T, filename = Path}) ->
5361
ok = ets:tab2file(T, Path, [{extended_info, [object_count]}]).

deps/rabbitmq_mqtt/src/rabbit_mqtt_retainer_sup.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
start_link(SupName) ->
1818
supervisor:start_link(SupName, ?MODULE, []).
1919

20+
-spec child_for_vhost(rabbit_types:vhost()) -> pid().
2021
child_for_vhost(VHost) when is_binary(VHost) ->
2122
case rabbit_mqtt_retainer_sup:start_child(VHost) of
2223
{ok, Pid} -> Pid;

deps/rabbitmq_mqtt/src/rabbit_mqtt_sup.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ init([{Listeners, SslListeners0}]) ->
7070
)
7171
]}}.
7272

73+
-spec stop_listeners() -> ok.
7374
stop_listeners() ->
7475
_ = rabbit_networking:stop_ranch_listener_of_protocol(?TCP_PROTOCOL),
7576
_ = rabbit_networking:stop_ranch_listener_of_protocol(?TLS_PROTOCOL),

0 commit comments

Comments
 (0)