Commit 7ff79771 authored by unknown's avatar unknown
Browse files

WL#1034 updated

- split into several files
- forbid parallel execution (before analyse is done how to make it possible)
  because the same sp_head instance cannot be executed in parallel
- added GPL headers
- changed EVENT_ACL to be per DB variable
- fixed minor problems


mysql-test/lib/init_db.sql:
  WL#1034 updated
  - add Event_priv to mysql.user (update test)
  - add updated mysql.event table struct
scripts/mysql_fix_privilege_tables.sql:
  WL#1034 updated
  add updated mysql.event structure
sql/Makefile.am:
  split event.cc into
  - event.cc (create/alter/drop)
  - event_executor.cc (main and worker threads)
  - event_timed.cc (class event_timed)
  - event_priv.h (some definitions used internally by the module)
sql/event.cc:
  - added GPL header
  - split into few files
  - fixed some issues after code review
  - now using SP routines for opening/traversing/closing tables
    (will be reverted)
sql/event.h:
  - add GPL header
  - remove two methods - inline them in sql_yacc.yy 
  - don't use absolute values for EVEX_ defines but the SP_ equivalents (have to move 100% to SP_
    defines and as later step to not transfer messages upwards in the stack but
    report them at the place they occur)
  - updated reference table definition
  - move default mem_root param from event.cc to the header
sql/mysqld.cc:
  WL#1034
  rename --event-executor to --event-scheduler
  executor sounds a bit scary :)
