Commit 83187d4e authored by vasil's avatar vasil

Implement this feature request:

http://bugs.mysql.com/30706

* Add a function that returns the number of microseconds since
  epoch - ut_time_us().

* Add (innodb|innobase|srv)_replication_delay MySQL config parameter.

* Add UT_WAIT_FOR() macro that waits for a specified condition to occur
  until a timeout elapses.

* Using all of the above, handle the replication thread specially in
  srv_conc_enter_innodb().

Approved by:	Heikki
parent 2f03b9e3
......@@ -7962,6 +7962,12 @@ static MYSQL_SYSVAR_BOOL(use_adaptive_hash_indexes, innobase_use_adaptive_hash_i
"Enable the InnoDB adaptive hash indexes (enabled by default)",
NULL, NULL, TRUE);
static MYSQL_SYSVAR_ULONG(replication_delay, srv_replication_delay,
PLUGIN_VAR_RQCMDARG,
"Replication thread delay (ms) on the slave server if "
"innodb_thread_concurrency is reached (0 by default)",
NULL, NULL, 0, 0, ~0UL, 0);
static MYSQL_SYSVAR_LONG(additional_mem_pool_size, innobase_additional_mem_pool_size,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.",
......@@ -8091,6 +8097,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
MYSQL_SYSVAR(rollback_on_timeout),
MYSQL_SYSVAR(stats_on_metadata),
MYSQL_SYSVAR(use_adaptive_hash_indexes),
MYSQL_SYSVAR(replication_delay),
MYSQL_SYSVAR(status_file),
MYSQL_SYSVAR(support_xa),
MYSQL_SYSVAR(sync_spin_loops),
......
......@@ -136,6 +136,8 @@ extern ulong srv_max_buf_pool_modified_pct;
extern ulong srv_max_purge_lag;
extern ibool srv_use_awe;
extern ibool srv_use_adaptive_hash_indexes;
extern ulint srv_replication_delay;
/*-------------------------------------------*/
extern ulint srv_n_rows_inserted;
......
......@@ -17,6 +17,21 @@ Created 1/20/1994 Heikki Tuuri
typedef time_t ib_time_t;
/*************************************************************************
Delays execution for at most max_wait_us microseconds or returns earlier
if cond becomes true; cond is evaluated every 2 ms. */
#define UT_WAIT_FOR(cond, max_wait_us) \
do { \
ullint start_us; \
start_us = ut_time_us(NULL); \
while (!(cond) \
&& ut_time_us(NULL) - start_us < (max_wait_us)) {\
\
os_thread_sleep(2000 /* 2 ms */); \
} \
} while (0)
/************************************************************
Gets the high 32 bits in a ulint. That is makes a shift >> 32,
but since there seem to be compiler bugs in both gcc and Visual C++,
......@@ -152,6 +167,18 @@ ut_usectime(
/*========*/
ulint* sec, /* out: seconds since the Epoch */
ulint* ms); /* out: microseconds since the Epoch+*sec */
/**************************************************************
Returns the number of microseconds since epoch. Similar to
time(3), the return value is also stored in *tloc, provided
that tloc is non-NULL. */
ullint
ut_time_us(
/*=======*/
/* out: us since epoch */
ullint* tloc); /* out: us since epoch, if non-NULL */
/**************************************************************
Returns the difference of two times in seconds. */
......
......@@ -28,6 +28,7 @@ Created 10/8/1995 Heikki Tuuri
#include "srv0srv.h"
#include "ut0mem.h"
#include "ut0ut.h"
#include "os0proc.h"
#include "mem0mem.h"
#include "mem0pool.h"
......@@ -341,6 +342,8 @@ disable adaptive hash indexes */
ibool srv_use_awe = FALSE;
ibool srv_use_adaptive_hash_indexes = TRUE;
ulint srv_replication_delay = 0;
/*-------------------------------------------*/
ulong srv_n_spin_wait_rounds = 20;
ulong srv_n_free_tickets_to_enter = 500;
......@@ -991,11 +994,10 @@ srv_conc_enter_innodb(
if (trx->mysql_thd != NULL
&& thd_is_replication_slave_thread(trx->mysql_thd)) {
/* TODO Do something more interesting (based on a config
parameter). Some users what to give the replication
thread very low priority, see http://bugs.mysql.com/25078
This can be done by introducing
innodb_replication_delay(ms) config parameter */
UT_WAIT_FOR(srv_conc_n_threads
< (lint)srv_thread_concurrency,
srv_replication_delay * 1000);
return;
}
......
......@@ -127,6 +127,31 @@ ut_usectime(
*ms = (ulint) tv.tv_usec;
}
/**************************************************************
Returns the number of microseconds since epoch. Similar to
time(3), the return value is also stored in *tloc, provided
that tloc is non-NULL. */
ullint
ut_time_us(
/*=======*/
/* out: us since epoch */
ullint* tloc) /* out: us since epoch, if non-NULL */
{
struct timeval tv;
ullint us;
ut_gettimeofday(&tv, NULL);
us = (ullint) tv.tv_sec * 1000000 + tv.tv_usec;
if (tloc != NULL) {
*tloc = us;
}
return(us);
}
/**************************************************************
Returns the difference of two times in seconds. */
......
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