Skip to content

Commit d34d403

Browse files
committed
file_handle_cache: Move RabbitMQ-specific functions to rabbit_fhc_helpers
Those are the functions to clear the read buffer cache in various internal RabbitMQ processes. file_handle_cache still reads the `fhc_read_buffering` and `fhc_write_buffering` rabbit application variables, though. Thus, this change almost removes a dependency of file_handle_cache on the broker. Reading the configuration variable is acceptable for now so this will allow us to move file_handle_cache to rabbitmq-common. [#118490793]
1 parent 58d7abd commit d34d403

File tree

2 files changed

+54
-32
lines changed

2 files changed

+54
-32
lines changed

src/file_handle_cache.erl

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
open_with_absolute_path/3]).
150150
-export([obtain/0, obtain/1, release/0, release/1, transfer/1, transfer/2,
151151
set_limit/1, get_limit/0, info_keys/0, with_handle/1, with_handle/2,
152-
info/0, info/1, clear_read_cache/0]).
152+
info/0, info/1, clear_read_cache/0, clear_process_read_cache/0]).
153153
-export([ulimit/0]).
154154

155155
-export([start_link/0, start_link/2, init/1, handle_call/3, handle_cast/2,
@@ -165,8 +165,6 @@
165165
-define(CLIENT_ETS_TABLE, file_handle_cache_client).
166166
-define(ELDERS_ETS_TABLE, file_handle_cache_elders).
167167

168-
-include("rabbit.hrl"). % For #amqqueue record definition.
169-
170168
%%----------------------------------------------------------------------------
171169

172170
-record(file,
@@ -601,35 +599,7 @@ info() -> info(?INFO_KEYS).
601599
info(Items) -> gen_server2:call(?SERVER, {info, Items}, infinity).
602600

603601
clear_read_cache() ->
604-
case application:get_env(rabbit, fhc_read_buffering) of
605-
{ok, true} ->
606-
gen_server2:cast(?SERVER, clear_read_cache),
607-
clear_vhost_read_cache(rabbit_vhost:list());
608-
_ -> %% undefined or {ok, false}
609-
ok
610-
end.
611-
612-
clear_vhost_read_cache([]) ->
613-
ok;
614-
clear_vhost_read_cache([VHost | Rest]) ->
615-
clear_queue_read_cache(rabbit_amqqueue:list(VHost)),
616-
clear_vhost_read_cache(Rest).
617-
618-
clear_queue_read_cache([]) ->
619-
ok;
620-
clear_queue_read_cache([#amqqueue{pid = MPid, slave_pids = SPids} | Rest]) ->
621-
%% Limit the action to the current node.
622-
Pids = [P || P <- [MPid | SPids], node(P) =:= node()],
623-
%% This function is executed in the context of the backing queue
624-
%% process because the read buffer is stored in the process
625-
%% dictionary.
626-
Fun = fun(_, State) ->
627-
_ = clear_process_read_cache(),
628-
State
629-
end,
630-
[rabbit_amqqueue:run_backing_queue(Pid, rabbit_variable_queue, Fun)
631-
|| Pid <- Pids],
632-
clear_queue_read_cache(Rest).
602+
gen_server2:cast(?SERVER, clear_read_cache).
633603

634604
clear_process_read_cache() ->
635605
[

src/rabbit_fhc_helpers.erl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License
4+
%% at http://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
%% the License for the specific language governing rights and
9+
%% limitations under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developer of the Original Code is GoPivotal, Inc.
14+
%% Copyright (c) 2007-2017 Pivotal Software, Inc. All rights reserved.
15+
%%
16+
17+
-module(rabbit_fhc_helpers).
18+
19+
-export([clear_read_cache/0]).
20+
21+
-include("rabbit.hrl"). % For #amqqueue record definition.
22+
23+
clear_read_cache() ->
24+
case application:get_env(rabbit, fhc_read_buffering) of
25+
{ok, true} ->
26+
file_handle_cache:clear_read_cache(),
27+
clear_vhost_read_cache(rabbit_vhost:list());
28+
_ -> %% undefined or {ok, false}
29+
ok
30+
end.
31+
32+
clear_vhost_read_cache([]) ->
33+
ok;
34+
clear_vhost_read_cache([VHost | Rest]) ->
35+
clear_queue_read_cache(rabbit_amqqueue:list(VHost)),
36+
clear_vhost_read_cache(Rest).
37+
38+
clear_queue_read_cache([]) ->
39+
ok;
40+
clear_queue_read_cache([#amqqueue{pid = MPid, slave_pids = SPids} | Rest]) ->
41+
%% Limit the action to the current node.
42+
Pids = [P || P <- [MPid | SPids], node(P) =:= node()],
43+
%% This function is executed in the context of the backing queue
44+
%% process because the read buffer is stored in the process
45+
%% dictionary.
46+
Fun = fun(_, State) ->
47+
_ = file_handle_cache:clear_process_read_cache(),
48+
State
49+
end,
50+
[rabbit_amqqueue:run_backing_queue(Pid, rabbit_variable_queue, Fun)
51+
|| Pid <- Pids],
52+
clear_queue_read_cache(Rest).

0 commit comments

Comments
 (0)