Skip to content

Commit 3e6d1ad

Browse files
author
Daniil Fedotov
committed
Replace orddicts with maps
1 parent c0dcb2b commit 3e6d1ad

8 files changed

+71
-72
lines changed

src/gm.erl

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@
399399
-define(FORCE_GC_TIMER, 250).
400400
-define(VERSION_START, 0).
401401
-define(SETS, ordsets).
402-
-define(DICT, orddict).
403402

404403
-record(state,
405404
{ self,
@@ -824,8 +823,8 @@ handle_msg({catchup, Left, MembersStateLeft},
824823
members_state = MembersState })
825824
when MembersState =/= undefined ->
826825
MembersStateLeft1 = build_members_state(MembersStateLeft),
827-
AllMembers = lists:usort(?DICT:fetch_keys(MembersState) ++
828-
?DICT:fetch_keys(MembersStateLeft1)),
826+
AllMembers = lists:usort(maps:keys(MembersState) ++
827+
maps:keys(MembersStateLeft1)),
829828
{MembersState1, Activity} =
830829
lists:foldl(
831830
fun (Id, MembersStateActivity) ->
@@ -995,21 +994,21 @@ is_member_alias(Member, Self, View) ->
995994
dead_member_id({dead, Member}) -> Member.
996995

997996
store_view_member(VMember = #view_member { id = Id }, {Ver, View}) ->
998-
{Ver, ?DICT:store(Id, VMember, View)}.
997+
{Ver, maps:put(Id, VMember, View)}.
999998

1000999
with_view_member(Fun, View, Id) ->
10011000
store_view_member(Fun(fetch_view_member(Id, View)), View).
10021001

1003-
fetch_view_member(Id, {_Ver, View}) -> ?DICT:fetch(Id, View).
1002+
fetch_view_member(Id, {_Ver, View}) -> maps:get(Id, View).
10041003

1005-
find_view_member(Id, {_Ver, View}) -> ?DICT:find(Id, View).
1004+
find_view_member(Id, {_Ver, View}) -> maps:find(Id, View).
10061005

1007-
blank_view(Ver) -> {Ver, ?DICT:new()}.
1006+
blank_view(Ver) -> {Ver, maps:new()}.
10081007

1009-
alive_view_members({_Ver, View}) -> ?DICT:fetch_keys(View).
1008+
alive_view_members({_Ver, View}) -> maps:keys(View).
10101009

10111010
all_known_members({_Ver, View}) ->
1012-
?DICT:fold(
1011+
maps:fold(
10131012
fun (Member, #view_member { aliases = Aliases }, Acc) ->
10141013
?SETS:to_list(Aliases) ++ [Member | Acc]
10151014
end, [], View).
@@ -1374,24 +1373,24 @@ with_member_acc(Fun, Id, {MembersState, Acc}) ->
13741373
{store_member(Id, MemberState, MembersState), Acc1}.
13751374

13761375
find_member_or_blank(Id, MembersState) ->
1377-
case ?DICT:find(Id, MembersState) of
1376+
case maps:find(Id, MembersState) of
13781377
{ok, Result} -> Result;
13791378
error -> blank_member()
13801379
end.
13811380

1382-
erase_member(Id, MembersState) -> ?DICT:erase(Id, MembersState).
1381+
erase_member(Id, MembersState) -> maps:remove(Id, MembersState).
13831382

13841383
blank_member() ->
13851384
#member { pending_ack = queue:new(), last_pub = -1, last_ack = -1 }.
13861385

1387-
blank_member_state() -> ?DICT:new().
1386+
blank_member_state() -> maps:new().
13881387

13891388
store_member(Id, MemberState, MembersState) ->
1390-
?DICT:store(Id, MemberState, MembersState).
1389+
maps:put(Id, MemberState, MembersState).
13911390

1392-
prepare_members_state(MembersState) -> ?DICT:to_list(MembersState).
1391+
prepare_members_state(MembersState) -> maps:to_list(MembersState).
13931392

1394-
build_members_state(MembersStateList) -> ?DICT:from_list(MembersStateList).
1393+
build_members_state(MembersStateList) -> maps:from_list(MembersStateList).
13951394

13961395
make_member(GroupName) ->
13971396
{case dirty_read_group(GroupName) of

src/rabbit_limiter.erl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
%% 'Notify' is a boolean that indicates whether a queue should be
185185
%% notified of a change in the limit or volume that may allow it to
186186
%% deliver more messages via the limiter's channel.
187-
queues = orddict:new(), % QPid -> {MonitorRef, Notify}
187+
queues = maps:new(), % QPid -> {MonitorRef, Notify}
188188
volume = 0}).
189189

190190
%% mode is of type credit_mode()
@@ -402,28 +402,28 @@ prefetch_limit_reached(#lim{prefetch_count = Limit, volume = Volume}) ->
402402
Limit =/= 0 andalso Volume >= Limit.
403403

404404
remember_queue(QPid, State = #lim{queues = Queues}) ->
405-
case orddict:is_key(QPid, Queues) of
405+
case maps:is_key(QPid, Queues) of
406406
false -> MRef = erlang:monitor(process, QPid),
407-
State#lim{queues = orddict:store(QPid, {MRef, false}, Queues)};
407+
State#lim{queues = maps:put(QPid, {MRef, false}, Queues)};
408408
true -> State
409409
end.
410410

411411
forget_queue(QPid, State = #lim{queues = Queues}) ->
412-
case orddict:find(QPid, Queues) of
412+
case maps:find(QPid, Queues) of
413413
{ok, {MRef, _}} -> true = erlang:demonitor(MRef),
414-
State#lim{queues = orddict:erase(QPid, Queues)};
414+
State#lim{queues = maps:remove(QPid, Queues)};
415415
error -> State
416416
end.
417417

418418
limit_queue(QPid, State = #lim{queues = Queues}) ->
419419
UpdateFun = fun ({MRef, _}) -> {MRef, true} end,
420-
State#lim{queues = orddict:update(QPid, UpdateFun, Queues)}.
420+
State#lim{queues = maps:update_with(QPid, UpdateFun, Queues)}.
421421

422422
notify_queues(State = #lim{ch_pid = ChPid, queues = Queues}) ->
423423
{QList, NewQueues} =
424-
orddict:fold(fun (_QPid, {_, false}, Acc) -> Acc;
424+
maps:fold(fun (_QPid, {_, false}, Acc) -> Acc;
425425
(QPid, {MRef, true}, {L, D}) ->
426-
{[QPid | L], orddict:store(QPid, {MRef, false}, D)}
426+
{[QPid | L], maps:put(QPid, {MRef, false}, D)}
427427
end, {[], Queues}, Queues),
428428
case length(QList) of
429429
0 -> ok;

src/rabbit_msg_store.erl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ init([Type, BaseDir, ClientRefs, StartupFunState]) ->
780780
sync_timer_ref = undefined,
781781
sum_valid_data = 0,
782782
sum_file_size = 0,
783-
pending_gc_completion = orddict:new(),
783+
pending_gc_completion = maps:new(),
784784
gc_pid = GCPid,
785785
file_handles_ets = FileHandlesEts,
786786
file_summary_ets = FileSummaryEts,
@@ -1269,7 +1269,7 @@ contains_message(MsgId, From,
12691269
gen_server2:reply(From, false),
12701270
State;
12711271
#msg_location { file = File } ->
1272-
case orddict:is_key(File, Pending) of
1272+
case maps:is_key(File, Pending) of
12731273
true -> add_to_pending_gc_completion(
12741274
{contains, MsgId, From}, File, State);
12751275
false -> gen_server2:reply(From, true),
@@ -1280,16 +1280,16 @@ contains_message(MsgId, From,
12801280
add_to_pending_gc_completion(
12811281
Op, File, State = #msstate { pending_gc_completion = Pending }) ->
12821282
State #msstate { pending_gc_completion =
1283-
rabbit_misc:orddict_cons(File, Op, Pending) }.
1283+
rabbit_misc:maps_cons(File, Op, Pending) }.
12841284

12851285
run_pending(Files, State) ->
12861286
lists:foldl(
12871287
fun (File, State1 = #msstate { pending_gc_completion = Pending }) ->
1288-
Pending1 = orddict:erase(File, Pending),
1288+
Pending1 = maps:remove(File, Pending),
12891289
lists:foldl(
12901290
fun run_pending_action/2,
12911291
State1 #msstate { pending_gc_completion = Pending1 },
1292-
lists:reverse(orddict:fetch(File, Pending)))
1292+
lists:reverse(maps:get(File, Pending)))
12931293
end, State, Files).
12941294

12951295
run_pending_action({read, MsgId, From}, State) ->
@@ -1320,9 +1320,9 @@ adjust_valid_total_size(File, Delta, State = #msstate {
13201320
[{#file_summary.valid_total_size, Delta}]),
13211321
State #msstate { sum_valid_data = SumValid + Delta }.
13221322

1323-
orddict_store(Key, Val, Dict) ->
1324-
false = orddict:is_key(Key, Dict),
1325-
orddict:store(Key, Val, Dict).
1323+
maps_store(Key, Val, Dict) ->
1324+
false = maps:is_key(Key, Dict),
1325+
maps:put(Key, Val, Dict).
13261326

13271327
update_pending_confirms(Fun, CRef,
13281328
State = #msstate { clients = Clients,
@@ -1860,7 +1860,7 @@ maybe_compact(State = #msstate { sum_valid_data = SumValid,
18601860
%% complete traversal of FileSummaryEts.
18611861
First = ets:first(FileSummaryEts),
18621862
case First =:= '$end_of_table' orelse
1863-
orddict:size(Pending) >= ?MAXIMUM_SIMULTANEOUS_GC_FILES of
1863+
maps:size(Pending) >= ?MAXIMUM_SIMULTANEOUS_GC_FILES of
18641864
true ->
18651865
State;
18661866
false ->
@@ -1869,8 +1869,8 @@ maybe_compact(State = #msstate { sum_valid_data = SumValid,
18691869
not_found ->
18701870
State;
18711871
{Src, Dst} ->
1872-
Pending1 = orddict_store(Dst, [],
1873-
orddict_store(Src, [], Pending)),
1872+
Pending1 = maps_store(Dst, [],
1873+
maps_store(Src, [], Pending)),
18741874
State1 = close_handle(Src, close_handle(Dst, State)),
18751875
true = ets:update_element(FileSummaryEts, Src,
18761876
{#file_summary.locked, true}),
@@ -1926,7 +1926,7 @@ delete_file_if_empty(File, State = #msstate {
19261926
0 -> true = ets:update_element(FileSummaryEts, File,
19271927
{#file_summary.locked, true}),
19281928
ok = rabbit_msg_store_gc:delete(GCPid, File),
1929-
Pending1 = orddict_store(File, [], Pending),
1929+
Pending1 = maps_store(File, [], Pending),
19301930
close_handle(File,
19311931
State #msstate { pending_gc_completion = Pending1 });
19321932
_ -> State

src/rabbit_node_monitor.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ init([]) ->
350350
subscribers = pmon:new(),
351351
partitions = [],
352352
guid = rabbit_guid:gen(),
353-
node_guids = orddict:new(),
353+
node_guids = maps:new(),
354354
autoheal = rabbit_autoheal:init()})}.
355355

356356
handle_call(partitions, _From, State = #state{partitions = Partitions}) ->
@@ -405,17 +405,17 @@ handle_cast({node_up, Node, NodeType, GUID},
405405
State = #state{guid = MyGUID,
406406
node_guids = GUIDs}) ->
407407
cast(Node, {announce_guid, node(), MyGUID}),
408-
GUIDs1 = orddict:store(Node, GUID, GUIDs),
408+
GUIDs1 = maps:put(Node, GUID, GUIDs),
409409
handle_cast({node_up, Node, NodeType}, State#state{node_guids = GUIDs1});
410410

411411
handle_cast({announce_guid, Node, GUID}, State = #state{node_guids = GUIDs}) ->
412-
{noreply, State#state{node_guids = orddict:store(Node, GUID, GUIDs)}};
412+
{noreply, State#state{node_guids = maps:put(Node, GUID, GUIDs)}};
413413

414414
handle_cast({check_partial_partition, Node, Rep, NodeGUID, MyGUID, RepGUID},
415415
State = #state{guid = MyGUID,
416416
node_guids = GUIDs}) ->
417417
case lists:member(Node, rabbit_mnesia:cluster_nodes(running)) andalso
418-
orddict:find(Node, GUIDs) =:= {ok, NodeGUID} of
418+
maps:find(Node, GUIDs) =:= {ok, NodeGUID} of
419419
true -> spawn_link( %%[1]
420420
fun () ->
421421
case rpc:call(Node, rabbit, is_running, []) of
@@ -560,10 +560,10 @@ handle_info({nodedown, Node, Info}, State = #state{guid = MyGUID,
560560
cast(N, {check_partial_partition,
561561
Node, node(), DownGUID, CheckGUID, MyGUID})
562562
end,
563-
case orddict:find(Node, GUIDs) of
563+
case maps:find(Node, GUIDs) of
564564
{ok, DownGUID} -> Alive = rabbit_mnesia:cluster_nodes(running)
565565
-- [node(), Node],
566-
[case orddict:find(N, GUIDs) of
566+
[case maps:find(N, GUIDs) of
567567
{ok, CheckGUID} -> Check(N, CheckGUID, DownGUID);
568568
error -> ok
569569
end || N <- Alive];

src/rabbit_priority_queue.erl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ publish(Msg, MsgProps, IsDelivered, ChPid, Flow,
207207
?passthrough1(publish(Msg, MsgProps, IsDelivered, ChPid, Flow, BQS)).
208208

209209
batch_publish(Publishes, ChPid, Flow, State = #state{bq = BQ, bqss = [{MaxP, _} |_]}) ->
210-
PubDict = partition_publish_batch(Publishes, MaxP),
210+
PubMap = partition_publish_batch(Publishes, MaxP),
211211
lists:foldl(
212212
fun ({Priority, Pubs}, St) ->
213213
pick1(fun (_P, BQSN) ->
214214
BQ:batch_publish(Pubs, ChPid, Flow, BQSN)
215215
end, Priority, St)
216-
end, State, orddict:to_list(PubDict));
216+
end, State, maps:to_list(PubMap));
217217
batch_publish(Publishes, ChPid, Flow,
218218
State = #passthrough{bq = BQ, bqs = BQS}) ->
219219
?passthrough1(batch_publish(Publishes, ChPid, Flow, BQS)).
@@ -229,7 +229,7 @@ publish_delivered(Msg, MsgProps, ChPid, Flow,
229229
?passthrough2(publish_delivered(Msg, MsgProps, ChPid, Flow, BQS)).
230230

231231
batch_publish_delivered(Publishes, ChPid, Flow, State = #state{bq = BQ, bqss = [{MaxP, _} |_]}) ->
232-
PubDict = partition_publish_delivered_batch(Publishes, MaxP),
232+
PubMap = partition_publish_delivered_batch(Publishes, MaxP),
233233
{PrioritiesAndAcks, State1} =
234234
lists:foldl(
235235
fun ({Priority, Pubs}, {PriosAndAcks, St}) ->
@@ -241,7 +241,7 @@ batch_publish_delivered(Publishes, ChPid, Flow, State = #state{bq = BQ, bqss = [
241241
{priority_on_acktags(P, AckTags), BQSN1}
242242
end, Priority, St),
243243
{[PriosAndAcks1 | PriosAndAcks], St1}
244-
end, {[], State}, orddict:to_list(PubDict)),
244+
end, {[], State}, maps:to_list(PubMap)),
245245
{lists:reverse(PrioritiesAndAcks), State1};
246246
batch_publish_delivered(Publishes, ChPid, Flow,
247247
State = #passthrough{bq = BQ, bqs = BQS}) ->
@@ -327,7 +327,7 @@ ackfold(MsgFun, Acc, State = #state{bq = BQ}, AckTags) ->
327327
AckTagsByPriority = partition_acktags(AckTags),
328328
fold2(
329329
fun (P, BQSN, AccN) ->
330-
case orddict:find(P, AckTagsByPriority) of
330+
case maps:find(P, AckTagsByPriority) of
331331
{ok, ATagsN} -> {AccN1, BQSN1} =
332332
BQ:ackfold(MsgFun, AccN, BQSN, ATagsN),
333333
{priority_on_acktags(P, AccN1), BQSN1};
@@ -439,7 +439,7 @@ zip_msgs_and_acks(Msgs, AckTags, Accumulator, #state{bqss = [{MaxP, _} |_]}) ->
439439
MsgsByPriority = partition_publish_delivered_batch(Msgs, MaxP),
440440
lists:foldl(fun (Acks, MAs) ->
441441
{P, _AckTag} = hd(Acks),
442-
Pubs = orddict:fetch(P, MsgsByPriority),
442+
Pubs = maps:get(P, MsgsByPriority),
443443
MAs0 = zip_msgs_and_acks(Pubs, Acks),
444444
MAs ++ MAs0
445445
end, Accumulator, AckTags);
@@ -527,7 +527,7 @@ fold_min2(Fun, State) ->
527527
fold_by_acktags2(Fun, AckTags, State) ->
528528
AckTagsByPriority = partition_acktags(AckTags),
529529
fold_append2(fun (P, BQSN) ->
530-
case orddict:find(P, AckTagsByPriority) of
530+
case maps:find(P, AckTagsByPriority) of
531531
{ok, AckTagsN} -> Fun(AckTagsN, BQSN);
532532
error -> {[], BQSN}
533533
end
@@ -597,11 +597,11 @@ partition_publishes(Publishes, ExtractMsg, MaxP) ->
597597
Partitioned =
598598
lists:foldl(fun (Pub, Dict) ->
599599
Msg = ExtractMsg(Pub),
600-
rabbit_misc:orddict_cons(priority(Msg, MaxP), Pub, Dict)
601-
end, orddict:new(), Publishes),
602-
orddict:map(fun (_P, RevPubs) ->
603-
lists:reverse(RevPubs)
604-
end, Partitioned).
600+
rabbit_misc:maps_cons(priority(Msg, MaxP), Pub, Dict)
601+
end, maps:new(), Publishes),
602+
maps:map(fun (_P, RevPubs) ->
603+
lists:reverse(RevPubs)
604+
end, Partitioned).
605605

606606

607607
priority_bq(Priority, [{MaxP, _} | _] = BQSs) ->
@@ -625,14 +625,14 @@ add_maybe_infinity(infinity, _) -> infinity;
625625
add_maybe_infinity(_, infinity) -> infinity;
626626
add_maybe_infinity(A, B) -> A + B.
627627

628-
partition_acktags(AckTags) -> partition_acktags(AckTags, orddict:new()).
628+
partition_acktags(AckTags) -> partition_acktags(AckTags, maps:new()).
629629

630630
partition_acktags([], Partitioned) ->
631-
orddict:map(fun (_P, RevAckTags) ->
632-
lists:reverse(RevAckTags)
633-
end, Partitioned);
631+
maps:map(fun (_P, RevAckTags) ->
632+
lists:reverse(RevAckTags)
633+
end, Partitioned);
634634
partition_acktags([{P, AckTag} | Rest], Partitioned) ->
635-
partition_acktags(Rest, rabbit_misc:orddict_cons(P, AckTag, Partitioned)).
635+
partition_acktags(Rest, rabbit_misc:maps_cons(P, AckTag, Partitioned)).
636636

637637
priority_on_acktags(P, AckTags) ->
638638
[case Tag of

src/rabbit_queue_consumers.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ subtract_acks(ChPid, AckTags, State) ->
254254
not_found;
255255
C = #cr{acktags = ChAckTags, limiter = Lim} ->
256256
{CTagCounts, AckTags2} = subtract_acks(
257-
AckTags, [], orddict:new(), ChAckTags),
257+
AckTags, [], maps:new(), ChAckTags),
258258
{Unblocked, Lim2} =
259-
orddict:fold(
259+
maps:fold(
260260
fun (CTag, Count, {UnblockedN, LimN}) ->
261261
{Unblocked1, LimN1} =
262262
rabbit_limiter:ack_from_queue(LimN, CTag, Count),
@@ -278,7 +278,7 @@ subtract_acks([T | TL] = AckTags, Prefix, CTagCounts, AckQ) ->
278278
case queue:out(AckQ) of
279279
{{value, {T, CTag}}, QTail} ->
280280
subtract_acks(TL, Prefix,
281-
orddict:update_counter(CTag, 1, CTagCounts), QTail);
281+
maps:update_with(CTag, fun (Old) -> Old + 1 end, 1, CTagCounts), QTail);
282282
{{value, V}, QTail} ->
283283
subtract_acks(AckTags, [V | Prefix], CTagCounts, QTail);
284284
{empty, _} ->

0 commit comments

Comments
 (0)