-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmnesia_schema_symmetry.erl
40 lines (37 loc) · 2.03 KB
/
mnesia_schema_symmetry.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
%% @copyright Geoff Cant 2009
%% @author Geoff Cant <[email protected]>
%% @version {@vsn}, {@date} {@time}
%% @doc Alter table copy types to match types on a specific node.
%% @end
f(SchemaDiff).
SchemaDiff = fun (IdealNode, OtherNodes) ->
Tables = rpc:call(IdealNode, mnesia, system_info, [tables]),
TableTypes = [{T, rpc:call(IdealNode, mnesia, table_info, [T, storage_type])}
|| T <- Tables],
[{Table, Type, [ case rpc:call(N, mnesia, table_info, [Table, storage_type]) of
Type -> {ok, N};
unknown ->
{missing, N};
Other ->
{different_type, Other, N}
end
|| N <- OtherNodes]}
|| {Table, Type} <- TableTypes]
end.
f(Rebalance).
Rebalance = fun (IdealNode, OtherNodes) ->
Tables = rpc:call(IdealNode, mnesia, system_info, [tables]),
TableTypes = [{T, rpc:call(IdealNode, mnesia, table_info, [T, storage_type])}
|| T <- Tables],
[{Table, Type, [ case rpc:call(N, mnesia, table_info, [Table, storage_type]) of
Type -> N;
unknown ->
{atomic, ok} = mnesia:add_table_copy(Table, N, Type),
{added, N};
Other ->
{atomic, ok} = mnesia:change_table_copy_type(Table, N, Type),
{fixed, N}
end
|| N <- OtherNodes]}
|| {Table, Type} <- TableTypes]
end.