diff options
author | Matthew Sackman <matthew@rabbitmq.com> | 2010-08-10 18:38:15 +0100 |
---|---|---|
committer | Matthew Sackman <matthew@rabbitmq.com> | 2010-08-10 18:38:15 +0100 |
commit | 8f2f778fdfb0362a145d9da5484cc337d1262c62 (patch) | |
tree | f3c85f8a260f16794954c551589e800a7c7dc510 | |
parent | 64436988c1fe5af7620aa21835beb4de24cd43e9 (diff) | |
download | rabbitmq-server-8f2f778fdfb0362a145d9da5484cc337d1262c62.tar.gz |
Partial implementation of 3rd suggestion. Partial because I just wanted to see the shape of it rather than implement the whole thing and then possibly have to revoke it. IMO, testing on the deep structure of terms is likely sufficient
-rw-r--r-- | src/rabbit_mnesia.erl | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index 505dc28f..de6b0642 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -157,26 +157,45 @@ table_definitions() -> [{rabbit_user, [{record_name, user}, {attributes, record_info(fields, user)}, - {disc_copies, [node()]}]}, + {disc_copies, [node()]}, + {test, fun (#user{}) -> true; + (_) -> false + end}]}, {rabbit_user_permission, [{record_name, user_permission}, {attributes, record_info(fields, user_permission)}, - {disc_copies, [node()]}]}, + {disc_copies, [node()]}, + {test, fun (#user_permission{user_vhost = #user_vhost{}, + permission = #permission{}}) -> true; + (_) -> false + end}]}, {rabbit_vhost, [{record_name, vhost}, {attributes, record_info(fields, vhost)}, - {disc_copies, [node()]}]}, + {disc_copies, [node()]}, + {test, fun (#vhost{}) -> true; + (_) -> false + end}]}, {rabbit_config, [{attributes, [key, val]}, % same mnesia's default - {disc_copies, [node()]}]}, + {disc_copies, [node()]}, + {test, fun ({rabbit_config, _Key, _Value}) -> true; + (_) -> false + end}]}, {rabbit_listener, [{record_name, listener}, {attributes, record_info(fields, listener)}, - {type, bag}]}, + {type, bag}, + {test, fun (#listener{}) -> true; + (_) -> false + end}]}, {rabbit_durable_route, [{record_name, route}, {attributes, record_info(fields, route)}, - {disc_copies, [node()]}]}, + {disc_copies, [node()]}, + {test, fun (#route{binding = #binding{}}) -> true; + (_) -> false + end}]}, {rabbit_route, [{record_name, route}, {attributes, record_info(fields, route)}, @@ -246,12 +265,26 @@ check_schema_integrity() -> Attrs = mnesia:table_info(Tab, attributes), Error = {table_attributes_mismatch, Tab, ExpAttrs, Attrs}, - Attrs /= ExpAttrs + case Attrs of + ExpAttrs -> + {_, Fun} = proplists:lookup(test, TabDef), + not read_test_table(Tab, Fun, + mnesia:dirty_first(Tab)); + _ -> true + end end] of [] -> ok; Errors -> {error, Errors} end. +read_test_table(_Tab, _Fun, '$end_of_table') -> + true; +read_test_table(Tab, Fun, Key) -> + case lists:all(Fun, mnesia:dirty_read(Tab, Key)) of + true -> read_test_table(Tab, Fun, mnesia:dirty_next(Tab, Key)); + false -> false + 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. %% @@ -389,11 +422,12 @@ move_db() -> create_tables() -> lists:foreach(fun ({Tab, TabArgs}) -> - case mnesia:create_table(Tab, TabArgs) of + TabArgs1 = proplists:delete(test, TabArgs), + case mnesia:create_table(Tab, TabArgs1) of {atomic, ok} -> ok; {aborted, Reason} -> throw({error, {table_creation_failed, - Tab, TabArgs, Reason}}) + Tab, TabArgs1, Reason}}) end end, table_definitions()), |