summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Scvortov <alexandru@rabbitmq.com>2010-08-05 18:51:40 +0100
committerAlexandru Scvortov <alexandru@rabbitmq.com>2010-08-05 18:51:40 +0100
commit3ba9a25edca5dafe46e30ab6e42ec0c775f3141b (patch)
tree126204fb0b1bf74d23a954a923f7572c0d58fd51
parentad6fde4fd7a44a44dda489f07248c0ba35ead067 (diff)
downloadrabbitmq-server-3ba9a25edca5dafe46e30ab6e42ec0c775f3141b.tar.gz
check that mnesia table attributes are as expected
-rw-r--r--src/rabbit_mnesia.erl30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl
index c808499b..af0f53b3 100644
--- a/src/rabbit_mnesia.erl
+++ b/src/rabbit_mnesia.erl
@@ -167,7 +167,8 @@ table_definitions() ->
{attributes, record_info(fields, vhost)},
{disc_copies, [node()]}]},
{rabbit_config,
- [{disc_copies, [node()]}]},
+ [{attributes, [key, val]}, % same mnesia's default
+ {disc_copies, [node()]}]},
{rabbit_listener,
[{record_name, listener},
{attributes, record_info(fields, listener)},
@@ -232,10 +233,29 @@ ensure_mnesia_not_running() ->
end.
check_schema_integrity() ->
- %%TODO: more thorough checks
- case catch [mnesia:table_info(Tab, version) || Tab <- table_names()] of
- {'EXIT', Reason} -> {error, Reason};
- _ -> ok
+ try
+ % Check that all tables are present
+ case catch [mnesia:table_info(Tab, version) || Tab <- table_names()] of
+ {'EXIT', Reason} -> throw({missing_table, Reason});
+ _ -> ok
+ end,
+ % Check that tables are defined correctly
+ TabDefs = table_definitions(),
+ lists:foreach(fun(Tab) ->
+ {_, TabDef} = proplists:lookup(Tab, TabDefs),
+ {_, ExpAttrs} = proplists:lookup(attributes, TabDef),
+ Attrs = mnesia:table_info(Tab, attributes),
+ case lists:usort(ExpAttrs) /= lists:usort(Attrs) of
+ true ->
+ throw({table_not_defined_correctly, Tab});
+ _ ->
+ ok
+ end
+ end, table_names()),
+ ok
+ catch
+ throw:Why ->
+ {error, Why}
end.
%% The cluster node config file contains some or all of the disk nodes