bootstrapping rdbms
Ulf Wiger (AL/EAB)
ulf.wiger@REDACTED
Sun Mar 5 18:23:02 CET 2006
I'm not having any luck getting in touch with
sourceforge at the moment. Don't know if it's
a problem on my end, or at sourceforge.
Anyway, I thought I'd check in the following
addition in rdbms.erl. The idea was that you
could try out rdbms easier if you didn't have
to recompile the original mnesia modules.
As long as you compile the rdbms/mnesia-patches/src
and start erlang with -pa $rdbms/mnesia-patches/ebin
(and, of course, -pa $rdbms/ebin), then you can
call
rdbms:patch_mnesia()
before calling
mnesia:start([{access_module, rdbms}]).
The patch_mnesia() function will recompile the mnesia
code in memory, not touching the source on disk. It
adds one attribute to the cstruct record, so you won't
be able to use an existing database without converting
the data first (no code provided for that.) You _can_
create new databases, though.
Obviously, the patch_mnesia() function will have to be
called again, any time the node is restarted.
I'll check it into cvs whenever I can establish contact
again.
/Ulf W
patch_mnesia() ->
application:load(mnesia),
{ok,Ms} = application:get_key(mnesia, modules),
ToPatch = Ms -- [mnesia, mnesia_controller, mnesia_frag,
mnesia_lib, mnesia_loader, mnesia_log,
mnesia_schema, mnesia_tm],
OrigDir = filename:join(code:lib_dir(mnesia), "ebin"),
lists:foreach(
fun(M) ->
F = filename:join(
OrigDir,atom_to_list(M) ++
code:objfile_extension()),
{ok,{_M,[{abstract_code,{raw_abstract_v1,Forms}}]}} =
beam_lib:chunks(F, [abstract_code]),
[_|TailF] = Forms,
io:format("Transforming ~p ... ", [M]),
NewTailF = transform_mod(TailF),
{ok, Module, Bin} = compile:forms(NewTailF, []),
io:format("ok.~n", []),
case code:load_binary(Module, foo, Bin) of
{module, Module} ->
ok;
Error ->
erlang:error({Error,Module})
end
end, ToPatch).
transform_mod(Fs) ->
lists:map(fun({attribute,L,record,{cstruct,Flds}}) ->
{attribute,L,record,{cstruct, insert_attr(Flds)}};
(X) -> X
end, Fs).
insert_attr([{record_field,L,{atom,_,load_order},_} = H|T]) ->
[{record_field,L,{atom,L,external_copies}, {nil,L}},H|T];
insert_attr([H|T]) ->
[H|insert_attr(T)];
insert_attr([]) ->
[].
More information about the erlang-questions
mailing list