New mnesia events

Hakan Mattsson <>
Fri Mar 9 12:02:25 CET 2001


On Fri, 9 Mar 2001, Chandrashekhar Mullaparthi wrote:

Chandrashekhar> I think it will be useful if mnesia could issue the following events.
Chandrashekhar>  
Chandrashekhar> {table_created, Table}
Chandrashekhar> {table_deleted, Table}

Don't you like mnesia:subscribe({table, schema})?

Chandrashekhar> {table_available, Table} - This would be like an asynchronous version of
Chandrashekhar> mnesia:wait_for_tables(Tables, Timeout). Right now, I have some very big
Chandrashekhar> tables and a process which uses them doesn't know when they will be
Chandrashekhar> available. But it can't wait forever in mnesia:wait_for_tables - the way to
Chandrashekhar> do it now would be to have a timer to periodically check if the required
Chandrashekhar> table is available. Would be easier if my process could just subscribe for
Chandrashekhar> an event.
Chandrashekhar>  
Chandrashekhar> The first two would be useful in a case where tables are created/deleted
Chandrashekhar> dynamically in an application. The way to do it now would be to use
Chandrashekhar> mnesia:report_event - but it would be nice to have a standard way of knowing
Chandrashekhar> when a table has been created/deleted.

You always have the option of spawning a separate process in order
to perform the monitoring of when tables gets loaded, but my original 
idea was to handle thos via the event mechanism.

Chandrashekhar> The table event {delete, {Tab, Key}, ActivityId} is not issued for each key
Chandrashekhar> when a table is deleted - which is sensible - but {table_deleted, Table}
Chandrashekhar> would nicely fill the gap.

As mentioned above, use the mnesia:subscribe/1 function.

/Håkan

---
Håkan Mattsson
Ericsson
Computer Science Laboratory
http://www.ericsson.se/cslab/~hakan


--- CUT --- CUT --- CUT --- CUT --- CUT --- CUT --- CUT --- CUT --
unix> erl
Erlang (BEAM) emulator version 5.0.2 [threads]

Eshell V5.0.2  (abort with ^G)
1> mnesia:start().
ok
2> mnesia:subscribe({table, schema}).
{}
3> mnesia:create_table(a_brand_new_table, []).
{atomic,ok}
4> flush().
Shell got {mnesia_table_event,{write,{schema,
                                         a_brand_new_table,
                                         [{name,a_brand_new_table},
                                          {type,set},
                                          {ram_copies,[]},
                                          {disc_copies,[]},
                                          {disc_only_copies,[]},
                                          {load_order,0},
                                          {access_mode,read_write},
                                          {index,[]},
                                          {snmp,[]},
                                          {local_content,false},
                                          {record_name,a_brand_new_table},
                                          {attributes,[key,val]},
                                          {user_properties,[]},
                                          {frag_properties,[]},
                                          {cookie,
                                              {{984,134919,30740},
                                               }},
                                          {version,{{2,0},[]}}]},
                                     {tid,3,<0.63.0>}}}
Shell got {mnesia_table_event,{write,{schema,
                                         a_brand_new_table,
                                         [{name,a_brand_new_table},
                                          {type,set},
                                          {ram_copies,[]},
                                          {disc_copies,[]},
                                          {disc_only_copies,[]},
                                          {load_order,0},
                                          {access_mode,read_write},
                                          {index,[]},
                                          {snmp,[]},
                                          {local_content,false},
                                          {record_name,a_brand_new_table},
                                          {attributes,[key,val]},
                                          {user_properties,[]},
                                          {frag_properties,[]},
                                          {cookie,
                                              {{984,134919,30740},
                                               }},
                                          {version,{{2,0},[]}}]},
                                     {tid,3,<0.63.0>}}}
5> mnesia:delete_table(a_brand_new_table).
{atomic,ok}
6> flush(). 
Shell got {mnesia_table_event,{delete,{schema,
                                          a_brand_new_table,
                                          [{name,a_brand_new_table},
                                           {type,set},
                                           {ram_copies,[]},
                                           {disc_copies,[]},
                                           {disc_only_copies,[]},
                                           {load_order,0},
                                           {access_mode,read_write},
                                           {index,[]},
                                           {snmp,[]},
                                           {local_content,false},
                                           {record_name,a_brand_new_table},
                                           {attributes,[key,val]},
                                           {user_properties,[]},
                                           {frag_properties,[]},
                                           {cookie,
                                               {{984,135646,22951},
                                                }},
                                           {version,{{2,0},[]}}]},
                                      {tid,4,<0.66.0>}}}
ok
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution7> 
unix>



More information about the erlang-questions mailing list