Delete/Create in the same transaction

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Delete/Create in the same transaction

chandru
6> mnesia:create_table(bag, [{attributes, [a,b]}, {type, bag}, {disc_copies,
[node()]}]).
{atomic,ok}
.
.        
18> mnesia:transaction(fun() -> mnesia:write({bag, 1, 2}) end).
{atomic,ok}
19>
19>
19> mnesia:transaction(fun() -> mnesia:write({bag, 1, 3}) end).
{atomic,ok}
20>
20> [mnesia:dirty_read({bag, X}) || X <- mnesia:dirty_all_keys(bag)].
[[{bag,1,2},{bag,1,3}]]
21>
21> mnesia:transaction(fun() -> mnesia:delete_object({bag, 1, 2}),
mnesia:write({bag, 1, 2}) end).
{atomic,ok}
22>
22> [mnesia:dirty_read({bag, X}) || X <- mnesia:dirty_all_keys(bag)].
[[{bag,1,3}]]

In step 21, Why is it that if I delete an object in a transaction and write
it back again in the same, the object doesn't exist in the database??
Intuitively it seems to be a bug....

cheers,
Chandru



NOTICE AND DISCLAIMER:
This email (including attachments) is confidential.  If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents.  We cannot accept liability for any breaches of
confidence arising through use of email.  Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions.  We will not accept responsibility for any commitments
made by our employees outside the scope of our business.  We do not warrant
the accuracy or completeness of such information.



Reply | Threaded
Open this post in threaded view
|

Delete/Create in the same transaction

Ulf Wiger-4



On Mon, 16 Apr 2001, Chandrashekhar Mullaparthi wrote:

[snip]

>21> mnesia:transaction(fun() -> mnesia:delete_object({bag, 1, 2}),
>mnesia:write({bag, 1, 2}) end).
>{atomic,ok}
>22>
>22> [mnesia:dirty_read({bag, X}) || X <- mnesia:dirty_all_keys(bag)].
>[[{bag,1,3}]]
>
>In step 21, Why is it that if I delete an object in a transaction
>and write it back again in the same, the object doesn't exist in the
>database?? Intuitively it seems to be a bug....

I don't know if this is your problem, but if you want to verify that
the object actually gets written, you may want to do so with another
transaction. The above test suffers from a race condition in that
dirty operations never wait for a transaction to finish.

The transaction returns when it is committed, but before all the work
is done to make the data visible. Transactions are guaranteed to see
the complete results of earlier transactions but dirty operations are
not.

/Uffe
--
Ulf Wiger                                    tfn: +46  8 719 81 95
Senior System Architect                      mob: +46 70 519 81 95
Strategic Product & System Management    ATM Multiservice Networks
Data Backbone & Optical Services Division      Ericsson Telecom AB