Mnesia bug?

Ulf Wiger ulf.wiger@REDACTED
Mon Feb 2 17:28:33 CET 2004



mnesia:erl:
----------
write_table_property(Tab, Prop) ->
     mnesia_schema:write_table_property(Tab, Prop).

mnesia_schema.erl:
-----------------
write_table_property(Tab, Prop) when tuple(Prop), size(Prop) >= 1 ->
     schema_transaction(fun() -> do_write_table_property(Tab, Prop) end);


You cannot start a schema transaction within a regular transaction.
You might want to try the following (again, from mnesia_schema.erl):

%% Needed outside to be able to use/set table_properties
%% from user (not supported)
-export([schema_transaction/1,
          insert_schema_ops/2,
          do_create_table/1,
          do_delete_table/1,
          do_delete_table_property/2,
          do_write_table_property/2]).

Note the "(not supported)" disclaimer. This is, however, your
only option if you want to perform complex actions on properties
with any form of transaction safety.

(The rdbms contrib uses this, BTW.)

/Uffe


On Mon, 2 Feb 2004 16:58:10 +0100, Rudolph van Graan 
<rvg@REDACTED> wrote:

> It seems as though mnesia (R9C) does not allow updates to user
> properties of a table during a transaction... Any ideas?
>
> -module(mnesia_bug).
> -export([run/0]).
>
> run() ->
>   mnesia:delete_table(abc),
> %Drop Table
>   {atomic,ok} = mnesia:create_table(abc,[{attributes,[a,b,c]}]),
> %Create a simple table
>   mnesia:write_table_property(abc,{some_value,1}),
> %Write a value to the table properties
>   {some_value,1} = mnesia:read_table_property(abc,some_value),
> %Check that it is correct
>   io:format("Value of 1written and verified\n",[]),
>   F = fun() ->
> %Now modify the value in the fun
> 	  io:format("Changing value to 2\n",[]),
> 	  mnesia:write_table_property(abc,{some_value,2}),
> 	  {some_value,New_value_1} =
> mnesia:read_table_property(abc,some_value),%Verify it is ok
> 	  case New_value_1 of
> 	    2 ->
> 	      io:format("Value has changed to 2 - this is ok\n",[]);
> 	    Other ->
> 	      io:format("Value is ~p - this is NOT ok\n",[Other])
> 	  end
>       end,
>   {atomic,ok} = mnesia:transaction(F),
> %Run the fun
>   io:format("Now read it back again...\n",[]),
>   {some_value,Last_Value} = mnesia:read_table_property(abc,some_value),
> %And read it back again
>   io:format("Value is ~p\n",[Last_Value])  .
>
>
> Rudolph van Graan



-- 
Ulf Wiger, Senior System Architect
EAB/UPD/S

This communication is confidential and intended solely for the addressee(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you believe this message has been sent to you in error, please notify the sender by replying to this transmission and delete the message without disclosing it. Thank you.

E-mail including attachments is susceptible to data corruption, interruption, unauthorized amendment, tampering and viruses, and we only send and receive e-mails on the basis that we are not liable for any such corruption, interception, amendment, tampering or viruses or any consequences thereof.




More information about the erlang-questions mailing list