Skip to content

Commit 7b71672

Browse files
author
Simon MacMullen
committed
It's possible somehow we could be left with an empty mnesia directory (spotted with "make cleandb" but maybe other things could do this). So instead check for the existence of the guid serial, which has not changed since at least 1.7.0.
1 parent 975806e commit 7b71672

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/rabbit_guid.erl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-behaviour(gen_server).
2020

2121
-export([start_link/0]).
22+
-export([filename/0]).
2223
-export([gen/0, gen_secure/0, string/2, binary/2]).
2324

2425
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
@@ -38,6 +39,7 @@
3839
-type(guid() :: binary()).
3940

4041
-spec(start_link/0 :: () -> rabbit_types:ok_pid_or_error()).
42+
-spec(filename/0 :: () -> string()).
4143
-spec(gen/0 :: () -> guid()).
4244
-spec(gen_secure/0 :: () -> guid()).
4345
-spec(string/2 :: (guid(), any()) -> string()).
@@ -51,8 +53,14 @@ start_link() ->
5153
gen_server:start_link({local, ?SERVER}, ?MODULE,
5254
[update_disk_serial()], []).
5355

56+
%% We use this to detect a (possibly rather old) Mnesia directory,
57+
%% since it has existed since at least 1.7.0 (as far back as I cared
58+
%% to go).
59+
filename() ->
60+
filename:join(rabbit_mnesia:dir(), ?SERIAL_FILENAME).
61+
5462
update_disk_serial() ->
55-
Filename = filename:join(rabbit_mnesia:dir(), ?SERIAL_FILENAME),
63+
Filename = filename(),
5664
Serial = case rabbit_file:read_term_file(Filename) of
5765
{ok, [Num]} -> Num;
5866
{error, enoent} -> 0;

src/rabbit_version.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ record_desired_for_scope(Scope) ->
9696
upgrades_required(Scope) ->
9797
case recorded_for_scope(Scope) of
9898
{error, enoent} ->
99-
case filelib:is_dir(rabbit_mnesia:dir() ++ "/") of
99+
case filelib:is_file(rabbit_guid:filename()) of
100100
false -> {ok, []}; %% We're blank, no upgrade needed
101101
true -> {error, version_not_available}
102102
end;

0 commit comments

Comments
 (0)