RFC: mnesia majority checking

Ulf Wiger ulf.wiger@REDACTED
Thu Dec 9 15:26:10 CET 2010

git fetch git://github.com/uwiger/otp mnesia-majority


This is a first stab at a function that I believe could be useful in 
high-availability applications using mnesia.

At this stage, I'd love to have some comments, and suggestions,
if someone thinks of a better way to do it.

From the commit message:

"Add {majority, boolean()} per-table option.

With {majority, true} set for a table, write transactions will
abort if they cannot commit to a majority of the nodes that
have a copy of the table. Currently, the implementation hooks
into the prepare_commit, and forces an asymmetric transaction
if the commit set affects any table with the majority flag set.
In the commit itself, the transaction will abort if it cannot
satisfy the majority requirement for all tables involved in the

A future optimization might be to abort already when a write
lock is attempted on such a table (/-object) and the lock cannot
be set on enough nodes.

This functionality introduces the possibility to automatically
"fence off" a table in the presence of failures.

This is a first implementation. Only basic tests have been

One particular use of this functionality would be to have  a "global 
resource pool" in one table with {majority, true}, and periodically 
check out resources into a local buffer. If there is a failure condition,
you can use the local buffer, but not check out more resources, unless
you happen to still be in contact with more than half of the replicas.

This should allow for a well-defined merge after a network split.

Ulf W

Ulf Wiger, CTO, Erlang Solutions, Ltd.

More information about the erlang-questions mailing list