summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2015-05-21 18:56:57 +0200
committerJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2015-05-21 18:56:57 +0200
commit3a76c1536748ba2a684b5e815f20bb7f8b6f29a4 (patch)
treeb7f209e906c69c4e995ee15bbbd6afacf71d33a3
parent79da7e3a17b07425797acbb5dfd76821799c6b69 (diff)
parentb710efcbf80867334bdffe4bd71990eafd44285d (diff)
downloadrabbitmq-server-git-3a76c1536748ba2a684b5e815f20bb7f8b6f29a4.tar.gz
Merge branch 'rabbitmq-server-157' into stable
-rw-r--r--src/rabbit.erl31
-rw-r--r--src/rabbit_table.erl14
2 files changed, 38 insertions, 7 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 24883dc6d4..ee87739337 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -885,6 +885,33 @@ config_setting() ->
%% We don't want this in fhc since it references rabbit stuff. And we can't put
%% this in the bootstep directly.
start_fhc() ->
- rabbit_sup:start_restartable_child(
+ ok = rabbit_sup:start_restartable_child(
file_handle_cache,
- [fun rabbit_alarm:set_alarm/1, fun rabbit_alarm:clear_alarm/1]).
+ [fun rabbit_alarm:set_alarm/1, fun rabbit_alarm:clear_alarm/1]),
+ ensure_working_fhc().
+
+ensure_working_fhc() ->
+ %% To test the file handle cache, we simply read a file we know it
+ %% exists (Erlang kernel's .app file).
+ %%
+ %% To avoid any pollution of the application process' dictionary by
+ %% file_handle_cache, we spawn a separate process.
+ Parent = self(),
+ TestFun = fun() ->
+ Filename = filename:join(code:lib_dir(kernel, ebin), "kernel.app"),
+ {ok, Fd} = file_handle_cache:open(Filename, [raw, binary, read], []),
+ {ok, _} = file_handle_cache:read(Fd, 1),
+ ok = file_handle_cache:close(Fd),
+ Parent ! fhc_ok
+ end,
+ TestPid = spawn_link(TestFun),
+ %% Because we are waiting for the test fun, abuse the
+ %% 'mnesia_table_loading_timeout' parameter to find a sane timeout
+ %% value.
+ Timeout = rabbit_table:wait_timeout(),
+ receive
+ fhc_ok -> ok;
+ {'EXIT', TestPid, Exception} -> throw({ensure_working_fhc, Exception})
+ after Timeout ->
+ throw({ensure_working_fhc, {timeout, TestPid}})
+ end.
diff --git a/src/rabbit_table.erl b/src/rabbit_table.erl
index 41bf958556..d425fcb8cc 100644
--- a/src/rabbit_table.erl
+++ b/src/rabbit_table.erl
@@ -18,7 +18,7 @@
-export([create/0, create_local_copy/1, wait_for_replicated/0, wait/1,
force_load/0, is_present/0, is_empty/0, needs_default_data/0,
- check_schema_integrity/0, clear_ram_only_tables/0]).
+ check_schema_integrity/0, clear_ram_only_tables/0, wait_timeout/0]).
-include("rabbit.hrl").
@@ -30,6 +30,7 @@
-spec(create_local_copy/1 :: ('disc' | 'ram') -> 'ok').
-spec(wait_for_replicated/0 :: () -> 'ok').
-spec(wait/1 :: ([atom()]) -> 'ok').
+-spec(wait_timeout/0 :: () -> non_neg_integer() | infinity).
-spec(force_load/0 :: () -> 'ok').
-spec(is_present/0 :: () -> boolean()).
-spec(is_empty/0 :: () -> boolean()).
@@ -73,10 +74,7 @@ wait_for_replicated() ->
wait(TableNames) ->
%% We might be in ctl here for offline ops, in which case we can't
%% get_env() for the rabbit app.
- Timeout = case application:get_env(rabbit, mnesia_table_loading_timeout) of
- {ok, T} -> T;
- undefined -> 30000
- end,
+ Timeout = wait_timeout(),
case mnesia:wait_for_tables(TableNames, Timeout) of
ok ->
ok;
@@ -86,6 +84,12 @@ wait(TableNames) ->
throw({error, {failed_waiting_for_tables, Reason}})
end.
+wait_timeout() ->
+ case application:get_env(rabbit, mnesia_table_loading_timeout) of
+ {ok, T} -> T;
+ undefined -> 30000
+ end.
+
force_load() -> [mnesia:force_load_table(T) || T <- names()], ok.
is_present() -> names() -- mnesia:system_info(tables) =:= [].