List:Commits« Previous MessageNext Message »
From:ahristov Date:January 16 2006 1:59pm
Subject:bk commit into 5.1 tree (andrey:1.2054) BUG#16435
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of andrey. When andrey does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2054 06/01/16 14:59:25 andrey@lmy004. +4 -0
  fix bug #16435 (Weekly events execute every second) (WL#1034 Internal CRON)
  Before the interval expression was considered to be in seconds, now it is
  just a number and the type of interval is considered.

  sql/event_timed.cc
    1.18 06/01/16 14:59:18 andrey@lmy004. +50 -38
    - more docs
    - add static get_next_time() which sums a TIME with an interval
    - fix bug #16435 (Weekly events execute every second)
    Before the interval expression was considered to be in seconds, now it is
    just a number and the type of interval is considered.

  sql/event_executor.cc
    1.19 06/01/16 14:59:18 andrey@lmy004. +6 -1
    - pass thd to event_timed::compute_next_execution_time()
    - a bit more DBUG info in the server log

  sql/event.h
    1.13 06/01/16 14:59:17 andrey@lmy004. +2 -2
    pass thd to mark_last_executed() to be able to call thd->end_time()

  sql/event.cc
    1.21 06/01/16 14:59:17 andrey@lmy004. +6 -0
    don't use second_part

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	andrey
# Host:	lmy004.
# Root:	/work/mysql-5.1-tt-copy-works

--- 1.20/sql/event.cc	2006-01-11 12:49:43 +01:00
+++ 1.21/sql/event.cc	2006-01-16 14:59:17 +01:00
@@ -88,8 +88,14 @@
 int
 my_time_compare(TIME *a, TIME *b)
 {
+/*
+  Switch to this when we have miliseconds resolution
+
   my_ulonglong a_t= TIME_to_ulonglong_datetime(a)*100L + a->second_part;
   my_ulonglong b_t= TIME_to_ulonglong_datetime(b)*100L + b->second_part;
+*/
+  my_ulonglong a_t= TIME_to_ulonglong_datetime(a);
+  my_ulonglong b_t= TIME_to_ulonglong_datetime(b);
 
   if (a_t > b_t)
     return 1;

--- 1.12/sql/event.h	2006-01-12 19:51:02 +01:00
+++ 1.13/sql/event.h	2006-01-16 14:59:17 +01:00
@@ -143,12 +143,12 @@
 
   int
   load_from_row(MEM_ROOT *mem_root, TABLE *table);
-  
+
   bool
   compute_next_execution_time();  
 
   void
-  mark_last_executed();
+  mark_last_executed(THD *thd);
   
   int
   drop(THD *thd);

--- 1.18/sql/event_executor.cc	2006-01-12 16:51:18 +01:00
+++ 1.19/sql/event_executor.cc	2006-01-16 14:59:18 +01:00
@@ -335,8 +335,13 @@
       pthread_t th;
 
       DBUG_PRINT("evex main thread",("mark_last_executed"));
-      et->mark_last_executed();
+      DBUG_PRINT("evex main thread", ("[%10s] this exec at [%llu]", et->name.str,
+                               TIME_to_ulonglong_datetime(&et->execute_at)));
+      et->mark_last_executed(thd);
       et->compute_next_execution_time();
+      DBUG_PRINT("evex main thread", ("[%10s] next exec at [%llu]", et->name.str,
+                               TIME_to_ulonglong_datetime(&et->execute_at)));
+
       et->update_fields(thd);
       DBUG_PRINT("info", ("  Spawning a thread %d", ++iter_num));
 #ifndef DBUG_FAULTY_THR

--- 1.17/sql/event_timed.cc	2006-01-12 16:51:19 +01:00
+++ 1.18/sql/event_timed.cc	2006-01-16 14:59:18 +01:00
@@ -355,7 +355,7 @@
  Loads an event from a row from mysql.event
  
  SYNOPSIS
-   event_timed::load_from_row()
+   event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table)
    
  REMARKS
    This method is silent on errors and should behave like that. Callers
