thanks. it does the work. but what if the app crashes? will the last row lost?<br><br><div class="gmail_quote">On Sat, Nov 22, 2008 at 1:06 AM, Michael McDaniel <span dir="ltr"><<a href="mailto:erlangy@autosys.us">erlangy@autosys.us</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> try<br>
<br>
5> mnesia:stop().<br>
6> q().<br>
<br>
<br>
instead of the CTRL-C,<br>
<br>
then restart and check - showed abcde for me.<br>
<br>
~Michael<br>
P.S. of course, using db_put and db_get instead, and commenting out<br>
'utils' lines<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
On Sat, Nov 22, 2008 at 12:28:03AM +0000, Linan Wang wrote:<br>
> hi,<br>
><br>
> I'm coding a simple queue application on top of mnesia. I found one<br>
> strange thing that the last inserted row would lost if not referenced<br>
> after restart. Is this a feature, bug, or my mistake? It has been<br>
> troubling me for two days. I'm running R12 B5 on an iMac. Any<br>
> suggestion is appreciated.<br>
><br>
> =================================<br>
><br>
> My codes:<br>
><br>
> =================================<br>
><br>
> > -module(taskq).<br>
> > -export([start/0, db_put/1, db_get/0]).<br>
> ><br>
> > -record(oid, {name, id}).<br>
> > -record(task, {id, info}).<br>
> > start()-><br>
> > %% start db or create;<br>
> > mnesia:start(),<br>
> > try<br>
> > mnesia:table_info(task, type)<br>
> > catch<br>
> > exit: _ -><br>
> > utils:log("No db exists, create one."),<br>
> > mnesia:stop(),<br>
> > mnesia:create_schema([node()]),<br>
> ><br>
> > mnesia:start(),<br>
> > mnesia:create_table(oid, [{disc_copies, [node()]}, {type,<br>
> > set}, {attributes, record_info(fields, oid)}]),<br>
> > mnesia:create_table(task, [{disc_copies, [node()]}, {type,<br>
> > ordered_set}, {attributes, record_info(fields, task)}]),<br>
> ><br>
> > mnesia:transaction(fun()-><br>
> > mnesia:s_write(#oid{name = task, id = 0})<br>
> > end),<br>
> ><br>
> > utils:log("Taskdb created.")<br>
> > end.<br>
> ><br>
> > db_put(Info)-><br>
> > mnesia:transaction(fun()-><br>
> > Id = mnesia:dirty_update_counter({oid, task}, 1),<br>
> > mnesia:s_write(#task{id = Id, info = Info})<br>
> > end).<br>
> > db_get()-><br>
> > {atomic, R} = mnesia:transaction(fun()-><br>
> > Id = mnesia:first(task),<br>
> > case Id of<br>
> > '$end_of_table' -><br>
> > none;<br>
> > _ -><br>
> > [Ret] = mnesia:wread({task, Id}),<br>
> > mnesia:s_delete({task, Id}),<br>
</div></div>> > Ret#[1]<a href="http://task.info" target="_blank">task.info</a><br>
<div><div></div><div class="Wj3C7c">> > end<br>
> > end),<br>
> > R.<br>
> > ==================================<br>
> > Execution session:<br>
> > ==================================<br>
> > Linan-iMac:~$ erl<br>
> > Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0]<br>
> > [kernel-poll:false]<br>
> > Eshell V5.6.5 (abort with ^G)<br>
> > 1> c(taskq).<br>
> > {ok,taskq}<br>
> > 2> c(utils).<br>
> > {ok,utils}<br>
> > 3> taskq:start().<br>
> > 2008/11/22 0:23:17 No db exists, create one.<br>
> > =INFO REPORT==== 22-Nov-2008::00:23:17 ===<br>
> > application: mnesia<br>
> > exited: stopped<br>
> > type: temporary<br>
> > 2008/11/22 0:23:18 Taskdb created.<br>
> > ok<br>
> > 4> taskq:put(abcde).<br>
> > {atomic,ok}<br>
> > 5><br>
> > BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded<br>
> > (v)ersion (k)ill (D)b-tables (d)istribution<br>
> > q<br>
> > Linan-iMac:~$ erl<br>
> > Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0]<br>
> > [kernel-poll:false]<br>
> > Eshell V5.6.5 (abort with ^G)<br>
> > 1> taskq:start().<br>
> > ordered_set<br>
> > 2> taskq:get().<br>
> > none<br>
> > 3><br>
> > Linan Wang<br>
> ><br>
</div></div>> > References<br>
> ><br>
> > 1. <a href="http://task.info/" target="_blank">http://task.info/</a><br>
><br>
> > _______________________________________________<br>
> > erlang-questions mailing list<br>
> > <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> > <a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
> --<br>
> Michael McDaniel<br>
> Portland, Oregon, USA<br>
> <a href="http://autosys.us" target="_blank">http://autosys.us</a><br>
><br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Best regards<br><br>Linan Wang<br>