summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2011-02-24 14:29:25 +0000
committerSimon MacMullen <simon@rabbitmq.com>2011-02-24 14:29:25 +0000
commit64fc40f4a222d04a974bd10ab1fa0b46ceb2f967 (patch)
tree8e61c1347bd1e3aeee6f196cba5e4a51e5055c67
parent43c93e349a527da111791a276bc445392169a12f (diff)
parentcc858f2e62aaa48f7a87f381ab2c6a9d792fa42c (diff)
downloadrabbitmq-server-git-64fc40f4a222d04a974bd10ab1fa0b46ceb2f967.tar.gz
Merge bug23877 into default.
-rw-r--r--src/rabbit_mnesia.erl55
1 files changed, 29 insertions, 26 deletions
diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl
index d3cb492efc..fc95b77b36 100644
--- a/src/rabbit_mnesia.erl
+++ b/src/rabbit_mnesia.erl
@@ -282,45 +282,48 @@ ensure_schema_integrity() ->
check_schema_integrity() ->
Tables = mnesia:system_info(tables),
- case [Error || {Tab, TabDef} <- table_definitions(),
- case lists:member(Tab, Tables) of
- false ->
- Error = {table_missing, Tab},
- true;
- true ->
- {_, ExpAttrs} = proplists:lookup(attributes, TabDef),
- Attrs = mnesia:table_info(Tab, attributes),
- Error = {table_attributes_mismatch, Tab,
- ExpAttrs, Attrs},
- Attrs /= ExpAttrs
- end] of
- [] -> check_table_integrity();
- Errors -> {error, Errors}
+ case check_tables(fun (Tab, TabDef) ->
+ case lists:member(Tab, Tables) of
+ false -> {error, {table_missing, Tab}};
+ true -> check_table_attributes(Tab, TabDef)
+ end
+ end) of
+ ok -> ok = wait_for_tables(),
+ check_tables(fun check_table_content/2);
+ Other -> Other
end.
-check_table_integrity() ->
- ok = wait_for_tables(),
- case lists:all(fun ({Tab, TabDef}) ->
- {_, Match} = proplists:lookup(match, TabDef),
- read_test_table(Tab, Match)
- end, table_definitions()) of
- true -> ok;
- false -> {error, invalid_table_content}
+check_table_attributes(Tab, TabDef) ->
+ {_, ExpAttrs} = proplists:lookup(attributes, TabDef),
+ case mnesia:table_info(Tab, attributes) of
+ ExpAttrs -> ok;
+ Attrs -> {error, {table_attributes_mismatch, Tab, ExpAttrs, Attrs}}
end.
-read_test_table(Tab, Match) ->
+check_table_content(Tab, TabDef) ->
+ {_, Match} = proplists:lookup(match, TabDef),
case mnesia:dirty_first(Tab) of
'$end_of_table' ->
- true;
+ ok;
Key ->
ObjList = mnesia:dirty_read(Tab, Key),
MatchComp = ets:match_spec_compile([{Match, [], ['$_']}]),
case ets:match_spec_run(ObjList, MatchComp) of
- ObjList -> true;
- _ -> false
+ ObjList -> ok;
+ _ -> {error, {table_content_invalid, Tab, Match, ObjList}}
end
end.
+check_tables(Fun) ->
+ case [Error || {Tab, TabDef} <- table_definitions(),
+ case Fun(Tab, TabDef) of
+ ok -> Error = none, false;
+ {error, Error} -> true
+ end] of
+ [] -> ok;
+ Errors -> {error, Errors}
+ end.
+
%% The cluster node config file contains some or all of the disk nodes
%% that are members of the cluster this node is / should be a part of.
%%