[erlang-questions] Detecting 'inconsistent_database' and other Mnesia events

Scott Lystig Fritchie fritchie@REDACTED
Thu Jan 11 07:36:30 CET 2007


Good evening.  As I've been refactoring a Mnesia-based application, it
struck me that mnesia:subscribe/1 cannot be called until Mnesia has
been started.

As a Mnesia event subscriber, if I want extremely *prompt* and
*reliable* notification of important events such as the
'inconsistent_database' warning ... hm, it seems I'm stuck with a race
condition, possibly missing the event between starting Mnesia and
becoming an event subscriber.

My solution, before refactoring, was to have my custom error_logger
report handler check for "inconsistent_database" in any string that it
was about to write to disk.  Not very elegant, but effective.

After refactoring, my report handler is now in a hunk of code that
can/will be shared by many applications, and the code that reacts to
the Mnesia error will differ from app to app.

So ... are there any easy ways around this problem, something I've
missed?

-Scott

P.S. Hm.  Here's the only thing that I can come up with, hitting my
brain about 5 seconds before pressing "Send".

1. Add yet another custom report handler, foo, callback for
error_logger.

2. In foo.erl, have a callback func that looks something like:

    handle_event({_T, _GL, SomeWackyTermThing}, State) ->
        scream_murder_then_halt_abruptly(),
        {ok, State};
    handle_event(_Event, State) ->
        {ok, State}.

... where SomeWackyTermThing is really whatever report/format/whatever
that Mnesia logs when 'inconsistent_database' is detected.

3. Fiddle a lot with creating Mnesia inconsistencies to try to figure
out *exactly* what that !@#$! error logger event looks like.



More information about the erlang-questions mailing list