[erlang-questions] mnesia question

Michael McDaniel erlangy@REDACTED
Sat Nov 22 02:06:50 CET 2008


  try 
 
  5> mnesia:stop().
  6> q().
 
 
  instead of the CTRL-C,

  then restart and check - showed abcde for me.
 
 ~Michael
 P.S. of course, using db_put and db_get instead, and commenting out
      'utils' lines
 
 
 On Sat, Nov 22, 2008 at 12:28:03AM +0000, Linan Wang wrote:
 >    hi,
 > 
 >    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.
 > 
 >    =================================
 > 
 >    My codes:
 > 
 >    =================================
 > 
> >    -module(taskq).
> >    -export([start/0, db_put/1, db_get/0]).
> > 
> >    -record(oid, {name, id}).
> >    -record(task, {id, info}).
> >    start()->
> >        %% start db or create;
> >        mnesia:start(),
> >        try
> >            mnesia:table_info(task, type)
> >        catch
> >            exit: _ ->
> >                utils:log("No db exists, create one."),
> >                mnesia:stop(),
> >                mnesia:create_schema([node()]),
> > 
> >                mnesia:start(),
> >                mnesia:create_table(oid,  [{disc_copies, [node()]}, {type,
> >    set}, {attributes, record_info(fields, oid)}]),
> >                mnesia:create_table(task, [{disc_copies, [node()]}, {type,
> >    ordered_set}, {attributes, record_info(fields, task)}]),
> > 
> >                mnesia:transaction(fun()->
> >                        mnesia:s_write(#oid{name = task, id = 0})
> >                    end),
> > 
> >                utils:log("Taskdb created.")
> >        end.
> > 
> >    db_put(Info)->
> >        mnesia:transaction(fun()->
> >            Id = mnesia:dirty_update_counter({oid, task}, 1),
> >            mnesia:s_write(#task{id = Id, info =  Info})
> >            end).
> >    db_get()->
> >        {atomic, R} = mnesia:transaction(fun()->
> >            Id = mnesia:first(task),
> >            case Id of
> >                '$end_of_table' ->
> >                    none;
> >                _ ->
> >                    [Ret] = mnesia:wread({task, Id}),
> >                    mnesia:s_delete({task, Id}),
> >                    Ret#[1]task.info
> >            end
> >            end),
> >        R.
> >    ==================================
> >    Execution session:
> >    ==================================
> >    Linan-iMac:~$ erl
> >    Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0]
> >    [kernel-poll:false]
> >    Eshell V5.6.5  (abort with ^G)
> >    1> c(taskq).
> >    {ok,taskq}
> >    2> c(utils).
> >    {ok,utils}
> >    3> taskq:start().
> >    2008/11/22 0:23:17 No db exists, create one.
> >    =INFO REPORT==== 22-Nov-2008::00:23:17 ===
> >        application: mnesia
> >        exited: stopped
> >        type: temporary
> >    2008/11/22 0:23:18 Taskdb created.
> >    ok
> >    4> taskq:put(abcde).
> >    {atomic,ok}
> >    5>
> >    BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
> >           (v)ersion (k)ill (D)b-tables (d)istribution
> >    q
> >    Linan-iMac:~$ erl
> >    Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0]
> >    [kernel-poll:false]
> >    Eshell V5.6.5  (abort with ^G)
> >    1> taskq:start().
> >    ordered_set
> >    2> taskq:get().
> >    none
> >    3>
> >    Linan Wang
> > 
> > References
> > 
> >    1. http://task.info/
> 
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> -- 
> Michael McDaniel
> Portland, Oregon, USA
> http://autosys.us
> 




More information about the erlang-questions mailing list