Erlang/OTP Forums

Author Message

<  Open Telecom Platform (OTP)  ~  Mnesia:write/3 failure

flodis
Posted: Tue Jun 16, 2009 7:14 pm Reply with quote
User Joined: 09 Jul 2008 Posts: 27
I wrote a piece of code that should store a record containg node and its load in a mnesia db.
If the transaction fails its probably because the table does not exists so the table is created and then the transaction is run again.
However the mnesia:write/3 operation always fail with the error:
Code:
{aborted,{bad_type,{areasrv_load,'monsrv1@flodis-desktop',1}}}


The table is sucessfully created after the first transaction failure, but write/3 still fails.

Code:
register_areasrv_load(AreaSrv, Node, Load) ->
    F = fun() ->
            mnesia:write(AreaSrv,
                #areasrv_load{node=Node, load=Load}, write)
    end,
    case mnesia:transaction(F) of
        {atomic, Result} ->
            Result;
        %{aborted, {bad_type, _Record}} ->
        Failure ->
            error_logger:info_report([{failure, Failure}]),
            create_table(AreaSrv),
            mnesia:transaction(F)
    end.

create_table(AreaSrv) ->
    mnesia:create_table(AreaSrv, [{ram_copies, [node()]},
        {attributes, record_info(fields, areasrv_load)},
        {type, ordered_set}]),
    error_logger:info_report([{created_load_table, AreaSrv}]).
View user's profile Send private message
flodis
Posted: Tue Jun 16, 2009 7:24 pm Reply with quote
User Joined: 09 Jul 2008 Posts: 27
I found out myself after some "Googling". If the name of the table differs from the record name, you have to provide the option {record_name, areasrv_load} to the options when the table is created.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum