[erlang-questions] About mnesia in multi-nodes

Håkan Mattsson <>
Thu Apr 1 02:58:17 CEST 2010

On Tue, Mar 30, 2010 at 5:12 PM, 钱晓明 <> wrote:
> Hi, I create mnesia schema in 2 nodes successfully, and create tables with
> disc_copies option. After writing one record into one table, I close all
> erlang nodes. Then I restart one node, call mnesia:start(), use tv:start()
> to view records in that table, but I see none. If I start 2 nodes, I can see
> records. Is there any way I can make sure records wrote all nodes, so I can
> start my system when only one node runing?

The records has safely been written to disk on both nodes. Even if it seems a
little bit confusing, Mnesia works as expected. The table load mechanism is
a part of the transaction recovery mechanism. When Mnesia on one node
looses contact with Mnesia on another node, this is noted in the transaction
log. At that time point Mnesia knows that the node that still is up and running
has a consistent replica of its tables. The replica on he node that was shutdown
first may be outdated since the other nodes may update their replicas
of  the table.

At startup Mnesia tries to connect with the other nodes and if that suceeds it
loads its tables from them. If the other nodes are down, it looks for
marks in its local transaction log in order to determine if it has a consistent
replica or not of its tables. The node that was shutdown last has mnesia_down's
from all the other nodes. This means that it safely can load its tables. If some
of the other nodes where started first (as in your case) Mnesia will
wait indefinitely
for another node to connect in order to load its tables

However, if the other node cannot be started for some reason, it is possible to
bypass the transaction recovery mechanism by explicitly calling
mnesia:force_load_table/1 to load the local replica of the table
(regardless of it
is up-to-date or not).  But as it can lead to database inconsistency it must be
used with care. The same goes for the configuration parameter
(see the reference manual) which also may cause Mnesia to bypass the transaction
recovery mechansism when some nodes refuses to start. You trade availability for

Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list