Commit b934539d authored by unknown's avatar unknown
Browse files

fix for bug#16537

(post-review pre-push changes)
coding style (mostly trailing spaces removed)


mysql-test/r/events.result:
  fix result file
sql/event.cc:
  - remove trailing spaces
  - add a missing initializer (gcc warning)
  - C++ to C comments
sql/event_executor.cc:
  - fix coding style (C++ to C comments, remove trailing spaces)
  - fix wrong indexing buggie not found till now (queue indexing is 0 based,
    not 1 based)
sql/event_timed.cc:
  - fix coding style
parent f6f52921
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ drop event event2;
CREATE EVENT event_starts_test ON SCHEDULE EVERY 10 SECOND COMMENT "" DO SELECT 1;
SHOW EVENTS;
Db	Name	Definer	Type	Execute at	Interval value	Interval field	Starts	Ends	Status
events_test	event_starts_test	root@localhost	RECURRING	NULL	10	INTERVAL_SECOND	#	#	ENABLED
events_test	event_starts_test	root@localhost	RECURRING	NULL	10	SECOND	#	#	ENABLED
SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
starts IS NULL	ends IS NULL	comment
0	1	
@@ -69,21 +69,21 @@ DROP EVENT event_starts_test;
CREATE EVENT event_starts_test ON SCHEDULE EVERY 20 SECOND STARTS '2020-02-02 20:00:02' ENDS '2022-02-02 20:00:02' DO SELECT 2;
SHOW EVENTS;
Db	Name	Definer	Type	Execute at	Interval value	Interval field	Starts	Ends	Status
events_test	event_starts_test	root@localhost	RECURRING	NULL	20	INTERVAL_SECOND	#	#	ENABLED
events_test	event_starts_test	root@localhost	RECURRING	NULL	20	SECOND	#	#	ENABLED
SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
starts IS NULL	ends IS NULL	comment
0	0	
ALTER EVENT event_starts_test COMMENT "non-empty comment";
SHOW EVENTS;
Db	Name	Definer	Type	Execute at	Interval value	Interval field	Starts	Ends	Status
events_test	event_starts_test	root@localhost	RECURRING	NULL	20	INTERVAL_SECOND	#	#	ENABLED
events_test	event_starts_test	root@localhost	RECURRING	NULL	20	SECOND	#	#	ENABLED
SELECT starts IS NULL, ends IS NULL, comment FROM mysql.event WHERE db='events_test' AND name='event_starts_test';
starts IS NULL	ends IS NULL	comment
0	0	non-empty comment
ALTER EVENT event_starts_test COMMENT "";
SHOW EVENTS;
Db	Name	Definer	Type	Execute at	Interval value	Interval field	Starts	Ends	Status
events_test	event_starts_test	root@localhost	RECURRING	NULL	20	INTERVAL_SECOND	#	#	ENABLED
events_test	event_starts_test	root@localhost	RECURRING	NULL	20	SECOND	#	#	ENABLED
DROP EVENT event_starts_test;
create event e_43 on schedule every 1 second do set @a = 5;
set global event_scheduler = 1;
+98 −100
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ static TABLE_FIELD_W_TYPE event_table_fields[EVEX_FIELD_COUNT] = {
  {
    {(char *) STRING_WITH_LEN("last_executed")},
    {(char *) STRING_WITH_LEN("datetime")},
    {NULL, 0}
  },
  {
    {(char *) STRING_WITH_LEN("starts")},
@@ -343,8 +344,6 @@ event_timed_compare_q(void *vptr, byte* a, byte *b)
  RETURNS
   0 - OK
   1 - Error
  
 
*/

int
@@ -619,7 +618,7 @@ evex_fill_row(THD *thd, TABLE *table, event_timed *et, my_bool is_update)
                  store(et->name.str, et->name.length, system_charset_info))
    goto trunc_err;

  // both ON_COMPLETION and STATUS are NOT NULL thus not calling set_notnull()
  /* both ON_COMPLETION and STATUS are NOT NULL thus not calling set_notnull() */
  table->field[EVEX_FIELD_ON_COMPLETION]->store((longlong)et->on_completion);

  table->field[EVEX_FIELD_STATUS]->store((longlong)et->status);
@@ -653,7 +652,7 @@ evex_fill_row(THD *thd, TABLE *table, event_timed *et, my_bool is_update)

    if (!et->starts_null)
    {
      table->field[EVEX_FIELD_STARTS]->set_notnull();// set NULL flag to OFF
      table->field[EVEX_FIELD_STARTS]->set_notnull();
      table->field[EVEX_FIELD_STARTS]->
                            store_time(&et->starts, MYSQL_TIMESTAMP_DATETIME);
    }	   
@@ -679,8 +678,10 @@ evex_fill_row(THD *thd, TABLE *table, event_timed *et, my_bool is_update)
  else
  {
    DBUG_ASSERT(is_update);
    // it is normal to be here when the action is update
    // this is an error if the action is create. something is borked
    /*
      it is normal to be here when the action is update
      this is an error if the action is create. something is borked
    */
  }
    
  ((Field_timestamp *)table->field[EVEX_FIELD_MODIFIED])->set_time();
@@ -799,7 +800,10 @@ db_create_event(THD *thd, event_timed *et, my_bool create_if_not,

  ((Field_timestamp *)table->field[EVEX_FIELD_CREATED])->set_time();

  // evex_fill_row() calls my_error() in case of error so no need to handle it here
  /*
    evex_fill_row() calls my_error() in case of error so no need to
    handle it here
  */
  if ((ret= evex_fill_row(thd, table, et, false)))
    goto err; 

@@ -813,7 +817,7 @@ db_create_event(THD *thd, event_timed *et, my_bool create_if_not,
  if (mysql_bin_log.is_open())
  {
    thd->clear_error();
    // Such a statement can always go directly to binlog, no trans cache
    /* Such a statement can always go directly to binlog, no trans cache */
    thd->binlog_query(THD::MYSQL_QUERY_TYPE,
                      thd->query, thd->query_length, FALSE, FALSE);
  }
@@ -869,7 +873,7 @@ db_update_event(THD *thd, event_timed *et, sp_name *new_name)
    goto err;
  }
  
  // first look whether we overwrite
  /* first look whether we overwrite */
  if (new_name)
  {
    if (!sortcmp_lex_string(et->name, new_name->m_name, system_charset_info) &&
@@ -898,13 +902,12 @@ db_update_event(THD *thd, event_timed *et, sp_name *new_name)
    goto err;
  }

  
  store_record(table,record[1]);

  // Don't update create on row update.
  /* Don't update create on row update. */
  table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;

  // evex_fill_row() calls my_error() in case of error so no need to handle it here
  /* evex_fill_row() calls my_error() in case of error so no need to handle it here */
  if ((ret= evex_fill_row(thd, table, et, true)))
    goto err;

@@ -922,7 +925,7 @@ db_update_event(THD *thd, event_timed *et, sp_name *new_name)
    goto err;
  }

  // close mysql.event or we crash later when loading the event from disk
  /* close mysql.event or we crash later when loading the event from disk */
  close_thread_tables(thd);
  DBUG_RETURN(0);

@@ -999,7 +1002,7 @@ db_find_event(THD *thd, sp_name *name, LEX_STRING *definer, event_timed **ett,
    delete et;
    et= 0;
  }
  // don't close the table if we haven't opened it ourselves
  /* don't close the table if we haven't opened it ourselves */
  if (!tbl && table)
    close_thread_tables(thd);
  *ett= et;
@@ -1021,7 +1024,6 @@ db_find_event(THD *thd, sp_name *name, LEX_STRING *definer, event_timed **ett,
   RETURN VALUE
       0   - OK
       < 0 - error (in this case underlying functions call my_error()).

*/

static int
@@ -1040,7 +1042,7 @@ evex_load_and_compile_event(THD * thd, sp_name *spn, LEX_STRING definer,
  thd->mem_root= &evex_mem_root;

  thd->reset_n_backup_open_tables_state(&backup);
  // no need to use my_error() here because db_find_event() has done it
  /* no need to use my_error() here because db_find_event() has done it */
  ret= db_find_event(thd, spn, &definer, &ett, NULL, NULL);
  thd->restore_backup_open_tables_state(&backup);
  if (ret)
@@ -1092,7 +1094,7 @@ evex_load_and_compile_event(THD * thd, sp_name *spn, LEX_STRING definer,
                  ALTER EVENT.

   RETURNS
     0 - OK (always)
     0  OK (always)
*/

static int
@@ -1135,7 +1137,7 @@ evex_remove_from_cache(LEX_STRING *db, LEX_STRING *name, bool use_lock,
      }
      DBUG_PRINT("evex_remove_from_cache", ("delete from queue"));
      evex_queue_delete_element(&EVEX_EQ_NAME, i);
      // ok, we have cleaned
      /* ok, we have cleaned */
      ret= 0;
      goto done;
    }
@@ -1189,7 +1191,7 @@ evex_create_event(THD *thd, event_timed *et, uint create_options,
  VOID(pthread_mutex_unlock(&LOCK_evex_running));

done:
  // No need to close the table, it will be closed in sql_parse::do_command
  /* No need to close the table, it will be closed in sql_parse::do_command */

  DBUG_RETURN(ret);
}
@@ -1263,7 +1265,6 @@ evex_update_event(THD *thd, event_timed *et, sp_name *new_name,
     et              event's name
     drop_if_exists  if set and the event not existing => warning onto the stack
     rows_affected   affected number of rows is returned heres
          
*/

int db_drop_event(THD *thd, event_timed *et, bool drop_if_exists,
@@ -1366,7 +1367,6 @@ evex_drop_event(THD *thd, event_timed *et, bool drop_if_exists,
   RETURNS
     0  -  OK
     1  - Error during writing to the wire
          
*/

int
@@ -1417,7 +1417,6 @@ evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer)

    protocol->store((char*) sql_mode_str, sql_mode_len, system_charset_info);

    
    protocol->store(show_str.c_ptr(), show_str.length(), system_charset_info);
    ret= protocol->write();
    send_eof(thd);
@@ -1453,7 +1452,6 @@ evex_show_create_event(THD *thd, sp_name *spn, LEX_STRING definer)
         spawned and can_spawn() is the right method.
       - event_timed::can_spawn() returns false -> being runned ATM
         just set the flags so it should drop itself.

*/

int
@@ -1525,7 +1523,7 @@ evex_drop_db_events(THD *thd, char *db)
    }
    DBUG_PRINT("info",("%d elements in the queue",
               evex_queue_num_elements(EVEX_EQ_NAME)));
    evex_queue_delete_element(&EVEX_EQ_NAME, i);// 1 is top
    evex_queue_delete_element(&EVEX_EQ_NAME, i);// 0 is top
    DBUG_PRINT("info",("%d elements in the queue",
               evex_queue_num_elements(EVEX_EQ_NAME)));
    /*
@@ -1602,7 +1600,7 @@ evex_drop_db_events(THD *thd, char *db)
  VOID(pthread_mutex_unlock(&LOCK_event_arrays));
  end_read_record(&read_record_info);

  thd->version--;  // Force close to free memory
  thd->version--;   /* Force close to free memory */

  close_thread_tables(thd);

+60 −59
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ evex_check_system_tables()
  bool not_used;
  Open_tables_state backup;

  // thd is 0x0 during boot of the server. Later it's !=0x0
  /* thd is 0x0 during boot of the server. Later it's !=0x0 */
  if (!thd)
    return;

@@ -206,7 +206,7 @@ init_events()
  if (event_executor_running_global_var)
  {
#ifndef DBUG_FAULTY_THR
    //TODO Andrey: Change the error code returned!
    /* TODO Andrey: Change the error code returned! */
    if (pthread_create(&th, &connection_attrib, event_executor_main,(void*)NULL))
      DBUG_RETURN(ER_SLAVE_THREAD);
#else
@@ -339,14 +339,14 @@ executor_wait_till_next_event_exec(THD *thd)
    if (et->dropped)
      et->drop(thd);
    delete et;
    evex_queue_delete_element(&EVEX_EQ_NAME, 1);// 1 is top
    evex_queue_delete_element(&EVEX_EQ_NAME, 0);// 0 is top, internally 1
    VOID(pthread_mutex_unlock(&LOCK_event_arrays));
    sql_print_information("Event found disabled, dropping.");
    DBUG_RETURN(1);
  }

  DBUG_PRINT("evex main thread",("computing time to sleep till next exec"));
  // set the internal clock of thd
  /* set the internal clock of thd */
  thd->end_time();
  my_tz_UTC->gmt_sec_to_TIME(&time_now, thd->query_start());
  t2sleep= evex_time_diff(&et->execute_at, &time_now);
@@ -387,7 +387,7 @@ executor_wait_till_next_event_exec(THD *thd)

   SYNOPSIS
     event_executor_main() 
       arg - unused
       arg  unused

   NOTES
      1. The host of the thead is my_localhost
@@ -407,11 +407,10 @@ event_executor_main(void *arg)
  DBUG_PRINT("event_executor_main", ("EVEX thread started"));


  // init memory root
  /* init memory root */
  init_alloc_root(&evex_mem_root, MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC);


  // needs to call my_thread_init(), otherwise we get a coredump in DBUG_ stuff
  /* needs to call my_thread_init(), otherwise we get a coredump in DBUG_ stuff*/
  my_thread_init();

  if (sizeof(my_time_t) != sizeof(time_t))
@@ -422,8 +421,8 @@ event_executor_main(void *arg)
    goto err_no_thd;
  }
  
  //TODO Andrey: Check for NULL
  if (!(thd = new THD)) // note that contructor of THD uses DBUG_ !
  /* note that contructor of THD uses DBUG_ ! */
  if (!(thd = new THD))                         
  {
    sql_print_error("SCHEDULER: Cannot create THD for the main thread.");
    goto err_no_thd;
@@ -584,10 +583,10 @@ event_executor_main(void *arg)
    }
    DBUG_PRINT("evex main thread",("unlocking"));
    VOID(pthread_mutex_unlock(&LOCK_event_arrays));
  }// while
  }/* while */
finish:

  // First manifest that this thread does not work and then destroy
  /* First manifest that this thread does not work and then destroy */
  VOID(pthread_mutex_lock(&LOCK_evex_running));
  evex_is_running= false;
  evex_main_thread_id= 0;
@@ -627,7 +626,7 @@ event_executor_main(void *arg)
    delete et;
  }
  VOID(pthread_mutex_unlock(&LOCK_event_arrays));
  // ... then we can thrash the whole queue at once
  /* ... then we can thrash the whole queue at once */
  evex_queue_destroy(&EVEX_EQ_NAME);

  thd->proc_info = "Clearing";
@@ -667,7 +666,7 @@ event_executor_main(void *arg)

   SYNOPSIS
     event_executor_worker()
       arg - the event_timed object to be processed
       arg  The event_timed object to be processed
*/

pthread_handler_t
@@ -684,7 +683,7 @@ event_executor_worker(void *event_void)
#ifndef DBUG_FAULTY_THR
  my_thread_init();

  if (!(thd = new THD)) // note that contructor of THD uses DBUG_ !
  if (!(thd = new THD)) /* note that contructor of THD uses DBUG_ ! */
  {
    sql_print_error("SCHEDULER: Cannot create a THD structure in an worker.");
    goto err_no_thd;
@@ -699,7 +698,7 @@ event_executor_worker(void *event_void)

  thd->init_for_queries();

  // make this thread visible it has no vio -> show processlist needs this flag
  /* make this thread visible it has no vio -> show processlist needs this flag */
  thd->system_thread= 1;

  VOID(pthread_mutex_lock(&LOCK_thread_count));
@@ -780,8 +779,8 @@ event_executor_worker(void *event_void)
       thd - Thread context. Used for memory allocation in some cases.
     
   RETURNS
     0  - OK
    !0  - Error
     0  OK
    !0  Error

   NOTES
     Reports the error to the console
@@ -847,7 +846,7 @@ evex_load_events_from_db(THD *thd)
      break;
    }

    // let's find when to be executed  
    /* let's find when to be executed */
    if (et->compute_next_execution_time())
    {
      sql_print_error("SCHEDULER: Error while computing execution time of %s.%s."
@@ -869,7 +868,8 @@ evex_load_events_from_db(THD *thd)
  VOID(pthread_mutex_unlock(&LOCK_event_arrays));
  end_read_record(&read_record_info);
  
  thd->version--;  // Force close to free memory
  /* Force close to free memory */
  thd->version--;  

  close_thread_tables(thd);
  if (!ret)
@@ -891,13 +891,13 @@ evex_load_events_from_db(THD *thd)
       car - the new value

   Returns
     0 - OK (always)
     0  OK (always)
*/

bool
sys_var_event_executor::update(THD *thd, set_var *var)
{
  // here start the thread if not running.
  /* here start the thread if not running. */
  DBUG_ENTER("sys_var_event_executor::update");
  VOID(pthread_mutex_lock(&LOCK_evex_running));
  *value= var->save_result.ulong_value;
@@ -954,7 +954,8 @@ evex_print_warnings(THD *thd, event_timed *et)
  while ((err= it++))
  {
    String err_msg(msg_buf, sizeof(msg_buf), system_charset_info);
    err_msg.length(0);// set it to 0 or we start adding at the end
    /* set it to 0 or we start adding at the end. That's the trick ;) */
    err_msg.length(0);
    if (!prefix.length())
    {
      prefix.append("SCHEDULER: [");
+18 −20
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ event_timed::init_body(THD *thd)
             body_begin, thd->lex->ptr));

  body.length= thd->lex->ptr - body_begin;
  // Trim nuls at the end
  /* Trim nuls at the end */
  while (body.length && body_begin[body.length-1] == '\0')
    body.length--;

@@ -161,14 +161,13 @@ event_timed::init_execute_at(THD *thd, Item *expr)
  
  /* no starts and/or ends in case of execute_at */
  DBUG_PRINT("info", ("starts_null && ends_null should be 1 is %d",
              (starts_null && ends_null)))
                      (starts_null && ends_null)));
  DBUG_ASSERT(starts_null && ends_null);
  
  // let's check whether time is in the past
  /* let's check whether time is in the past */
  thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, 
                                            (my_time_t) thd->query_start());


  if ((not_used= expr->get_date(&ltime, TIME_NO_ZERO_DATE)))
    DBUG_RETURN(ER_WRONG_VALUE);

@@ -252,14 +251,14 @@ event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval)
  case INTERVAL_DAY_MINUTE:
    expression= (interval.day* 24 + interval.hour) * 60 + interval.minute;
    break;
  case INTERVAL_HOUR_SECOND: // day is anyway 0
  case INTERVAL_HOUR_SECOND: /* day is anyway 0 */
  case INTERVAL_DAY_SECOND:
    /* DAY_SECOND having problems because of leap seconds? */
    expression= ((interval.day* 24 + interval.hour) * 60 + interval.minute)*60
                 + interval.second;
    break;
  case INTERVAL_MINUTE_MICROSECOND: // day and hour are 0
  case INTERVAL_HOUR_MICROSECOND:// day is anyway 0
  case INTERVAL_MINUTE_MICROSECOND: /* day and hour are 0 */
  case INTERVAL_HOUR_MICROSECOND:   /* day is anyway 0    */
  case INTERVAL_DAY_MICROSECOND:
    DBUG_RETURN(EVEX_MICROSECOND_UNSUP);
    expression= ((((interval.day*24) + interval.hour)*60+interval.minute)*60 +
@@ -535,7 +534,7 @@ event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table)
  et->definer_user.str= strmake_root(mem_root, et->definer.str, len);
  et->definer_user.length= len;
  len= et->definer.length - len - 1;            //1 is because of @
  et->definer_host.str= strmake_root(mem_root, ptr + 1, len);//1: because of @
  et->definer_host.str= strmake_root(mem_root, ptr + 1, len);/* 1:because of @*/
  et->definer_host.length= len;
  
  et->starts_null= table->field[EVEX_FIELD_STARTS]->is_null();
