aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mnesia/src/mnesia_schema.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mnesia/src/mnesia_schema.erl')
-rw-r--r--lib/mnesia/src/mnesia_schema.erl55
1 files changed, 48 insertions, 7 deletions
diff --git a/lib/mnesia/src/mnesia_schema.erl b/lib/mnesia/src/mnesia_schema.erl
index 782493fb4f..76a9dbf26c 100644
--- a/lib/mnesia/src/mnesia_schema.erl
+++ b/lib/mnesia/src/mnesia_schema.erl
@@ -647,7 +647,15 @@ cs2list(Cs) when is_record(Cs, cstruct) ->
cs2list(CreateList) when is_list(CreateList) ->
CreateList;
-%% since 4.6
+cs2list(Cs) when element(1, Cs) == cstruct, tuple_size(Cs) == 20 ->
+ Tags = [name,type,
+ ram_copies,disc_copies,disc_only_copies,external_copies,
+ load_order,access_mode,majority,index,snmp,local_content,
+ record_name,attributes,
+ user_properties,frag_properties,storage_properties,
+ cookie,version],
+ rec2list(Tags, Tags, 2, Cs);
+%% since vsn-4.6 (protocol 8.2 or older)
cs2list(Cs) when element(1, Cs) == cstruct, tuple_size(Cs) == 19 ->
Tags = [name,type,ram_copies,disc_copies,disc_only_copies,
load_order,access_mode,majority,index,snmp,local_content,
@@ -657,7 +665,17 @@ cs2list(Cs) when element(1, Cs) == cstruct, tuple_size(Cs) == 19 ->
rec2list(Tags, Tags, 2, Cs).
cs2list(false, Cs) ->
- cs2list(Cs).
+ cs2list(Cs);
+cs2list({8,3}, Cs) ->
+ cs2list(Cs);
+cs2list({8,Minor}, Cs) when Minor =:= 2; Minor =:= 1 ->
+ Orig = record_info(fields, cstruct),
+ Tags = [name,type,ram_copies,disc_copies,disc_only_copies,
+ load_order,access_mode,majority,index,snmp,local_content,
+ record_name,attributes,
+ user_properties,frag_properties,storage_properties,
+ cookie,version],
+ rec2list(Tags, Orig, 2, Cs).
rec2list([Tag | Tags], [Tag | Orig], Pos, Rec) ->
Val = element(Pos, Rec),
@@ -667,8 +685,19 @@ rec2list([], _, _Pos, _Rec) ->
rec2list(Tags, [_|Orig], Pos, Rec) ->
rec2list(Tags, Orig, Pos+1, Rec).
-normalize_cs(Cstructs, _Node) ->
- Cstructs.
+normalize_cs(Cstructs, Node) ->
+ %% backward-compatibility hack; normalize before returning
+ case need_old_cstructs([Node]) of
+ false ->
+ Cstructs;
+ Version ->
+ %% some other format
+ [convert_cs(Version, Cs) || Cs <- Cstructs]
+ end.
+
+convert_cs(Version, Cs) ->
+ Fields = [Value || {_, Value} <- cs2list(Version, Cs)],
+ list_to_tuple([cstruct|Fields]).
list2cs(List) when is_list(List) ->
Name = pick(unknown, name, List, must),
@@ -2795,11 +2824,23 @@ do_merge_schema(LockTabs0) ->
end.
fetch_cstructs(Node) ->
- rpc:call(Node, mnesia_controller, get_remote_cstructs, []).
+ Convert = mnesia_monitor:needs_protocol_conversion(Node),
+ case rpc:call(Node, mnesia_controller, get_remote_cstructs, []) of
+ {cstructs, Cs0, RemoteRunning1} when Convert ->
+ {cstructs, [list2cs(cs2list(Cs)) || Cs <- Cs0], RemoteRunning1};
+ Result ->
+ Result
+ end.
-need_old_cstructs() -> false.
+need_old_cstructs() ->
+ need_old_cstructs(val({schema, where_to_write})).
-need_old_cstructs(_Nodes) -> false.
+need_old_cstructs(Nodes) ->
+ Filter = fun(Node) -> mnesia_monitor:needs_protocol_conversion(Node) end,
+ case lists:filter(Filter, Nodes) of
+ [] -> false;
+ Ns -> lists:min([element(1, ?catch_val({protocol, Node})) || Node <- Ns])
+ end.
tab_to_nodes(Tab) when is_atom(Tab) ->
Cs = val({Tab, cstruct}),