sql/set_var.cc:
  rename internal variable name from event_executor to event_scheduler
  (ppl won't be scarried anymore :)
sql/share/errmsg.txt:
  omit one %s - not needed
sql/sp_head.cc:
  disable this DBUG_PRINT for a bit. m_next_cached_sp is 0x0 and I get crash here...
sql/sp_head.h:
  remove m_old_cmq, a temporal variable is used in sql_yacc.yy (Serg's idea)
  to keep the previous state.
  $<ulong_val>$ =  ....
  
  YYTHD->client_capabilites != $<ulong_val>4;
  
  (the same is done also for class event_timed)
sql/sql_acl.cc:
  handle pre-5.1.4 table and give the user EVENT_ACL if he had CREATE_ACL
sql/sql_acl.h:
  fix the bitmask
sql/sql_parse.cc:
  - move from EVENT_ACL being global to EVENT_ACL being per DB like
    CREATE_PROC_ACL
  - lex->m_qname dropped, because not needed, fix code therefore
  - add comment that SHOW CREATE EVENT has to be implemented
sql/sql_yacc.yy:
  - use temporal variable of Bison to store a short lived value
  - fix indentation
  - inline 2 class event_timed methods in the parser
sql/tztime.h:
  be more expressive - it's already extern
parent e7f18c97
Loading
Loading
Loading
Loading
+30 −3
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ CREATE TABLE user (
  Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL,
  Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL,
  Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL,
  Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL,
  ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL,
  ssl_cipher BLOB NOT NULL,
  x509_issuer BLOB NOT NULL,
@@ -103,9 +104,9 @@ CHARACTER SET utf8 COLLATE utf8_bin
comment='Users and global privileges';


INSERT INTO user VALUES ('localhost'   ,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
INSERT INTO user VALUES ('@HOSTNAME@%' ,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
REPLACE INTO user VALUES ('127.0.0.1'  ,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
INSERT INTO user VALUES ('localhost'   ,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
INSERT INTO user VALUES ('@HOSTNAME@%' ,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
REPLACE INTO user VALUES ('127.0.0.1'  ,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
INSERT  INTO user (host,user) VALUES ('localhost','');
INSERT  INTO user (host,user) VALUES ('@HOSTNAME@%','');

@@ -566,3 +567,29 @@ CREATE TABLE proc (
  comment           char(64) collate utf8_bin DEFAULT '' NOT NULL,
  PRIMARY KEY (db,name,type)
) character set utf8 comment='Stored Procedures';


CREATE TABLE event (
  'db' VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  'name' VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  'body' longblob NOT NULL,
  'definer' VARCHAR(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  'execute_at' DATETIME default NULL,
  'transient_expression' int(11) default NULL,
  'interval_type' ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK',
                       'SECOND','MICROSECOND', 'YEAR_MONTH','DAY_HOUR',
                       'DAY_MINUTE','DAY_SECOND',
                       'HOUR_MINUTE','HOUR_SECOND',
                       'MINUTE_SECOND','DAY_MICROSECOND',
                       'HOUR_MICROSECOND','MINUTE_MICROSECOND',
                       'SECOND_MICROSECOND') default NULL,
  'created' TIMESTAMP NOT NULL default '0000-00-00 00:00:00',
  'modified' TIMESTAMP NOT NULL default '0000-00-00 00:00:00',
  'last_executed' DATETIME default NULL,
  'starts' DATETIME default NULL,
  'ends' DATETIME default NULL,
  'status' ENUM('ENABLED','DISABLED') NOT NULL default 'ENABLED',
  'on_completion' ENUM('DROP','PRESERVE') NOT NULL default 'DROP',
  'comment' varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  PRIMARY KEY  ('db','name')
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events';
+38 −0
Original line number Diff line number Diff line
@@ -526,3 +526,41 @@ ALTER TABLE proc MODIFY db
                         char(77) collate utf8_bin DEFAULT '' NOT NULL,
                  MODIFY comment
                         char(64) collate utf8_bin DEFAULT '' NOT NULL;

#
# EVENT table
#


CREATE TABLE event (
  'db' VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  'name' VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  'body' longblob NOT NULL,
  'definer' VARCHAR(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  'execute_at' DATETIME default NULL,
  'transient_expression' int(11) default NULL,
  'interval_type' ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK',
                       'SECOND','MICROSECOND', 'YEAR_MONTH','DAY_HOUR',
                       'DAY_MINUTE','DAY_SECOND',
                       'HOUR_MINUTE','HOUR_SECOND',
                       'MINUTE_SECOND','DAY_MICROSECOND',
                       'HOUR_MICROSECOND','MINUTE_MICROSECOND',
                       'SECOND_MICROSECOND') default NULL,
  'created' TIMESTAMP NOT NULL default '0000-00-00 00:00:00',
  'modified' TIMESTAMP NOT NULL default '0000-00-00 00:00:00',
  'last_executed' DATETIME default NULL,
  'starts' DATETIME default NULL,
  'ends' DATETIME default NULL,
  'status' ENUM('ENABLED','DISABLED') NOT NULL default 'ENABLED',
  'on_completion' ENUM('DROP','PRESERVE') NOT NULL default 'DROP',
  'comment' varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '',
  PRIMARY KEY  ('db','name')
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events';


#
# EVENT privilege
#

ALTER TABLE mysql.user add Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Create_user_priv;
ALTER TABLE mysql.db add Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL;
+3 −2
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
                        tztime.h my_decimal.h\
			sp_head.h sp_pcontext.h sp_rcontext.h sp.h sp_cache.h \
			parse_file.h sql_view.h	sql_trigger.h \
			sql_array.h sql_cursor.h event.h \
			sql_array.h sql_cursor.h event.h event_priv.h \
			sql_plugin.h authors.h
mysqld_SOURCES =	sql_lex.cc sql_handler.cc sql_partition.cc \
			item.cc item_sum.cc item_buff.cc item_func.cc \
@@ -94,7 +94,8 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
			gstream.cc spatial.cc sql_help.cc sql_cursor.cc \
                        tztime.cc my_time.c my_decimal.cc\
			sp_head.cc sp_pcontext.cc  sp_rcontext.cc sp.cc \
			sp_cache.cc parse_file.cc sql_trigger.cc event.cc \
			sp_cache.cc parse_file.cc sql_trigger.cc \
                        event_executor.cc event.cc event_timed.cc \
			sql_plugin.cc\
			handlerton.cc
EXTRA_mysqld_SOURCES =	ha_innodb.cc ha_berkeley.cc ha_archive.cc \
+75 −1566

File changed.

Preview size limit exceeded, changes collapsed.

+68 −49
Original line number Diff line number Diff line
/* -*- C++ -*- */
/* Copyright (C) 2000-2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#ifndef _EVENT_H_
#define _EVENT_H_
#include "sp_head.h"
#include "sp.h"


extern ulong opt_event_executor;

#define EVEX_OK                 0
#define EVEX_KEY_NOT_FOUND     -1
#define EVEX_OPEN_TABLE_FAILED -2
#define EVEX_WRITE_ROW_FAILED  -3
#define EVEX_DELETE_ROW_FAILED -4
#define EVEX_GET_FIELD_FAILED  -5
#define EVEX_PARSE_ERROR       -6
#define EVEX_INTERNAL_ERROR    -7
#define EVEX_NO_DB_ERROR       -8
#define EVEX_GENERAL_ERROR     -9
#define EVEX_BAD_PARAMS        -10
#define EVEX_NOT_RUNNING       -11
#define EVEX_OK                 SP_OK
#define EVEX_KEY_NOT_FOUND      SP_KEY_NOT_FOUND
#define EVEX_OPEN_TABLE_FAILED  SP_OPEN_TABLE_FAILED
#define EVEX_WRITE_ROW_FAILED   SP_WRITE_ROW_FAILED
#define EVEX_DELETE_ROW_FAILED  SP_DELETE_ROW_FAILED
#define EVEX_GET_FIELD_FAILED   SP_GET_FIELD_FAILED
#define EVEX_PARSE_ERROR        SP_PARSE_ERROR
#define EVEX_INTERNAL_ERROR     SP_INTERNAL_ERROR
#define EVEX_NO_DB_ERROR        SP_NO_DB_ERROR
#define EVEX_GENERAL_ERROR     -20
#define EVEX_BAD_IDENTIFIER     SP_BAD_IDENTIFIER
#define EVEX_BODY_TOO_LONG      SP_BODY_TOO_LONG
#define EVEX_BAD_PARAMS        -21
#define EVEX_NOT_RUNNING       -22

#define EVENT_EXEC_NO_MORE      (1L << 0)
#define EVENT_NOT_USED          (1L << 1)

#define SP_OK                 0
#define SP_KEY_NOT_FOUND     -1
#define SP_OPEN_TABLE_FAILED -2
#define SP_WRITE_ROW_FAILED  -3
#define SP_DELETE_ROW_FAILED -4
#define SP_GET_FIELD_FAILED  -5
#define SP_PARSE_ERROR       -6
#define SP_INTERNAL_ERROR    -7
#define SP_NO_DB_ERROR       -8
#define SP_BAD_IDENTIFIER    -9
#define SP_BODY_TOO_LONG    -10

extern ulong opt_event_executor;

enum enum_event_on_completion
{ 
@@ -40,11 +71,12 @@ class event_timed
{
  event_timed(const event_timed &);	/* Prevent use of these */
  void operator=(event_timed &);
  my_bool running;
  pthread_mutex_t LOCK_running;

public:
  LEX_STRING m_db;
  LEX_STRING m_name;
  LEX_STRING m_qname;		// db.name
  LEX_STRING m_body;

  LEX_STRING m_definer_user;
@@ -64,9 +96,6 @@ class event_timed
  enum enum_event_status m_status;
  sp_head *m_sphead;



  uint m_old_cmq;  // Old CLIENT_MULTI_QUERIES value  
  const uchar *m_body_begin;
  
  bool m_dropped;
@@ -75,15 +104,19 @@ class event_timed
  bool m_last_executed_changed;
  bool m_status_changed;

  event_timed():m_expr(0), m_created(0), m_modified(0),
  event_timed():running(0), m_expr(0), m_created(0), m_modified(0),
                m_on_completion(MYSQL_EVENT_ON_COMPLETION_DROP),
                m_status(MYSQL_EVENT_ENABLED), m_sphead(0), m_dropped(false),
                m_free_sphead_on_delete(true), m_flags(0),
                m_last_executed_changed(false), m_status_changed(false)
  { init(); }
  {
    pthread_mutex_init(&LOCK_running, MY_MUTEX_INIT_FAST);
    init();
  }
 
  ~event_timed()
  {
    pthread_mutex_destroy(&LOCK_running);
    if (m_free_sphead_on_delete)
	    free_sp();
  }
@@ -115,12 +148,6 @@ class event_timed
  void
  init_comment(THD *thd, LEX_STRING *comment);

  void
  set_on_completion_drop(bool drop);

  void
  set_event_status(bool enabled);

  int
  load_from_row(MEM_ROOT *mem_root, TABLE *table);
  
@@ -140,10 +167,10 @@ class event_timed
  get_show_create_event(THD *thd, uint *length);
  
  int
  execute(THD *thd, MEM_ROOT *mem_root);
  execute(THD *thd, MEM_ROOT *mem_root= NULL);

  int
  compile(THD *thd, MEM_ROOT *mem_root);
  compile(THD *thd, MEM_ROOT *mem_root= NULL);
  
  void free_sp()
  {
@@ -172,29 +199,21 @@ init_events();
void
shutdown_events();

/*
typedef struct st_event_item {
  my_time_t execute_at;
  sp_head *proc;
  char *definer_user;
  char *definer_host;
} EVENT_ITEM;
*/

// auxiliary
int 
event_timed_compare(event_timed **a, event_timed **b);


/*
CREATE TABLE `event` (
  `db` varchar(64) character set latin1 collate latin1_bin NOT NULL default '',
  `name` varchar(64) NOT NULL default '',
  `body` blob NOT NULL,
  `definer` varchar(77) character set latin1 collate latin1_bin NOT NULL default '',
  `db` varchar(64) character set utf8 collate utf8_bin NOT NULL default '',
  `name` varchar(64) character set utf8 collate utf8_bin NOT NULL default '',
  `body` longblob NOT NULL,
  `definer` varchar(77) character set utf8 collate utf8_bin NOT NULL default '',
  `execute_at` datetime default NULL,
  `transient_expression` int(11) default NULL,
  `interval_type` enum('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK',
              'SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE',
	      'DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND',
	      'DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND',
	      'SECOND_MICROSECOND') DEFAULT NULL,
  `interval_type` enum('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') default NULL,
  `created` timestamp NOT NULL default '0000-00-00 00:00:00',
  `modified` timestamp NOT NULL default '0000-00-00 00:00:00',
  `last_executed` datetime default NULL,
@@ -202,9 +221,9 @@ CREATE TABLE `event` (
  `ends` datetime default NULL,
  `status` enum('ENABLED','DISABLED') NOT NULL default 'ENABLED',
  `on_completion` enum('DROP','PRESERVE') NOT NULL default 'DROP',
  `comment` varchar(64) character set latin1 collate latin1_bin NOT NULL default '',
  `comment` varchar(64) character set utf8 collate utf8_bin NOT NULL default '',
  PRIMARY KEY  (`db`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
) ENGINE=MyISAM DEFAULT CHARSET=utf8
*/

#endif /* _EVENT_H_ */
Loading