@@ -597,14 +596,14 @@ event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table)
#endif
  last_executed_changed= false;

  // ToDo : Andrey . Find a way not to allocate ptr on event_mem_root
  /* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */
  if ((ptr= get_field(mem_root, table->field[EVEX_FIELD_STATUS])) == NullS)
    goto error;

  DBUG_PRINT("load_from_row", ("Event [%s] is [%s]", et->name.str, ptr));
  et->status= (ptr[0]=='E'? MYSQL_EVENT_ENABLED:MYSQL_EVENT_DISABLED);

  // ToDo : Andrey . Find a way not to allocate ptr on event_mem_root
  /* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */
  if ((ptr= get_field(mem_root,
                  table->field[EVEX_FIELD_ON_COMPLETION])) == NullS)
    goto error;
@@ -931,7 +930,7 @@ event_timed::mark_last_executed(THD *thd)
  thd->end_time();
  my_tz_UTC->gmt_sec_to_TIME(&time_now, (my_time_t) thd->query_start());

  last_executed= time_now; // was execute_at
  last_executed= time_now; /* was execute_at */
#ifdef ANDREY_0
  last_executed= execute_at;
#endif
@@ -1086,7 +1085,7 @@ event_timed::get_create_event(THD *thd, String *buf)
  }
  else
  {
    char dtime_buff[20*2+32];// +32 to make my_snprintf_{8bit|ucs2} happy
    char dtime_buff[20*2+32];/* +32 to make my_snprintf_{8bit|ucs2} happy */
    buf->append(STRING_WITH_LEN("AT '"));
    /*
      Pass the buffer and the second param tells fills the buffer and
@@ -1498,7 +1497,6 @@ event_timed::spawn_thread_finish(THD *thd)
  Returns
    0 - ok
    1 - not locked by this thread
  
*/