[erlang-questions] Watching mnesia transactions

Bernard Duggan bernie@REDACTED
Wed Feb 10 04:59:49 CET 2010


Dan Gudmundsson wrote:
> There is no way to get that info today without patching mnesia,
> I think a variant of 'mnesia:subscribe' is the best solution.
>   
Thanks Dan, Ulf and Håkan for the answers (even if they weren't exactly
what I wanted to hear :)).

I've taken a look at the option of a patch to or variant of the
mnesia:subscribe system.  Basically I can think of two obvious choices:

* Add a new event category to subscribe(), in addition to 'system' and
{table, ..., ...} - call it 'activity'.  When a transaction has finished
committing, fire off a message like {activity_complete, ActivityID} to
all subscribers.

* Add a new event category to subscribe() called 'transaction' (or
something) which sends the full set of changes from a transaction, all
batched up in a single event, when the transaction finishes committing. 
That has the downside that in its simplest form you can't filter by
tables you're interested in and would probably end up being considerably
more complex to implement, so I'm inclined to go with the first option.

In both cases, the event would need to be sent at a point where the
transaction is still running and holding locks, but where all the
changes have been committed and we know the transaction isn't going to
restart.  It looks like the appropriate place to do that would be as the
final step of do_commit() (in mnesia_tm.erl) using an analogous method
to mnesia_subscr:report_table_event().

So my question to those learned in this area is: Does this sound like a
vaguely workable idea, or am I missing/misunderstanding something
fundamental?

Cheers,

Bernard


More information about the erlang-questions mailing list