Commit a3cc647d authored by Venkatesh Duggirala's avatar Venkatesh Duggirala

Bug #18808072 MYSQLBINLOG USES LOCALTIME() TO PRINT EVENTS, CAUSES KERNEL MUTEX CONTENTION

Problem: For every event read, mysqlbinlog calls localtime() which in turn
calls stat(/etc/localtime) which is causing kernel mutex contention.

Analysis and Fix:
localtime() calls stat(/etc/localtime) for every instance of the call
where as localtime_r() the reentrant version was optimized to store
the read only tz internal structure. Hence it will not call
stat(/etc/localtime). It will call only once at the beginning.
The mysql server is calling localtime_r() and mysqlbinlog tool is
one place where we are still using localtime().

Once the process (mysqlbinlog) is started if timezone is changed
it will be not picked up the the process and it will continue
with the same values as the beginning of the process. This
behavior is in-lined with mysql server.

Also adding localtime_r() and gmtime_r() support for windows.
parent 0d0c59ff
/* /*
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -2102,6 +2102,7 @@ int main(int argc, char** argv) ...@@ -2102,6 +2102,7 @@ int main(int argc, char** argv)
DBUG_PROCESS(argv[0]); DBUG_PROCESS(argv[0]);
my_init_time(); // for time functions my_init_time(); // for time functions
tzset(); // set tzname
if (load_defaults("my", load_default_groups, &argc, &argv)) if (load_defaults("my", load_default_groups, &argc, &argv))
exit(1); exit(1);
......
# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
...@@ -88,7 +88,7 @@ SET(HAVE_GETRLIMIT CACHE INTERNAL "") ...@@ -88,7 +88,7 @@ SET(HAVE_GETRLIMIT CACHE INTERNAL "")
SET(HAVE_GETRUSAGE CACHE INTERNAL "") SET(HAVE_GETRUSAGE CACHE INTERNAL "")
SET(HAVE_GETTIMEOFDAY CACHE INTERNAL "") SET(HAVE_GETTIMEOFDAY CACHE INTERNAL "")
SET(HAVE_GETWD CACHE INTERNAL "") SET(HAVE_GETWD CACHE INTERNAL "")
SET(HAVE_GMTIME_R CACHE INTERNAL "") SET(HAVE_GMTIME_R 1 CACHE INTERNAL "")
SET(HAVE_GRP_H CACHE INTERNAL "") SET(HAVE_GRP_H CACHE INTERNAL "")
SET(HAVE_IA64INTRIN_H CACHE INTERNAL "") SET(HAVE_IA64INTRIN_H CACHE INTERNAL "")
SET(HAVE_IEEEFP_H CACHE INTERNAL "") SET(HAVE_IEEEFP_H CACHE INTERNAL "")
...@@ -109,7 +109,7 @@ SET(HAVE_LANGINFO_H CACHE INTERNAL "") ...@@ -109,7 +109,7 @@ SET(HAVE_LANGINFO_H CACHE INTERNAL "")
SET(HAVE_LDIV 1 CACHE INTERNAL "") SET(HAVE_LDIV 1 CACHE INTERNAL "")
SET(HAVE_LIMITS_H 1 CACHE INTERNAL "") SET(HAVE_LIMITS_H 1 CACHE INTERNAL "")
SET(HAVE_LOCALE_H 1 CACHE INTERNAL "") SET(HAVE_LOCALE_H 1 CACHE INTERNAL "")
SET(HAVE_LOCALTIME_R CACHE INTERNAL "") SET(HAVE_LOCALTIME_R 1 CACHE INTERNAL "")
SET(HAVE_LOG2 CACHE INTERNAL "") SET(HAVE_LOG2 CACHE INTERNAL "")
SET(HAVE_LONGJMP 1 CACHE INTERNAL "") SET(HAVE_LONGJMP 1 CACHE INTERNAL "")
SET(HAVE_LRAND48 CACHE INTERNAL "") SET(HAVE_LRAND48 CACHE INTERNAL "")
......
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. /* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -142,8 +142,18 @@ int pthread_attr_init(pthread_attr_t *connect_att); ...@@ -142,8 +142,18 @@ int pthread_attr_init(pthread_attr_t *connect_att);
int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack); int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack);
int pthread_attr_destroy(pthread_attr_t *connect_att); int pthread_attr_destroy(pthread_attr_t *connect_att);
int my_pthread_once(my_pthread_once_t *once_control,void (*init_routine)(void)); int my_pthread_once(my_pthread_once_t *once_control,void (*init_routine)(void));
struct tm *localtime_r(const time_t *timep,struct tm *tmp);
struct tm *gmtime_r(const time_t *timep,struct tm *tmp); static inline struct tm *localtime_r(const time_t *timep, struct tm *tmp)
{
localtime_s(tmp, timep);
return tmp;
}
static inline struct tm *gmtime_r(const time_t *clock, struct tm *res)
{
gmtime_s(res, clock);
return res;
}
void pthread_exit(void *a); void pthread_exit(void *a);
int pthread_join(pthread_t thread, void **value_ptr); int pthread_join(pthread_t thread, void **value_ptr);
......
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. /* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -344,26 +344,4 @@ int pthread_attr_destroy(pthread_attr_t *connect_att) ...@@ -344,26 +344,4 @@ int pthread_attr_destroy(pthread_attr_t *connect_att)
return 0; return 0;
} }
/****************************************************************************
** Fix localtime_r() to be a bit safer
****************************************************************************/
struct tm *localtime_r(const time_t *timep,struct tm *tmp)
{
if (*timep == (time_t) -1) /* This will crash win32 */
{
bzero(tmp,sizeof(*tmp));
}
else
{
struct tm *res=localtime(timep);
if (!res) /* Wrong date */
{
bzero(tmp,sizeof(*tmp)); /* Keep things safe */
return 0;
}
*tmp= *res;
}
return tmp;
}
#endif /* __WIN__ */ #endif /* __WIN__ */
...@@ -2162,13 +2162,8 @@ void Log_event::print_timestamp(IO_CACHE* file, time_t* ts) ...@@ -2162,13 +2162,8 @@ void Log_event::print_timestamp(IO_CACHE* file, time_t* ts)
DBUG_ENTER("Log_event::print_timestamp"); DBUG_ENTER("Log_event::print_timestamp");
if (!ts) if (!ts)
ts = &when; ts = &when;
#ifdef MYSQL_SERVER // This is always false
struct tm tm_tmp; struct tm tm_tmp;
localtime_r(ts,(res= &tm_tmp)); localtime_r(ts,(res= &tm_tmp));
#else
res=localtime(ts);
#endif
my_b_printf(file,"%02d%02d%02d %2d:%02d:%02d", my_b_printf(file,"%02d%02d%02d %2d:%02d:%02d",
res->tm_year % 100, res->tm_year % 100,
res->tm_mon+1, res->tm_mon+1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment