Moving mnesia schema to another node

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Moving mnesia schema to another node

chandru
Look in the Mnesia user guide in Section 6.9.1

The following example illustrates how mnesia:traverse_backup can be used to
rename a db_node in a backup file:

change_node_name(Mod, From, To, Source, Target) ->
    Switch =
        fun(Node) when Node == From -> To;
           (Node) when Node == To -> throw({error, already_exists});
           (Node) -> Node
        end,
    Convert =
        fun({schema, db_nodes, Nodes}, Acc) ->
                {[{schema, db_nodes, lists:map(Switch,Nodes)}], Acc};
           ({schema, version, Version}, Acc) ->
                {[{schema, version, Version}], Acc};
           ({schema, cookie, Cookie}, Acc) ->
                {[{schema, cookie, Cookie}], Acc};
           ({schema, Tab, CreateList}, Acc) ->
                Keys = [ram_copies, disc_copies, disc_only_copies],
                OptSwitch =
                    fun({Key, Val}) ->
                            case lists:member(Key, Keys) of
                                true -> {Key, lists:map(Switch, Val)};
                                false-> {Key, Val}
                            end
                    end,
                {[{schema, Tab, lists:map(OptSwitch, CreateList)}], Acc};
           (Other, Acc) ->
                {[Other], Acc}
        end,
    mnesia:traverse_backup(Source, Mod, Target, Mod, Convert, switched).

view(Source, Mod) ->
    View = fun(Item, Acc) ->
                   io:format("~p.~n",[Item]),
                   {[Item], Acc + 1}
           end,
    mnesia:traverse_backup(Source, Mod, dummy, read_only, View, 0).

cheers,
Chandru

> -----Original Message-----
> From: Erik Pearson [mailto:erik]
> Sent: 25 December 2001 02:19
> To: erlang-questions
> Subject: Moving mnesia schema to another node
>
>
> Hi,
>
> I need to move a mnesia database from one node to another,
> and haven't been
> able to figure out how. Mnesia is okay if you move it around
> on the same
> machine (different directories), but doesn't like to be moved
> to another
> machine -- (e.g. tar it up and untar it somehwere else) --
> even if the
> database directory is accessed via a generic directory name
> through an
> explicit -mnesia dir 'dirname' or -config configfile.
>
> I've also tried restoring from a backup, but stopped that
> after it ate up
> all CPU on the server. I also tried using install_fallback,
> but mnesia
> complains with
>
> {"No disc resident schema on local node", [myoldnode]}
>
> The backup seems to keep a reference to the old node, and
> doens't like to
> be restored anywhere else...
>
> Does anyone know how to do a "redirected backup and restore"
> from one node
> to another?
>
> Thanks,
>
> Erik Pearson
>



NOTICE AND DISCLAIMER:
This email (including attachments) is confidential.  If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents.  We cannot accept liability for any breaches of
confidence arising through use of email.  Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions.  We will not accept responsibility for any commitments
made by our employees outside the scope of our business.  We do not warrant
the accuracy or completeness of such information.



Reply | Threaded
Open this post in threaded view
|

Moving mnesia schema to another node

Erik Pearson-2
Thanks for the pointer. I just returned from winter holiday and will apply
this technique shortly. It seems like an awfully inefficient way of
changing just the node for a table, especially if one is dealing with large
tables.

(Should there not be a simpler technique for moving disc based tables from
one node to another? E.g. substitution of table attributes at either backup
or restore (and a table creation option for restore))

Erik.

--On Tuesday, December 25, 2001 9:17 AM +0000 Chandrashekhar Mullaparthi
<Chandrashekhar.Mullaparthi> wrote:

