Mnesia table events

Dan Gudmundsson <>
Fri Aug 16 10:14:01 CEST 2002


Sivakumar Krishnasamy writes:
 > Hi Dan Gudmundsson,
 >    Thanks for your reply.
 >    What will happen if I subscribe for table events on both the nodes (, ), but perform replicated table operations in  ?.
 >    Will the events be distributed to both subscribed processes in  and  ??.

Yes 

 > 
 >      Node A                                                 Node B (A1) 
 >      ()1> mnesia:start().                               ()1>  mnesia:start().
 >       ok                                                            ok
 > 
 >      ()2> mnesia:change_config(extra_db_nodes, []).    
 >      {ok,[]}                                               
 > 
 >      ()3> mnesia:create_table(a,[{ram_copies,[]}]).
 >      {atomic,ok}                                                  
 > 
 >      ()4> mnesia:subscribe({table, a}).            ()3>  mnesia:subscribe({table, a}).
 >      {}                                                          {}     
 > 
 >      ()4> mnesia:dirty_write({a,1,1}).                      
 >          ok 
 >   
 >      Note: So performing table operation in  creates an event and it is captured by the subscribed process in  Am I right ?? 

Well, the event(s) are created locally on the node(s) when data is
written (or deleted), conceptually that the same thing.

 > 
 >      ()5>                                                   ()4> flush().
 >      Will I get event here too??                         Shell got {mnesia_table_event,
 >                                                                         {write,{a,1,1},{dirty,<127.32.0>}}}

Yes, if you had subscribed to events on 

If you connect a third node (a2), but don't create a replica of
table a on a2, then you can't subscribe to the events of table a.
You can still read and write data from that node (a2). Events
will be generated on the nodes with an replica.

/Dan

 > 
 > Regards,
 > Sivakumar Krishnasamy.
 >     
 > 
 > 
 > ----- Original Message ----- 
 > From: "Dan Gudmundsson" <>
 > To: "Sivakumar Krishnasamy" <>
 > Cc: <>
 > Sent: Friday, August 16, 2002 11:34 AM
 > Subject: Mnesia table events
 > 
 > 
 > > 
 > > You only get events on the node where you called the subscribe command:
 > > 
 > > Node A                                                 Node B (A1)
 > > 
 > > ()1> mnesia:start().                               ()1>  mnesia:start().
 > > ok                                                    ok
 > > ()2> mnesia:change_config(extra_db_nodes, []).    
 > > {ok,[]}                                               
 > > ()3> mnesia:create_table(a,[{ram_copies,[]}]).
 > > {atomic,ok}                                                  
 > > ()4>                                               ()3>  mnesia:subscribe({table, a}).
 > > ()4>                                               {}
 > > ()4> mnesia:dirty_write({a,1,1}).                      
 > > ok 
 > > ()5>       ()4> flush().
 > >       Shell got {mnesia_table_event,
 > >                                                        {write,{a,1,1},{dirty,<127.32.0>}}}
 > > 
 > > /Dan
 > > 
 > > 
 > > 
 > > 
 > > Sivakumar Krishnasamy writes:
 > >  > Hi all,
 > >  >     I have created a table, which is replicated in 2 nodes ..say Node A and Node B. If I insert a value in Node A, then it's is replicated in Node B.
 > >  >     Is it possible to subscribe for capturing table events in Node B, to capture table events When I perform table operations like write/delete in Node A for the replicated table. 
 > >  >     When I tried the above scenario, I am getting events only in Node A, and node B doesn't seems to generate any table events, when its replicated table is accessed in Node A.
 > >  >  
 > >  > Regards,
 > >  > Sivakumar Krishnasamy.
 > >  >    
 > >  >     



More information about the erlang-questions mailing list