[erlang-questions] Illusive mnesia bug

lloyd@REDACTED lloyd@REDACTED
Tue Nov 10 19:24:43 CET 2015


Hello,

I've been building a simple mnesia-based app--- basically a prototype to gain experience with mnesia. See nim_links1.erl, attached. 

Had it working, but following a few simple but undocumented/unremembered changes, it no longer works.  So far I've spent a day trying to understand how I managed to break it.

Here's what I know:

1. nim_links1.erl compiles

2. mnesia is running and links table is installed:

40> mnesia:info().

   ---> Processes holding locks <--- 
   ---> Processes waiting for locks <--- 
   ---> Participant transactions <--- 
   ---> Coordinator transactions <---
   ---> Uncertain transactions <--- 
   ---> Active tables <--- 
   schema         : with 2        records occupying 533      words of mem
   links          : with 0        records occupying 299      words of mem
   ===> System info in version "4.13.1", debug level = none <===
   opt_disc. Directory "/home/lloyd/nindex/Mnesia.nindex@REDACTED" is used.
   use fallback at restart = false
   running db nodes   = ['nindex@REDACTED']
   stopped db nodes   = [] 
   master node tables = []
   remote             = []
   ram_copies         = []
   disc_copies        = [links,schema]
   disc_only_copies   = []
   [{'nindex@REDACTED',disc_copies}] = [links,schema]
   4 transactions committed, 6 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

3. record_info/2 works:

   41> record_info(fields, weblink).

   [id,topic,tags,descriptor,url]

4. As do nim_links1:create_link_record/4 and nim_links1:get_all/0:

   42> Topic = "Erlang".     
   "Erlang"

   43> Tags = [].
   []

   44> Descriptor = "Nerves Project (embedded Erlang)".
   "Nerves Project (embedded Erlang)"

   45> Url = "http://nerves-project.org/".
   "http://nerves-project.org/"
 
   46> Record = nim_links1:create_link_record(Topic, Tags, Descriptor, Url).

   #weblink{id = "ECFB6AB4443",topic = "Erlang",tags = [],
            descriptor = "Nerves Project (embedded Erlang)",
            url = "http://nerves-project.org/"}

   48> nim_links1:get_all().

   []

5. BUT, nim_links1/1 fails:

50> nim_links1:put_record(Record).

   ** exception error: no match of right hand side value {aborted,{no_exists,weblink}}
      in function  nim_links1:put_record/1 (/home/lloyd/nindex/site/src 
     /nim_links1.erl, line 50)

6. As does mnesia:dirty_write/1:

   51> mnesia:dirty_write(Record).
   ** exception exit: {aborted,{no_exists,weblink}}
        in function  mnesia:abort/1 (mnesia.erl, line 313)

And now I've run out of ideas of how to proceed.

If I'm reading the error messages correctly, the mnesia write functions are not recognizing the defined weblink record. I've attached ni_mnesia.erl to show how I initialized mnesia.

I'd much appreciate any insights into 

- where I'm going wrong and how to fix it
- debugging strategies in cases like this
- how I can improve the code

Many thanks,

LRP 







-------------- next part --------------
A non-text attachment was scrubbed...
Name: nim_links1.erl
Type: text/x-erlang
Size: 1445 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151110/90994beb/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ni_mnesia.erl
Type: text/x-erlang
Size: 1108 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151110/90994beb/attachment-0001.bin>


More information about the erlang-questions mailing list