Skip to content

Commit b3fc71a

Browse files
author
Daniil Fedotov
committed
wip
1 parent d1bffd0 commit b3fc71a

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

src/rabbit_variable_queue.erl

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,17 +2689,44 @@ migrate_queue(Queue, OldStore, NewStoreSup) ->
26892689
OldStoreClient = get_old_client(OldStore),
26902690
NewStoreClient = get_new_store_client(Queue, NewStoreSup),
26912691
walk_queue_index(
2692-
fun(MessageIdInStore) ->
2693-
Msg = get_msg_from_store(OldStoreClient),
2694-
put_message_to_store(Msg, NewStoreClient)
2692+
fun(MessageIdInStore, OldC) ->
2693+
case rabbit_msg_store:read(MessageIdInStore, OldStoreClient) of
2694+
{{ok, Msg}, OldC1} ->
2695+
ok = rabbit_msg_store:write(MessageIdInStore, Msg, NewStoreClient),
2696+
OldC1;
2697+
_ -> OldC
2698+
end
26952699
end,
26962700
Queue).
26972701

2702+
spawn_for_each(Fun, List) ->
2703+
Ref = erlang:make_ref(),
2704+
Self = self(),
2705+
Processes = lists:map(
2706+
fun(El) ->
2707+
spawn_link(
2708+
fun() ->
2709+
Fun(El),
2710+
Self ! {ok, self(), Ref}
2711+
end)
2712+
end,
2713+
List),
2714+
{Ref, Processes}.
2715+
2716+
wait({Ref, Processes}) ->
2717+
lists:foreach(
2718+
fun(Proc) ->
2719+
receive {ok, Proc, Ref} -> ok
2720+
end
2721+
end,
2722+
Processes).
26982723

26992724
get_new_store_client(Queue, NewStoreSup) ->
27002725
Vhost = queue_vhost(Queue),
27012726
get_new_client(NewStoreSup, Vhost).
27022727

2728+
queue_vhost(#amqqueue{name = #resource{virtual_host = VHost}}) -> VHost.
2729+
27032730
get_new_client(NewStoreSup, VHost) ->
27042731
rabbit_msg_store_vhost_sup:client_init(NewStoreSup,
27052732
rabbit_guid:gen(),
@@ -2735,7 +2762,7 @@ start_recovery_terms(Queues) ->
27352762
{Refs, StartFunState}.
27362763

27372764
run_old_persistent_store(Refs, StartFunState) ->
2738-
OldStoreName = old_persistent_msg_store.
2765+
OldStoreName = old_persistent_msg_store,
27392766
ok = rabbit_sup:start_child(OldStoreName, rabbit_msg_store,
27402767
[OldStoreName, rabbit_mnesia:dir(),
27412768
Refs, StartFunState]),
@@ -2753,3 +2780,12 @@ start_new_store_sup() ->
27532780
undefined, {fun (ok) -> finished end, ok}]),
27542781
?PERSISTENT_MSG_STORE.
27552782

2783+
delete_old_store(OldStore) ->
2784+
gen_server:stop(OldStore),
2785+
rabbit_file:recursive_delete(
2786+
filename:join([rabbit_mnesia:dir(), ?PERSISTENT_MSG_STORE])).
2787+
2788+
2789+
2790+
2791+

0 commit comments

Comments
 (0)