summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2017-05-09 11:50:50 +0200
committerJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2017-05-19 16:34:31 +0200
commitd34d403e360d9d5c15c607a307fb49d1c0992d14 (patch)
treee23b4a2ceba92237376661c3d29ae9d30ae7dcd6 /src
parent58d7abdd8b1634f6c839ac4cc3846f6e59a365f2 (diff)
downloadrabbitmq-server-git-d34d403e360d9d5c15c607a307fb49d1c0992d14.tar.gz
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]
Diffstat (limited to 'src')
-rw-r--r--src/file_handle_cache.erl34
-rw-r--r--src/rabbit_fhc_helpers.erl52
2 files changed, 54 insertions, 32 deletions
diff --git a/src/file_handle_cache.erl b/src/file_handle_cache.erl
index d4f83be513..af51718873 100644
--- a/src/file_handle_cache.erl
+++ b/src/file_handle_cache.erl
@@ -149,7 +149,7 @@
open_with_absolute_path/3]).
-export([obtain/0, obtain/1, release/0, release/1, transfer/1, transfer/2,
set_limit/1, get_limit/0, info_keys/0, with_handle/1, with_handle/2,
- info/0, info/1, clear_read_cache/0]).
+ info/0, info/1, clear_read_cache/0, clear_process_read_cache/0]).
-export([ulimit/0]).
-export([start_link/0, start_link/2, init/1, handle_call/3, handle_cast/2,
@@ -165,8 +165,6 @@
-define(CLIENT_ETS_TABLE, file_handle_cache_client).
-define(ELDERS_ETS_TABLE, file_handle_cache_elders).
--include("rabbit.hrl"). % For #amqqueue record definition.
-
%%----------------------------------------------------------------------------
-record(file,
@@ -601,35 +599,7 @@ info() -> info(?INFO_KEYS).
info(Items) -> gen_server2:call(?SERVER, {info, Items}, infinity).
clear_read_cache() ->
- case application:get_env(rabbit, fhc_read_buffering) of
- {ok, true} ->
- gen_server2:cast(?SERVER, clear_read_cache),
- clear_vhost_read_cache(rabbit_vhost:list());
- _ -> %% undefined or {ok, false}
- ok
- end.
-
-clear_vhost_read_cache([]) ->
- ok;
-clear_vhost_read_cache([VHost | Rest]) ->
- clear_queue_read_cache(rabbit_amqqueue:list(VHost)),
- clear_vhost_read_cache(Rest).
-
-clear_queue_read_cache([]) ->
- ok;
-clear_queue_read_cache([#amqqueue{pid = MPid, slave_pids = SPids} | Rest]) ->
- %% Limit the action to the current node.
- Pids = [P || P <- [MPid | SPids], node(P) =:= node()],
- %% This function is executed in the context of the backing queue
- %% process because the read buffer is stored in the process
- %% dictionary.
- Fun = fun(_, State) ->
- _ = clear_process_read_cache(),
- State
- end,
- [rabbit_amqqueue:run_backing_queue(Pid, rabbit_variable_queue, Fun)
- || Pid <- Pids],
- clear_queue_read_cache(Rest).
+ gen_server2:cast(?SERVER, clear_read_cache).
clear_process_read_cache() ->
[
diff --git a/src/rabbit_fhc_helpers.erl b/src/rabbit_fhc_helpers.erl
new file mode 100644
index 0000000000..5f19eff087
--- /dev/null
+++ b/src/rabbit_fhc_helpers.erl
@@ -0,0 +1,52 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and
+%% limitations under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is GoPivotal, Inc.
+%% Copyright (c) 2007-2017 Pivotal Software, Inc. All rights reserved.
+%%
+
+-module(rabbit_fhc_helpers).
+
+-export([clear_read_cache/0]).
+
+-include("rabbit.hrl"). % For #amqqueue record definition.
+
+clear_read_cache() ->
+ case application:get_env(rabbit, fhc_read_buffering) of
+ {ok, true} ->
+ file_handle_cache:clear_read_cache(),
+ clear_vhost_read_cache(rabbit_vhost:list());
+ _ -> %% undefined or {ok, false}
+ ok
+ end.
+
+clear_vhost_read_cache([]) ->
+ ok;
+clear_vhost_read_cache([VHost | Rest]) ->
+ clear_queue_read_cache(rabbit_amqqueue:list(VHost)),
+ clear_vhost_read_cache(Rest).
+
+clear_queue_read_cache([]) ->
+ ok;
+clear_queue_read_cache([#amqqueue{pid = MPid, slave_pids = SPids} | Rest]) ->
+ %% Limit the action to the current node.
+ Pids = [P || P <- [MPid | SPids], node(P) =:= node()],
+ %% This function is executed in the context of the backing queue
+ %% process because the read buffer is stored in the process
+ %% dictionary.
+ Fun = fun(_, State) ->
+ _ = file_handle_cache:clear_process_read_cache(),
+ State
+ end,
+ [rabbit_amqqueue:run_backing_queue(Pid, rabbit_variable_queue, Fun)
+ || Pid <- Pids],
+ clear_queue_read_cache(Rest).