Skip to content

Commit a728662

Browse files
Merge pull request #2973 from luos/mirror-sync-reduce-memory-use
Classic queue mirrors should also continue pushing messages to disk when syncing
2 parents f6df03c + 3d92907 commit a728662

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

deps/rabbit/src/rabbit_mirror_queue_slave.erl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,13 @@ handle_info({bump_credit, Msg}, State) ->
385385
credit_flow:handle_bump_msg(Msg),
386386
noreply(State);
387387

388-
handle_info(bump_reduce_memory_use, State) ->
389-
noreply(State);
388+
handle_info(bump_reduce_memory_use, State = #state{backing_queue = BQ,
389+
backing_queue_state = BQS}) ->
390+
BQS1 = BQ:handle_info(bump_reduce_memory_use, BQS),
391+
BQS2 = BQ:resume(BQS1),
392+
noreply(State#state{
393+
backing_queue_state = BQS2
394+
});
390395

391396
%% In the event of a short partition during sync we can detect the
392397
%% master's 'death', drop out of sync, and then receive sync messages

deps/rabbit/src/rabbit_mirror_queue_sync.erl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ wait_for_credit(SPids) ->
288288
end.
289289

290290
wait_for_resources(Ref, SPids) ->
291+
erlang:garbage_collect(),
292+
% Probably bump_reduce_memory_use messages should be handled here as well,
293+
% otherwise the BQ is not pushing messages to disk
291294
receive
292295
{conserve_resources, memory, false} ->
293296
SPids;
@@ -367,7 +370,11 @@ slave_sync_loop(Args = {Ref, MRef, Syncer, BQ, UpdateRamDuration, Parent},
367370
%% If the master throws an exception
368371
{'$gen_cast', {gm, {delete_and_terminate, Reason}}} ->
369372
BQ:delete_and_terminate(Reason, BQS),
370-
{stop, Reason, {[], TRef, undefined}}
373+
{stop, Reason, {[], TRef, undefined}};
374+
bump_reduce_memory_use ->
375+
BQS1 = BQ:handle_info(bump_reduce_memory_use, BQS),
376+
BQS2 = BQ:resume(BQS1),
377+
slave_sync_loop(Args, {MA, TRef, BQS2})
371378
end.
372379

373380
%% We are partitioning messages by the Unacked element in the tuple.

0 commit comments

Comments
 (0)