Skip to content

Commit

Permalink
After starting the fhc, ensure it is working
Browse files Browse the repository at this point in the history
This is a runtime check to ensure the fix proposed in #157 actually
works.

Export rabbit_table:wait_timeout/0 which returns the value of
'mnesia_table_loading_timeout' or 30000.

References #157.
  • Loading branch information
dumbbell committed May 21, 2015
1 parent 64b133c commit 10e54dd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
30 changes: 28 additions & 2 deletions src/rabbit.erl
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,32 @@ 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 add a timeout.
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.
14 changes: 9 additions & 5 deletions src/rabbit_table.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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").

Expand All @@ -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()).
Expand Down Expand Up @@ -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;
Expand All @@ -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) =:= [].
Expand Down

0 comments on commit 10e54dd

Please sign in to comment.