[erlang-questions] Four ways to start mnesia in OTP environment. Which one should one use?

Ulf Wiger ulf.wiger@REDACTED
Sun Jul 5 10:15:53 CEST 2009


Sergey Samokhin wrote:
> Hello.
> 
> I've found four ways to start mnesia in OTP environment. Which one
> should I use? I was a bit puzzled to decide which of them is better.
> 
> 1) Boot scripts
> [...]
> 
> [-] Runtime doesn't give you a standard way to prepare the system
> before a dependency has been started. E.g. it isn't possible for me to
> ensure that a directory pointed by "-mnesia dir" is really exist
> before mnesia has been started.

The conventional way to deal with this is to require
an explicit install phase.

One way to accomplish this is to create an application
that starts before mnesia. The way to ensure that it runs
before mnesia when using a boot script is to list the
application before mnesia in the .rel file. The script
builder may adjust the order of applications based on
dependencies, but it will not reorder applications un-
necessarily. Thus, if you put an application before mnesia,
and it doesn't depend on mnesia, it will start before it.

This app can check whether the system has been installed,
or bootstrap the installation otherwise. It could also
check e.g. whether the node has restarted due to partitioned
network, and try to figure out whether to set master nodes
in mnesia, or perhaps whether it should simply wait for
some condition to be fulfilled before letting mnesia synch
with the others.


> [-] If you use a boot script you have to generate a new one for every
> OTP release your application is supposed to work with.

Well, yes, but erlc will do that for you. The pain is that
you have to generate a new .erl file, as the application
versions are listed in it. The 'builder' contrib that I
wrote years ago addressed that, and I believe that Sinan/Faxien
does that too. http://www.erlware.org

> [-] Mnesia isn't automatically stopped after you application has been
> terminated. I'm not sure if it's a problem, but if one is going to
> start another application which is supposed to use mnesia in the same
> VM, it's a good idea to restart mnesia with a fresh schema generated.

This sounds like you really have two independent applications
that do /not/ need to run in the same VM.

Why do you want to reuse the VM instance?
I'd shut down the erlang node in an orderly fashion, and
start a new one, using a different boot script and
a different mnesia dir.

BR,
Ulf W
-- 
Ulf Wiger
CTO, Erlang Training & Consulting Ltd
http://www.erlang-consulting.com


More information about the erlang-questions mailing list