
Mnesia is a
distributed,
soft real-time
Real-time computing (RTC) is the computer science term for hardware and software systems subject to a "real-time constraint", for example from event to system response. Real-time programs must guarantee response within specified time constrai ...
database management system
In computing, a database is an organized collection of data stored and accessed electronically. Small databases can be stored on a file system, while large databases are hosted on computer clusters or cloud storage. The design of databases span ...
written in the
Erlang programming language.
It is distributed as part of the
Open Telecom Platform
OTP is a collection of useful middleware, libraries, and tools written in the Erlang programming language. It is an integral part of the open-source distribution of Erlang. The name OTP was originally an acronym for Open Telecom Platform, which w ...
.
Description
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
Data processing is the collection and manipulation of digital data to produce meaningful information.
Data processing is a form of ''information processing'', which is the modification (processing) of information in any manner detectable by an ...
database management system
In computing, a database is an organized collection of data stored and accessed electronically. Small databases can be stored on a file system, while large databases are hosted on computer clusters or cloud storage. The design of databases span ...
, 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 any SQL database server.
Database model
"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.
Backend types
Mnesia has three inbuilt table types: ram_copies, disc_copies and disc_only_copies.
Ram_copies
Data resides in memory and table size is limited by available memory and are backed b
ETS(erlang term storage) table.
Disc_copies
Data resides in memory but is also persisted on disk backed by disk_log. Disc_copies were backed b
tables until 30th September 2001 with the release of Erlang R7B-4.
Disc_only_copies
Data resides only on disc and are backed b
(disk version of ETS)
file format uses signed 32-bit integers for file offsets and has a limit of 2GB so do disc_only_copies.
Backend plugins
Due to limits imposed b
support for other backend plugins was suggested b
Ulf Wigerand these were added to Mnesia.
Klarna added the
LevelDB backend plugin whil
Aeternityadded the
RocksDB backend plugin.
Relational features
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
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.
Transactions
Erlang is a
functional language. Mnesia builds on this to obtain
ACID
In computer science, ACID ( atomicity, consistency, isolation, durability) is a set of properties of database transactions intended to guarantee data validity despite errors, power failures, and other mishaps. In the context of databases, a sequ ...
transaction
Transaction or transactional may refer to:
Commerce
* Financial transaction, an agreement, communication, or movement carried out between a buyer and a seller to exchange an asset for payment
*Debits and credits in a Double-entry bookkeeping sys ...
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
BEGIN
/
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
In computer science, ACID ( atomicity, consistency, isolation, durability) is a set of properties of database transactions intended to guarantee data validity despite errors, power failures, and other mishaps. In the context of databases, a sequ ...
, but offer around 10× more throughput.
In addition there are also in-memory alternatives, although these lose the ''durability'' property of
ACID
In computer science, ACID ( atomicity, consistency, isolation, durability) is a set of properties of database transactions intended to guarantee data validity despite errors, power failures, and other mishaps. In the context of databases, a sequ ...
.
Efficient execution
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
virtual machine throughout an application. LYME makes use of this, since the
Yaws web server is also implemented in Erlang.
Address space
In computing, an address space defines a range of discrete addresses, each of which may correspond to a network host, peripheral device, disk sector, a memory cell or other logical or physical entity.
For software programs to save and retrieve st ...
is shared (although safely so, under Erlang) between code and data, including Mnesia's table data.
Origins and licensing
Mnesia and Erlang were developed by the Ericsson Computer Science Laboratory. They have been released as
open source software. Mnesia is released under a derivative of the
Mozilla Public License.
Since OTP 18.0 they are published according to the open source
Apache License 2.0. Versions before OTP 18.0 were published under the open source ''Erlang Public License''.
ejabberd
Mnesia is also an option embedded within the Erlang-based
Jabber daemon,
ejabberd.
See also
*
Riak
*
Apache Cassandra
*
Couchbase
*
CouchDB
*
LYME (software bundle)
References
{{reflist, 30em
Erlang (programming language)
Free database management systems
Structured storage