@@ -499,8 +499,40 @@
 
 
 /*
-  Note: In the comments this->ends is referenced as m_ends
+ Computes the sum of a timestamp plus interval
+ 
+ SYNOPSIS
+   get_next_time(TIME *start, int interval_value, interval_type interval)
+   
+   start          - add interval_value to this time
+   ival_value - quantity of time type interval to add
+   ival       - type of interval to add (SECOND, MINUTE, HOUR, WEEK ...) 
+*/
+
+static
+TIME get_next_time(TIME *start, int ival_value, interval_type ival)
+{
+  TIME ret;
+  Item_func_now_utc item_now_utc;
+  Item_int item_expr(ival_value);
+  Item_date_add_interval dai((Item *)&item_now_utc, (Item *)&item_expr, ival, 0);
+  
+  dai.fix_fields(current_thd, NULL);
+  dai.get_date(&ret, TIME_FUZZY_DATE);
 
+  return ret;
+}
+
+
+/*
+ Computes next execution time. 
+ 
+ SYNOPSIS
+   event_timed::compute_next_execution_time()
+ 
+ REMARKS:
+   The time is set in execute_at, if no more executions the latter is set to
+   0000-00-00.
 */
 
 bool
@@ -605,14 +637,10 @@
       execute_at= time_now;
     else
     {
-      my_time_t last, ll_ends;
-
-      // There was previous execution     
-      last= sec_since_epoch_TIME(&last_executed) + expression;
-      ll_ends= sec_since_epoch_TIME(&ends);
-      //now convert back to TIME
-      //ToDo Andrey: maybe check for error here?
-      if (ll_ends < last)
+      TIME next_exec= get_next_time(&last_executed, expression, interval);
+      
+      // There was previous execution
+      if (my_time_compare(&ends, &next_exec) == -1)
       {
         // Next execution after ends. No more executions
         set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME);
@@ -620,7 +648,7 @@
           dropped= true;
       }
       else
-        my_tz_UTC->gmt_sec_to_TIME(&execute_at, last);
+        execute_at= next_exec;
     }
     goto ret;
   }
@@ -628,14 +656,11 @@
   {
     // both starts and m_ends are not set, se we schedule for the next
     // based on last_executed
-    if (!last_executed.year)
+    if (last_executed.year)
+      execute_at= get_next_time(&last_executed, expression, interval);
+    else
        //last_executed not set. Schedule the event for now
       execute_at= time_now;
-    else
-      //ToDo Andrey: maybe check for error here?
-      my_tz_UTC->gmt_sec_to_TIME(&execute_at, 
-                   sec_since_epoch_TIME(&last_executed) + expression);
-    goto ret;
   }
   else
   {
@@ -648,17 +673,10 @@
         Hence schedule for starts + m_expression in case last_executed
         is not set, otherwise to last_executed + m_expression
       */
-      my_time_t last;
-
-      //convert either last_executed or starts to seconds
       if (last_executed.year)
-        last= sec_since_epoch_TIME(&last_executed) + expression;
+        execute_at= get_next_time(&last_executed, expression, interval);
       else
-        last= sec_since_epoch_TIME(&starts);
-
-      //now convert back to TIME
-      //ToDo Andrey: maybe check for error here?
-      my_tz_UTC->gmt_sec_to_TIME(&execute_at, last);
+        execute_at= starts;
     }
     else
     {
@@ -668,25 +686,20 @@
         Hence check for m_last_execute and increment with m_expression.
         If last_executed is not set then schedule for now
       */
-      my_time_t last, ll_ends;
 
       if (!last_executed.year)
         execute_at= time_now;
       else
       {
-        last= sec_since_epoch_TIME(&last_executed);
-        ll_ends= sec_since_epoch_TIME(&ends);
-        last+= expression;
-        //now convert back to TIME
-        //ToDo Andrey: maybe check for error here?
-        if (ll_ends < last)
+        TIME next_exec= get_next_time(&last_executed, expression, interval);
+        if (my_time_compare(&ends, &next_exec) == -1)
         {
           set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME);
           if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP)
             dropped= true;
         }
         else
-          my_tz_UTC->gmt_sec_to_TIME(&execute_at, last);
+          execute_at= next_exec;
       }
     }
     goto ret;
@@ -698,13 +711,12 @@
 
 
 void
-event_timed::mark_last_executed()
+event_timed::mark_last_executed(THD *thd)
 {
   TIME time_now;
-  my_time_t now;
 
-  time((time_t *)&now);
-  my_tz_UTC->gmt_sec_to_TIME(&time_now, now);
+  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
 #ifdef ANDREY_0
Thread
bk commit into 5.1 tree (andrey:1.2054) BUG#16435ahristov16 Jan