hi,<div><br></div><div>I'm coding a simple queue application on top of mnesia. I found one strange thing that the last inserted row would lost if not referenced after restart. Is this a feature, bug, or my mistake? It has been troubling me for two days. I'm running R12 B5 on an iMac. Any suggestion is appreciated.</div>
<div><br></div><div>=================================</div><div>My codes:</div><div>=================================</div><div><br></div><div><div>-module(taskq).</div><div>-export([start/0, db_put/1, db_get/0]).</div><div>
<br></div></div><div><div>-record(oid, {name, id}).</div><div>-record(task, {id, info}).</div><div><br></div><div>start()-></div><div> %% start db or create;</div><div> mnesia:start(),</div><div> try</div><div>
mnesia:table_info(task, type)</div><div> catch</div><div> exit: _ -></div><div> utils:log("No db exists, create one."),</div><div> mnesia:stop(),</div><div> mnesia:create_schema([node()]),</div>
<div> </div><div> mnesia:start(),</div><div> mnesia:create_table(oid, [{disc_copies, [node()]}, {type, set}, {attributes, record_info(fields, oid)}]),</div><div> mnesia:create_table(task, [{disc_copies, [node()]}, {type, ordered_set}, {attributes, record_info(fields, task)}]),</div>
<div> </div><div> mnesia:transaction(fun()-></div><div> mnesia:s_write(#oid{name = task, id = 0})</div><div> end),</div><div> </div><div> utils:log("Taskdb created.") </div>
<div> end.</div><div> </div><div>db_put(Info)-> </div><div> mnesia:transaction(fun()-></div><div> Id = mnesia:dirty_update_counter({oid, task}, 1),</div><div> mnesia:s_write(#task{id = Id, info = Info})</div>
<div> end).</div><div><br></div><div>db_get()-></div><div> {atomic, R} = mnesia:transaction(fun()-></div><div> Id = mnesia:first(task),</div><div> case Id of</div><div> '$end_of_table' -></div>
<div> none;</div><div> _ -></div><div> [Ret] = mnesia:wread({task, Id}),</div><div> mnesia:s_delete({task, Id}),</div><div> Ret#<a href="http://task.info">task.info</a></div>
<div> end</div><div> end),</div><div> R.</div><div><br></div><div>==================================</div><div>Execution session:</div><div>==================================</div><div><br></div><div><div>
Linan-iMac:~$ erl</div><div>Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0] [kernel-poll:false]</div><div><br></div><div>Eshell V5.6.5 (abort with ^G)</div><div>1> c(taskq).</div><div>{ok,taskq}</div><div>
2> c(utils).</div><div>{ok,utils}</div><div>3> taskq:start().</div><div>2008/11/22 0:23:17 No db exists, create one.</div><div><br></div><div>=INFO REPORT==== 22-Nov-2008::00:23:17 ===</div><div> application: mnesia</div>
<div> exited: stopped</div><div> type: temporary</div><div>2008/11/22 0:23:18 Taskdb created.</div><div>ok</div><div>4> taskq:put(abcde).</div><div>{atomic,ok}</div><div>5> </div><div>BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded</div>
<div> (v)ersion (k)ill (D)b-tables (d)istribution</div><div>q</div><div><br></div><div>Linan-iMac:~$ erl</div><div>Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0] [kernel-poll:false]</div><div><br></div>
<div>Eshell V5.6.5 (abort with ^G)</div><div>1> taskq:start().</div><div>ordered_set</div><div>2> taskq:get().</div><div>none</div><div>3> </div><div><br></div></div>Linan Wang<br>
</div>