> Look in the Mnesia user guide in Section 6.9.1
>
> The following example illustrates how mnesia:traverse_backup can be used
> to rename a db_node in a backup file:
>
> change_node_name(Mod, From, To, Source, Target) ->
>     Switch =
>         fun(Node) when Node == From -> To;
>            (Node) when Node == To -> throw({error, already_exists});
>            (Node) -> Node
>         end,
>     Convert =
>         fun({schema, db_nodes, Nodes}, Acc) ->
>                 {[{schema, db_nodes, lists:map(Switch,Nodes)}], Acc};
>            ({schema, version, Version}, Acc) ->
>                 {[{schema, version, Version}], Acc};
>            ({schema, cookie, Cookie}, Acc) ->
>                 {[{schema, cookie, Cookie}], Acc};
>            ({schema, Tab, CreateList}, Acc) ->
>                 Keys = [ram_copies, disc_copies, disc_only_copies],
>                 OptSwitch =
>                     fun({Key, Val}) ->
>                             case lists:member(Key, Keys) of
>                                 true -> {Key, lists:map(Switch, Val)};
>                                 false-> {Key, Val}
>                             end
>                     end,
>                 {[{schema, Tab, lists:map(OptSwitch, CreateList)}], Acc};
>            (Other, Acc) ->
>                 {[Other], Acc}
>         end,
>     mnesia:traverse_backup(Source, Mod, Target, Mod, Convert, switched).
>
> view(Source, Mod) ->
>     View = fun(Item, Acc) ->
>                    io:format("~p.~n",[Item]),
>                    {[Item], Acc + 1}
>            end,
>     mnesia:traverse_backup(Source, Mod, dummy, read_only, View, 0).
>
> cheers,
> Chandru
>
>> -----Original Message-----
>> From: Erik Pearson [mailto:erik]
>> Sent: 25 December 2001 02:19
>> To: erlang-questions
>> Subject: Moving mnesia schema to another node
>>
>>
>> Hi,
>>
>> I need to move a mnesia database from one node to another,
>> and haven't been
>> able to figure out how. Mnesia is okay if you move it around
>> on the same
>> machine (different directories), but doesn't like to be moved
>> to another
>> machine -- (e.g. tar it up and untar it somehwere else) --
>> even if the
>> database directory is accessed via a generic directory name
>> through an
>> explicit -mnesia dir 'dirname' or -config configfile.
>>
>> I've also tried restoring from a backup, but stopped that
>> after it ate up
>> all CPU on the server. I also tried using install_fallback,
>> but mnesia
>> complains with
>>
>> {"No disc resident schema on local node", [myoldnode]}
>>
>> The backup seems to keep a reference to the old node, and
>> doens't like to
>> be restored anywhere else...
>>
>> Does anyone know how to do a "redirected backup and restore"
>> from one node
>> to another?
>>
>> Thanks,
>>
>> Erik Pearson
>>
>
>
>
> NOTICE AND DISCLAIMER:
> This email (including attachments) is confidential.  If you have received
> this email in error please notify the sender immediately and delete this
> email from your system without copying or disseminating it or placing any
> reliance upon its contents.  We cannot accept liability for any breaches
> of confidence arising through use of email.  Any opinions expressed in
> this email (including attachments) are those of the author and do not
> necessarily reflect our opinions.  We will not accept responsibility for
> any commitments made by our employees outside the scope of our business.
> We do not warrant the accuracy or completeness of such information.
>



Erik Pearson
@ Adaptations
email     : erik
voice/fax : +1 510 527 5437
text page : page.erik



Reply | Threaded
Open this post in threaded view
|

Moving mnesia schema to another node

Ulf Wiger-4
On Fri, 11 Jan 2002, Erik Pearson wrote:

>Thanks for the pointer. I just returned from winter holiday and will apply
>this technique shortly. It seems like an awfully inefficient way of
>changing just the node for a table, especially if one is dealing with large
>tables.
>
>(Should there not be a simpler technique for moving disc based tables from
>one node to another? E.g. substitution of table attributes at either backup
>or restore (and a table creation option for restore))
>
>Erik.

In a running system, you'd simply call
mnesia:delete_table_copy(...)  / mnesia:add_table_copy(...). The
technique of traversing the backup is rather a means to relocate
the entire database.

/Uffe



Reply | Threaded
Open this post in threaded view
|

Moving mnesia schema to another node

Erik Pearson-2
Doesn't this imply that the node that the table is being moved to is
accessible from the node that the table currently exists on?

In any case, I was being imprecise. I was just noting that a simple method
of copying individual tables, a database, or a portion of a database from
one node to another would be convenient. E.g. in a relational db like DB2,
you can backup an active database, and restore it to another maching, disk,
etc., or you can export an individual table from one database and import it
into another. Perhaps my expectations are different because I'm not really
using Erlang in its classic mode, but rather mostly for standalone
applications. In my usage, it is common to develop an application on one
machine (node) and then deploy on another, then make changes to the
development, them update the production version, and so on. Normally the
production version is not active, but only run periodically. In that usage
model, it makes a lot of sense to make moving tables or entire databases as
easy as moving source code files.

Erik.

--On Monday, January 14, 2002 6:00 PM +0100 Ulf Wiger
<etxuwig> wrote:

> On Fri, 11 Jan 2002, Erik Pearson wrote:
>
>> Thanks for the pointer. I just returned from winter holiday and will
>> apply this technique shortly. It seems like an awfully inefficient way of
>> changing just the node for a table, especially if one is dealing with
>> large tables.
>>
>> (Should there not be a simpler technique for moving disc based tables
>> from one node to another? E.g. substitution of table attributes at
>> either backup or restore (and a table creation option for restore))
>>
>> Erik.
>
> In a running system, you'd simply call
> mnesia:delete_table_copy(...)  / mnesia:add_table_copy(...). The
> technique of traversing the backup is rather a means to relocate
> the entire database.
>
> /Uffe
>



Erik Pearson
@ Adaptations
email     : erik
voice/fax : +1 510 527 5437
text page : page.erik



Reply | Threaded
Open this post in threaded view
|

Moving mnesia schema to another node

Ulf Wiger-4
On Mon, 14 Jan 2002, Erik Pearson wrote:

>Doesn't this imply that the node that the table is being moved to is
>accessible from the node that the table currently exists on?

Yes, it does.

Mnesia is a bit unusual in that it provides a lot of nice
functions for dynamically reconfiguring and transforming the
database in a running system, while being quite weak on offline
configuration (compared to traditional RDBMSs).

Hopefully, more offline tools will emerge as Mnesia makes it into
other types of application.

/Uffe