Friday, 17 July 2009

Playing with mnesia

Well just got the new erlang book by Cesarini and Thompson so thought I'd start playing with Mnesia the Erlang database.
First thing is to create a schema for our database using
mnesia:create_schema()

So starting the shell

C:\work\erlang\mnesia1>erl
consulting .erlang in "C:/work/erlang/mnesia1"
c:/work/erlang
Now in "c:/work/erlang"
Eshell V5.7.2 (abort with ^G)
1> cd(mnesia1).
c:/work/erlang/mnesia1
ok

If we see what is happening before we do anything:

2> mnesia:info().
===> System info in version {mnesia_not_loaded,nonode@nohost,
{1247,823453,76000}}, debug level = none <=== opt_disc. Directory "c:/work/erlang/mnesia1/Mnesia.nonode@nohost" is NOT used. use fallback at restart = false running db nodes = [] stopped db nodes = [nonode@nohost] ok 3>
At this point our working directory is still empty but after running

4> mnesia:create_schema([node()]).
ok

We get

C:\work\erlang\mnesia1>dir

17/07/2009 10:39 Mnesia.nonode@nohost

The directory contails a file called FULLBACK.BUP which is 503 bytes in size.

Looking at the info now we get

5> mnesia:info().
===> System info in version "4.4.10", debug level = none <===
opt_disc. Directory "c:/work/erlang/mnesia1/Mnesia.nonode@nohost" is used.
use fallback at restart = true
running db nodes = []
stopped db nodes = [nonode@nohost]
ok
6>

Note the message saying opt_disc is now used, however nothing is actually running.
So starting up mnesia

6> mnesia:start().
ok
7> mnesia:info().
---> Processes holding locks <---
---> Processes waiting for locks <---
---> Participant transactions <---
---> Coordinator transactions <---
---> Uncertain transactions <---
---> Active tables <---
schema : with 1 records occupying 432 words of mem
===> System info in version "4.4.10", debug level = none <===
opt_disc. Directory "c:/work/erlang/mnesia1/Mnesia.nonode@nohost" is used.
use fallback at restart = false
running db nodes = [nonode@nohost]
stopped db nodes = []
master node tables = []
remote = []
ram_copies = []
disc_copies = [schema]
disc_only_copies = []
[{nonode@nohost,disc_copies}] = [schema]
2 transactions committed, 0 aborted, 0 restarted, 0 logged to disc
0 held locks, 0 in queue; 0 local transactions, 0 remote
0 transactions waits for other nodes: []
ok
8>

After starting mnesia we can see we have a running db node at nonode@nohost and a disc copy of the schema to make it persist.

In the directory we now have two files,
LATEST.LOG and
schema.DAT

No tables as yet but that comes next.
Still more options for the schema creation to come.




Tuesday, 14 July 2009

Getting Worried About OpenSolaris

Ever since it looked like Oracle were buying Sun Microsystems there were concerns about where OpenSolaris was heading.
Latest is at http://blogs.computerworld.com/is_oracle_getting_ready_to_kill_opensolaris
Still we have got 118 to play with today.
I cannot believe things like DTrace and ZFS would have got the airing they have without OpenSolaris, still he who pays the piper calls the tune.
Still nothing is for certain, might as well enjoy it while you can :-)