mnesia no disk write after restart

Michael McDaniel erlang@REDACTED
Mon Apr 17 10:42:51 CEST 2006


BRIEF: module using mnesia works fine the first time I start it
       (when the schema and table get created), and the db is
       persistent for the next restart.  Henceforth, no records
       write to disk, they only exist in memory, and further
       restarts lose all but the records written on the initial
       start (when the table was created).


LONG:

My goal is a *persistent* database when restarting my module.

I am running R10B-10 on Linux.

I have abbreviated the following code.  I think all the pertinent
bits are there.

I start my module with the following fun:


start() -> 

 erlang:set_cookie( node(), some_cookie )

 mnesia:create_schema([node()]) ,
 mnesia:start() ,


 case catch mnesia:table_info(?DB, attributes) of

    L when is_list(L) -> 
                        ok ;

    _                 ->
       mnesia:create_table(?DB ,
          [ {disc_copies, [node()]} ,
            {attributes, record_info(fields, ?DB)} ,
            {type, set}
          ])

 end,
    
 mnesia:wait_for_tables([?DB,schema], 21000)
.


the write function is:

write(Rec) ->
    Trans = fun() -> mnesia:write(Rec) end ,
    mnesia:transaction(Trans) ,
    os:cmd("/bin/sync")
.


I run a loop that waits for messages of records to write.

I start the module from a script containing:


#!/bin/sh

HOST=`/bin/hostname`

/bin/su mmcdanie -c "cd /home/erl ; /usr/local/bin/erl              \
                 -sname  ${HOST}_block -config /home/erl/sys.config \
                 -setcookie xus -env TERM linux -env HOME /home/erl \
                 -home /home/erl -heart -detached                   \
                 -s block start /var/log/auth"
#% end


and the contents of sys.config:

[{mnesia, [{dir, "/home/erl/Mnesia.block"}  ,
%%           {debug, trace}                 ,
           {schema_location, disc}]}].


I start the application the first time with no Mnesia.block
directory created.  Module starts fine, directory and db files
are created, and I can send messages which get written to
the database.  I see the .LOG file change and the record.DCL
file get created.

I stop the module and restart it and I can see the records
in the database.

I send more messages and the records get written though only
to memory.  A new record.DCL file never gets created.  The
.LOG file(s) never change.  'Never' is waiting for over 10
minutes (and {dump_log_time_threshold,180000}).

I run mnesia:system_info from another node:

(fu@REDACTED)2> mnesia:system_info().
===> System info in version "4.2.5", debug level = none <===
disc. Directory "/home/erl/Mnesia.block" is used.
use fallback at restart = false
running db nodes   = [www_block@REDACTED,fu@REDACTED]
stopped db nodes   = []
master node tables = []
remote             = [ip]
ram_copies         = [schema]
disc_copies        = []
disc_only_copies   = []
[{fu@REDACTED,ram_copies},{www_block@REDACTED,disc_copies}] = [schema]
[{www_block@REDACTED,disc_copies}] = [ip]
3 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: []
yes


The '0 logged to disc' is after having written a new record that
does show in the database.


QUESTIONS:

1) Does anyone see something obvious I am overlooking here?

2) Any suggestions on what to do differently?

3) What is the next bit of information anyone needs to help?


thanks,

~Michael
P.S. I am doing essentially the same thing in another module
that I start from yaws and it works fine (i.e. persistent db
between restarts).  I have not sleuthed out the cause of the
different behaviours!  In the other module (that works) I do
not even have the case statement protecting the create_table/2
fun.



More information about the erlang-questions mailing list