[erlang-questions] mnesia question: full database replication across the several nodes

Paul Mineiro paul-trapexit@REDACTED
Fri Aug 28 17:54:56 CEST 2009


Thinking about your exact problem, however, it's probably simplest just to
have each node add the table copies to itself when it starts up.
Something like

mnesia:add_table_copy (TheTable, node (), TheTableType)

where TheTable is the table name (e.g., 'mytable') and TheTableType is
one of 'ram_copies', 'disc_copies', or 'disc_only_copies'.
mnesia:add_table_copy/3 is idempotent so this is relatively harmless to do
every time.  It does create a schema transaction, which can be slow under
extreme load.  I used the following "dirty schema read" to make things
faster in the case where typically the table already has a local copy.

-----------

fast_add_table_copy (TableName, Node, CopyType) ->
  try lists:member (Node, used_nodes (TableName)) of
    true -> { aborted, { already_exists, TableName, Node } };
    false -> mnesia:add_table_copy (TableName, Node, CopyType)
  catch
    _ : _ ->
      { aborted, { no_exists, TableName } }
  end.

used_nodes (TableName) ->
  lists:usort (used_nodes (TableName, ram_copies) ++
               used_nodes (TableName, disc_copies) ++
               used_nodes (TableName, disc_only_copies)).

used_nodes (TableName, CopyType) ->
  mnesia:table_info (TableName, CopyType).

-----------

Cheers,

-- p

On Fri, 28 Aug 2009, Paul Mineiro wrote:

> I wrote something called fragmentron originally intended for mnesia on
> EC2.  It takes a desired number of data copies for a table.  If you set
> this to a huge number (e.g., 999), you would get full replication of
> everything everywhere.
>
> http://code.google.com/p/fragmentron/
>
> -- p
>
> On Fri, 28 Aug 2009, Chandru wrote:
>
> > 2009/8/28 Eugen Sobchenko <esobchenko@REDACTED>
> >
> > > Hi! I have a distributed mnesia application that have to create new
> > > tables during it's work.
> > > I want to keep all tables replicated on all mnesia nodes in my
> > > cluster.
> > > What if the table has been created at the moment when some of the
> > > cluster nodes were down? Is there a standard solution to make full
> > > database replication across the several nodes?
> > >
> >
> > Table creation will fail if one (or more) of the nodes you've specified for
> > table copies is not reachable. If you want it to succeed regardless of some
> > nodes not being reachable, you have to create your table on whatever nodes
> > exist, and have some code which makes copies of tables when nodes come up.
> >
> > cheers
> > Chandru
> >
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>



More information about the erlang-questions mailing list