← Back to team overview

drizzle-discuss team mailing list archive

Re: New low level events plugin API

 

Hi,

I have pushed up my branch now. You can find it at:
lp:~barry-leslie/drizzle/drizzle_events

There is now a single event observer method called for all events. This
method is passed an event data object containing all the data for the event.
This makes it easy to add new events, passing what ever data is relevant to
the event. The event.h file contains a set of instructions on how to add new
events.


If you want to see it in action building it with the config option
--with-hello-events-plugin

Then after connecting to the server execute the following:
set global hello_events_enable = ON;
set global hello_events_watch_databases = "x";
set global hello_events_watch_tables = "x,y";

This will enable tracing for all session events and schema events on
database "x" as well as table events on tables "x" and "y". The hello_events
plugin has be setup to only be interested in tables that are in the
databases of interest. So you will not see any events if you do an insert
into table "x" in database "z" because "z" was not in the list of databases
to watch.

NOTE: Since the current session was created before the plugin was enabled
you will not see any session events. After reconnection you will start
seeing them.

 
I haven't really tested this very much so if you are lucky you may find some
bugs. 

Something that still needs to be sorted out is the order in which event
observers are called when multiple plugins are interested in an event. There
are 3 possibilities, either a plugin will want its event called first, last,
or it doesn't care. The problem is if two or more plugins want all be called
first or last for the same event. For example PBMS will want to be called
first for the PRE_WRITE_ROW and PRE_UPDATE_ROW events.

Barry


On 4/23/10 10:55 AM, "Jay Pipes" <jaypipes@xxxxxxxxx> wrote:

> Hi Barry!  I can't find your branch on Launchpad.net.  Could you post
> the link to it?
> 
> Thanks!
> 
> jay
> 
> On Thu, Apr 22, 2010 at 11:27 PM, Barry Leslie
> <Barry.Leslie@xxxxxxxxxxxxx> wrote:
>> Hi,
>> 
>> I am working on a low level events plugin. The idea is that this API can be
>> used to implement other plugins which are interested in observing different
>> database events and doing something with the information.
>> 
>> There are 3 type of events: "Session Events", "Schema Events", and "Table
>> Events". The plugins can register which events they are interested in and
>> then they will be notified of only the events they are interested in.
>> 
>> New plugin events can be added as people have need of them, currently I have
>> added the events I need for the PBMS daemon:
>> 
>>   /* Schema events: */
>>    PRE_DROP_TABLE,   POST_DROP_TABLE,
>>    PRE_RENAME_TABLE, POST_RENAME_TABLE,
>> 
>>    /* Table events: */
>>    PRE_WRITE_ROW,    POST_WRITE_ROW,
>>    PRE_UPDATE_ROW,   POST_UPDATE_ROW,
>>    PRE_DELETE_ROW,   POST_DELETE_ROW,
>> 
>>    /* Session events: */
>>    PRE_CREATE_DATABASE, POST_CREATE_DATABASE,
>>    PRE_DROP_DATABASE,   POST_DROP_DATABASE,
>> 
>> Table events are specific to a table so in he case of PBMS I can say I am
>> interested in table events that occur only on tables that contain BLOB
>> columns and I can specify exactly which events I am interested in.
>> 
>> Schema events are events that occur with in a specific database. So a plugin
>> can tell drizzle that it is only interested in schema events that occur on
>> database 'XYZ'.
>> 
>> Session events are events that occur out side of the context of a database
>> or table. It would be possible for example to only track session events for
>> specific users.
>> 
>> For any one event drizzle only calls the event observers that have
>> registered an interest in that event. So if no plugins have registered an
>> interest in an event nothing is done.
>> 
>> The event handlers are specific to each event, passing in what ever
>> information is relevant to that event. There is NO generic event handler.
>> 
>> The 'PRE' events may allow data modification depending on the type of event.
>> If a 'PRE' event handler fails then the action will be aborted. "POST" event
>> handlers are ReadOny and cannot modify the data, they are also not allowed
>> to fail, or if they do it will have no effect on the operation.
>> 
>> I have pushed up the branch "drizzle_events" containing my new plugin API.
>> The main points of interest are:
>> 
>> drizzled/plugin/event.h
>> drizzled/plugin/event.cc
>> 
>> You can look in drizzled/table_share.h and drizzled/session.h to see how the
>> events of interest are registered with the table, schema. or session.
>> 
>> You will find some example event points in:
>> drizzled/cursor.cc
>> drizzled/plugin/storage_engine.cc
>> drizzled/statement/create_schema.cc
>> drizzled/statement/drop_schema.cc
>> 
>> I have also created an example pluggin that observes some events and prints
>> them out as they occur.
>> 
>> plugin/hello_events
>> 
>> So I will just put on my flame proof suit and wait for people's comments and
>> suggestions. :)
>> 
>> Barry
>> 
>> 
>> -------------------------------------------------------------------------
>> Barry Leslie
>> 
>> SNAP Innovation Softwareentwicklung GmbH
>> Senior Software Engineer
>> 
>> Tel: (001) 250 884 1820
>> Fax: (001) 250 595 4460
>> Email: Barry.Leslie@xxxxxxxxxxxxx
>> Web: www.PrimeBase.com
>> 
>> SNAP Innovation Softwareentwicklung GmbH, D-22765 Hamburg,
>> Max-Brauer-Allee 50, Germany
>> Amtsgericht Hamburg HRB 61066, Geschäftsführer: Ulrich Zimmer, Paul
>> McCullagh
>> -------------------------------------------------------------------------
>> 
>> 
>> 
>> 
>> _______________________________________________
>> Mailing list: https://launchpad.net/~drizzle-discuss
>> Post to     : drizzle-discuss@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~drizzle-discuss
>> More help   : https://help.launchpad.net/ListHelp
>> 

-------------------------------------------------------------------------
Barry Leslie

SNAP Innovation Softwareentwicklung GmbH
Senior Software Engineer

Tel: (001) 250 884 1820
Fax: (001) 250 595 4460
Email: Barry.Leslie@xxxxxxxxxxxxx
Web: www.PrimeBase.com

SNAP Innovation Softwareentwicklung GmbH, D-22765 Hamburg,
Max-Brauer-Allee 50, Germany
Amtsgericht Hamburg HRB 61066, Geschäftsführer: Ulrich Zimmer, Paul
McCullagh
-------------------------------------------------------------------------






References