Sunday, November 27, 2005

Dynamically adding nodes to mnesia

Mnesia is very flexible in the different ways it allows you to distribute the database. For my purposes I'm keeping it simple and want a master database and allow other mnesia nodes to dynamically start up and access or get copies of the master database tables. This turns out to be easy.

The first step is to have the database working as I outlined in my previous post on mnesia. This runs on my main server. To bring up another node on a different machine I start that node using an additional command line option:
erl -name newnode -mnesia extra_db_nodes "[mainserver@servername]"

The parameter passed to 'extra_db_nodes' is a list of the nodes running the master mnesia database schema. In this case there's only one.

From the 'newnode', start mnesia using 'mnesia:start()' as normal. This will start mnesia and connect to the 'mainserver'. You can now run queries and transactions on the remote database tables. It's also possible to set up the tables to 'replicate' to the 'newnode' so that queries are run against the data locally.

Categories:

0 Comments:

Post a Comment

<< Home