|Stable release||4.11 / January 23, 2014|
|Type||Relational Database Management System|
|License||Open Source Erlang Licence|
Purpose of Mnesia
As with Erlang, Mnesia was developed by Ericsson for soft real-time distributed and high-availability computing work related to telecoms. It was not intended as a general office-based data processing DBMS, nor to replace SQL-based systems. Instead Mnesia exists to support Erlang, where DBMS-like persistence is required. It has more in common with embeddable DBMS such as Berkeley DB than with a SQL database server.
Working with Mnesia
"Rows" in tables are represented as records that contain a key value and a data field. This data field may in turn be a tuple containing an Erlang data structure of any complexity.
The database model is relational, but isn't what someone familiar with SQL might expect. A database contains tables. Relationships between them are modelled as other tables.
A key feature of Mnesia's high-availability approach is that tables can be reconfigured within a schema and relocated between nodes, not only while the database is still running, but even while write operations are still going on.
Coding for Mnesia
The query language of Mnesia is Erlang itself, rather than SQL. It permits easy representation of transactions as a natural feature of Erlang by allowing developers to utilize a single language throughout an application.
Erlang is a functional language. Mnesia builds on this to obtain ACID transaction support. The functional block which is run as a transaction is a commonplace Erlang construct called a Functional Object (or Fun) and is called by the single Mnesia statement
mnesia:transaction(F). This can lead to clearer source code than the paired
COMMIT syntax of SQL, and so avoids its problem of unclosed transactions within a procedure.
Again as a result of the functional nature of Erlang, nesting transactions is simple. It's also possible to distribute transactions across multiple nodes (i.e. separate servers). The semantics of using transactions in this way remains consistent, making it easy to write library code that works equally in either context.
General coding style for Mnesia will always use transactions. For performance reasons, it also supports deliberate "dirty operations" which avoid transactions. These compromise the atomicity and the isolation properties of ACID, but offer around 10× more throughput. In addition there are also in-memory alternatives, although these lose the durability property of ACID.
Mnesia forms part of the LYME web application stack. This is akin to LAMP, but based on Erlang. Implementation in Erlang confers an efficiency benefit because of the use of a single VM throughout an application. LYME makes use of this, since the Yaws web server is also implemented in Erlang.
Origins and licensing
Mnesia (and Erlang) were developed by the Ericsson Computer Science Laboratory. They have been open-sourced "to help encourage the spread of Erlang outside Ericsson." It is released under a derivative of the Mozilla Public License. They are published according to the open source Erlang Public License.
Contemporary interest in Mnesia
- Håkan Mattsson, Hans Nilsson, Claes Wikstrom (1999). "Mnesia - A Distributed Robust DBMS for Telecommunications Applications" (PDF).
- "Purpose of Mnesia". Open-source Erlang project.
- "Mnesia Getting Started guide". Open-source Erlang project.
- "Mnesia Reference Manual (v 4.4.5)". Open-source Erlang project.
- "6.17 Fun Expressions". Open-source Erlang project.
- Gavin Terrill (20 August 2007). "Erlang's Mnesia - a distributed DBMS for highly scalable apps". InfoQ.
- "Mnesia performance basics".
- "About Erlang". Open-source Erlang project.
- "Erlang Public License, V 1.1". Open-source Erlang project.
- "ejabberd project homepage".