mirror of
https://github.com/MariaDB/server.git
synced 2026-10-23 18:49:29 +03:00
This patch add support of system triggers fired on server start up and shutdown. On start up triggers can be associated only with AFTER event time, on shutdown triggers associated with BEFORE event time. Several triggers can be created to be run on the same time/event type. Core implementation - Extended the sql grammar to support creation of system triggers on startup/shutdown - System triggers metadata is stored in the table mysql.event - Events and system triggers share the same name space since both are stored in the table mysql.event declared with the PRIMARY KEY (`db`,`name`). In result, attempt to create an event with the same name as existent trigger and vice versa results in failure with the new error ER_TRG_EVENT_CONFLICTS_NAME - Since system triggers metadata is stored in the mysql.event table, the table mysql.event is now opened on handling the DROP TRIGGER statement - In case server is started against old version of mysql.event table that missing columns required for support of system triggers, system trigger feature is disabled - System triggers are loaded from the table mysql.event right before their execution - System triggers can be created only by users with the SUPER privilege - Added the option --sys_triggers for mysqldump to dump system triggers. The option is turned off by default. In case this option is on, mysqldump first dump the table 'mysql' unconditionally, regardless whether it was listed in the option --ignore-database
87 lines
2.5 KiB
C++
87 lines
2.5 KiB
C++
#ifndef SQL_SQL_SYS_OR_DDL_TRIGGER_H
|
|
#define SQL_SQL_SYS_OR_DDL_TRIGGER_H
|
|
|
|
#include "sp_head.h"
|
|
#include "sql_trigger.h" // trg_all_events_set, TRG_EVENT_MAX
|
|
|
|
/**
|
|
Type representing events for system triggers (on logon, on logoff,
|
|
on startup, on shutdown) and ddl triggers
|
|
*/
|
|
enum trg_sys_event_type
|
|
{
|
|
TRG_SYS_EVENT_MIN= TRG_EVENT_MAX,
|
|
TRG_EVENT_STARTUP= TRG_SYS_EVENT_MIN, // bit #3
|
|
TRG_EVENT_SHUTDOWN, // bit #4
|
|
TRG_EVENT_LOGON, // bit #5
|
|
TRG_EVENT_LOGOFF, // bit #6
|
|
TRG_EVENT_DDL, // bit #7
|
|
TRG_SYS_EVENT_MAX
|
|
};
|
|
|
|
static inline trg_all_events_set sys_trg2bit(enum trg_sys_event_type trg)
|
|
{ return static_cast<trg_all_events_set>(1 << static_cast<int>(trg)); }
|
|
|
|
static inline bool is_sys_trg_events(trg_all_events_set events)
|
|
{
|
|
static const trg_all_events_set sys_events= trg_all_events_set(0) |
|
|
sys_trg2bit(TRG_EVENT_LOGON) |
|
|
sys_trg2bit(TRG_EVENT_LOGOFF) |
|
|
sys_trg2bit(TRG_EVENT_STARTUP) |
|
|
sys_trg2bit(TRG_EVENT_SHUTDOWN);
|
|
/*
|
|
Return true in case any of system events is set in the mask
|
|
*/
|
|
return ((events & sys_events) != 0);
|
|
}
|
|
|
|
static inline bool is_ddl_trg_events(trg_all_events_set events)
|
|
{
|
|
static const trg_all_events_set ddl_events= trg_all_events_set(0) |
|
|
sys_trg2bit(TRG_EVENT_DDL);
|
|
/*
|
|
Return true in case the only TRG_EVENT_DDL bit is set in the mask,
|
|
that is the trigger is solely for handling DDL events
|
|
*/
|
|
return events != 0 && ((events & ddl_events) == events);
|
|
}
|
|
|
|
|
|
/**
|
|
Class for representing a system trigger to run on events like
|
|
AFTER STARTUP / BEFORE SHUTDOWN / etc.
|
|
*/
|
|
|
|
class Sys_trigger : public Sql_alloc
|
|
{
|
|
public:
|
|
Sys_trigger(THD *thd, sp_head *sp)
|
|
: m_thd{thd}, m_sp{sp} {}
|
|
|
|
~Sys_trigger()
|
|
{
|
|
sp_head::destroy(m_sp);
|
|
}
|
|
|
|
bool execute();
|
|
|
|
Sys_trigger(const Sys_trigger&)= delete;
|
|
Sys_trigger &operator=(const Sys_trigger&)= delete;
|
|
|
|
private:
|
|
THD *m_thd;
|
|
sp_head *m_sp;
|
|
};
|
|
|
|
void run_after_startup_triggers(bool bootstrap_or_noacl);
|
|
void run_before_shutdown_triggers(bool bootstrap_or_noacl);
|
|
|
|
bool show_create_sys_trigger(THD *thd, const sp_name *trg_name);
|
|
bool fill_schema_triggers_from_mysql_events(THD *thd, TABLE_LIST *tables);
|
|
void report_trg_already_exist_error(const sp_name *spname);
|
|
bool find_sys_trigger_by_name(THD *thd, sp_name *spname, bool *found);
|
|
|
|
void release_resources(THD *original_thd);
|
|
|
|
#endif /* SQL_SQL_SYS_OR_DDL_TRIGGER_H */
|