Create table in a transaction

Ulf Wiger <>
Fri Nov 3 11:44:53 CET 2000


On Fri, 3 Nov 2000, Chandrashekhar Mullaparthi wrote:


>I tried running normal table ops(mnesia:write/1) within the schema
>transaction. But the transaction aborts with {aborted, {no_exists,
>TableName}} - which I think is understandable. I haven't read thru the code
>- but I think schema changes are probably not committed until the schema
>transaction is completed - which is why mnesia:write complains that it cant
>find the table. Though I don't understand why schema transactions are
>different from normal transactions. 

Oh, you're trying to write to the very table that you're creating?

No, that won't work. As I understand it, table writes go into a
temporary ets store before prepare_commit, but create_table seems to
take effect in prepare_commit, and thus doesn't exist before that. To
handle that, mnesia_tm would have to peek at the requested ops and
figure out that the table you're writing to is about to be created. 

I think Dan is right, this is complicated.

Schema transactions are different from table transactions in a few
respects, but the main difference is that you have to be much more
careful when messing with the schema. This calls for a heavier
transaction protocol, the ability to follow through with the
transaction even if the requesting client dies, etc. Personally, I
don't think I quite fathom the complexity, so perhaps Dan, Håkan or
Klacke could give a better explanation.

>Maybe I'll go thru the code.....once I
>get ccviewer installed and running!
>
>Chandru

(:

/Uffe

>
>-----Original Message-----
>From: Ulf Wiger [mailto:]
>Sent: 3 November 2000 08:53
>To: Dan Gudmundsson
>Cc: Chandrashekhar Mullaparthi; 'Erlang mailing list'
>Subject: Re: Create table in a transaction
>
>
>On Thu, 2 Nov 2000, Dan Gudmundsson wrote:
>
>>
>>Sorry, but you can't do schema_transactions inside a normal transaction.
>>
>>schema_transaction's include 
>>create_table
>>move_table_copy
>>add_table_copy
>>change_table_copy
>>del_table
>>transform_table
>>..
>>
>>I got some requests on this but it is a lot of work do it rigth
>>with current implementation..
>>
>>/Dan
>
>But wouldn't it be possible to perform normal table updates from
>within a schema transaction?
>
>I haven't followed the complete thread, but it does seem as if
>schema_transaction calls mnesia:transaction/1, and that mnesia_tm.erl
>doesn't really care if schema transactions are combined with other
>operations.
>
>My mnesia_schema patch in the rdbms contrib exports
>mnesia_schema:schema_transaction/1, and has a few hacks to support
>multiple calls to write_table_property/2 within one schema
>transaction. You could try calling normal table ops within
>schema_transaction and see what happens.
>
>Note, though, that schema_transaction can't be called from within a
>transaction. If you want to try this, you'd also have to call
>create_table a bit differently. Here's an example from some code I've
>written:
>
>initialise_class(Class) ->
>    {Attrs, TableProps, UserProps} = Class:describe(),
>    F = fun() ->
>                create_table(
>                   Class, table_properties(Attrs, TableProps)),
>                rdbms:do_add_properties(UserProps, Class)
>        end,
>    mnesia_schema:schema_transaction(F).
>
>
>create_table(Name, Properties) ->
>    Cs = mnesia_schema:list2cs([{name, Name}|Properties]),
>    mnesia_schema:do_create_table(Cs).
>
>
>
>
>/Uffe
>
>
>>Chandrashekhar Mullaparthi writes:
>> > 
>> > I can't create a table within a transaction. Why is that?? A comment in
>> > mnesia_schema.erl says that a "very special transaction is used when we
>want
>> > to manipulate the schema". Basically what I want to do is:
>> > 
>> > * Do some checks
>> > * Update table_1
>> > * create table_2
>> > * Make entries in table_2
>> > 
>> > in one single transaction. I'm failing at step 3.
>> > 
>> > tia,
>> > Chandru
>> > 
>>
>
>

-- 
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




More information about the erlang-questions mailing list