Skip to content

Commit

Permalink
Merge 10.0 to 10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed May 26, 2017
2 parents 6bc9949 + 449a88e commit 4abc2dd
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 180 deletions.
9 changes: 9 additions & 0 deletions mysql-test/suite/innodb/r/drop_table_background.result
@@ -0,0 +1,9 @@
CREATE TABLE t(c0 SERIAL, c1 INT, c2 INT, c3 INT, c4 INT,
KEY(c1), KEY(c2), KEY(c2,c1),
KEY(c3), KEY(c3,c1), KEY(c3,c2), KEY(c3,c2,c1),
KEY(c4), KEY(c4,c1), KEY(c4,c2), KEY(c4,c2,c1),
KEY(c4,c3), KEY(c4,c3,c1), KEY(c4,c3,c2), KEY(c4,c3,c2,c1)) ENGINE=InnoDB;
SET DEBUG_DBUG='+d,row_drop_table_add_to_background';
DROP TABLE t;
CREATE TABLE t (a INT) ENGINE=InnoDB;
DROP TABLE t;
30 changes: 30 additions & 0 deletions mysql-test/suite/innodb/t/drop_table_background.test
@@ -0,0 +1,30 @@
--source include/have_innodb.inc
--source include/have_debug.inc
# Embedded server does not support restarting
--source include/not_embedded.inc

CREATE TABLE t(c0 SERIAL, c1 INT, c2 INT, c3 INT, c4 INT,
KEY(c1), KEY(c2), KEY(c2,c1),
KEY(c3), KEY(c3,c1), KEY(c3,c2), KEY(c3,c2,c1),
KEY(c4), KEY(c4,c1), KEY(c4,c2), KEY(c4,c2,c1),
KEY(c4,c3), KEY(c4,c3,c1), KEY(c4,c3,c2), KEY(c4,c3,c2,c1)) ENGINE=InnoDB;

let $n= 10;

SET DEBUG_DBUG='+d,row_drop_table_add_to_background';
--disable_query_log
let $i= $n;
while ($i) {
eval CREATE TABLE t$i LIKE t;
dec $i;
}
let $i= $n;
while ($i) {
eval DROP TABLE t$i;
dec $i;
}
--enable_query_log
DROP TABLE t;
--source include/restart_mysqld.inc
CREATE TABLE t (a INT) ENGINE=InnoDB;
DROP TABLE t;
15 changes: 11 additions & 4 deletions sql/CMakeLists.txt
Expand Up @@ -60,15 +60,22 @@ SET_SOURCE_FILES_PROPERTIES(${GEN_SOURCES}

# Gen_lex_token
# Make sure sql_yacc.h is generated before compiling gen_lex_token

IF(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
SET(DEPENDS_gen_lex_token DEPENDS gen_lex_token)
SET(DEPENDS_gen_lex_hash DEPENDS gen_lex_hash)
ENDIF()


IF(NOT CMAKE_CROSSCOMPILING)
ADD_EXECUTABLE(gen_lex_token gen_lex_token.cc)
ADD_DEPENDENCIES(gen_lex_token GenServerSource)
ADD_EXECUTABLE(gen_lex_token gen_lex_token.cc
${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.h)
ENDIF()

ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lex_token.h
COMMAND gen_lex_token > lex_token.h
DEPENDS gen_lex_token
${DEPENDS_gen_lex_token}
)

ADD_DEFINITIONS(-DMYSQL_SERVER -DHAVE_EVENT_SCHEDULER)
Expand Down Expand Up @@ -323,7 +330,7 @@ ENDIF()
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lex_hash.h
COMMAND gen_lex_hash > lex_hash.h
DEPENDS gen_lex_hash
${DEPENDS_gen_lex_hash}
)

MYSQL_ADD_EXECUTABLE(mysql_tzinfo_to_sql tztime.cc COMPONENT Server)
Expand Down
147 changes: 59 additions & 88 deletions storage/innobase/srv/srv0srv.cc
Expand Up @@ -1835,7 +1835,7 @@ DECLARE_THREAD(srv_monitor_thread)(void*)
}
}

if (srv_shutdown_state >= SRV_SHUTDOWN_CLEANUP) {
if (srv_shutdown_state != SRV_SHUTDOWN_NONE) {
goto exit_func;
}

Expand Down Expand Up @@ -1973,7 +1973,7 @@ DECLARE_THREAD(srv_error_monitor_thread)(void*)

os_event_wait_time_low(srv_error_event, 1000000, sig_count);

if (srv_shutdown_state < SRV_SHUTDOWN_CLEANUP) {
if (srv_shutdown_state == SRV_SHUTDOWN_NONE) {

goto loop;
}
Expand Down Expand Up @@ -2199,7 +2199,7 @@ srv_shutdown_print_master_pending(
time_elapsed = ut_difftime(current_time, *last_print_time);

if (time_elapsed > 60) {
*last_print_time = ut_time();
*last_print_time = current_time;

if (n_tables_to_drop) {
ut_print_timestamp(stderr);
Expand Down Expand Up @@ -2252,7 +2252,7 @@ srv_master_do_active_tasks(void)
MONITOR_INC_TIME_IN_MICRO_SECS(
MONITOR_SRV_BACKGROUND_DROP_TABLE_MICROSECOND, counter_time);

if (srv_shutdown_state > 0) {
if (srv_shutdown_state != SRV_SHUTDOWN_NONE) {
return;
}

Expand Down Expand Up @@ -2286,11 +2286,7 @@ srv_master_do_active_tasks(void)
MONITOR_SRV_MEM_VALIDATE_MICROSECOND, counter_time);
}
#endif
if (srv_shutdown_state > 0) {
return;
}

if (srv_shutdown_state > 0) {
if (srv_shutdown_state != SRV_SHUTDOWN_NONE) {
return;
}

Expand All @@ -2303,7 +2299,7 @@ srv_master_do_active_tasks(void)
MONITOR_SRV_DICT_LRU_MICROSECOND, counter_time);
}

if (srv_shutdown_state > 0) {
if (srv_shutdown_state != SRV_SHUTDOWN_NONE) {
return;
}

Expand Down Expand Up @@ -2347,7 +2343,7 @@ srv_master_do_idle_tasks(void)
MONITOR_SRV_BACKGROUND_DROP_TABLE_MICROSECOND,
counter_time);

if (srv_shutdown_state > 0) {
if (srv_shutdown_state != SRV_SHUTDOWN_NONE) {
return;
}

Expand All @@ -2363,7 +2359,7 @@ srv_master_do_idle_tasks(void)
MONITOR_INC_TIME_IN_MICRO_SECS(
MONITOR_SRV_IBUF_MERGE_MICROSECOND, counter_time);

if (srv_shutdown_state > 0) {
if (srv_shutdown_state != SRV_SHUTDOWN_NONE) {
return;
}

Expand All @@ -2379,7 +2375,7 @@ srv_master_do_idle_tasks(void)
MONITOR_INC_TIME_IN_MICRO_SECS(
MONITOR_SRV_LOG_FLUSH_MICROSECOND, counter_time);

if (srv_shutdown_state > 0) {
if (srv_shutdown_state != SRV_SHUTDOWN_NONE) {
return;
}

Expand All @@ -2390,70 +2386,42 @@ srv_master_do_idle_tasks(void)
counter_time);
}

/*********************************************************************//**
Perform the tasks during shutdown. The tasks that we do at shutdown
depend on srv_fast_shutdown:
2 => very fast shutdown => do no book keeping
1 => normal shutdown => clear drop table queue and make checkpoint
0 => slow shutdown => in addition to above do complete purge and ibuf
merge
@return TRUE if some work was done. FALSE otherwise */
/** Perform shutdown tasks.
@param[in] ibuf_merge whether to complete the change buffer merge */
static
ibool
srv_master_do_shutdown_tasks(
/*=========================*/
ib_time_t* last_print_time)/*!< last time the function
print the message */
void
srv_shutdown(bool ibuf_merge)
{
ulint n_bytes_merged = 0;
ulint n_tables_to_drop = 0;

ut_ad(!srv_read_only_mode);

++srv_main_shutdown_loops;

ut_a(srv_shutdown_state > 0);

/* In very fast shutdown none of the following is necessary */
if (srv_fast_shutdown == 2) {
return(FALSE);
}

/* ALTER TABLE in MySQL requires on Unix that the table handler
can drop tables lazily after there no longer are SELECT
queries to them. */
srv_main_thread_op_info = "doing background drop tables";
n_tables_to_drop = row_drop_tables_for_mysql_in_background();

/* make sure that there is enough reusable space in the redo
log files */
srv_main_thread_op_info = "checking free log space";
log_free_check();
ulint n_bytes_merged = 0;
ulint n_tables_to_drop;
ib_time_t now = ut_time();

/* In case of normal shutdown we don't do ibuf merge or purge */
if (srv_fast_shutdown == 1) {
goto func_exit;
}

/* Do an ibuf merge */
srv_main_thread_op_info = "doing insert buffer merge";
n_bytes_merged = ibuf_merge_in_background(true);

/* Flush logs if needed */
srv_sync_log_buffer_in_background();

func_exit:
/* Make a new checkpoint about once in 10 seconds */
srv_main_thread_op_info = "making checkpoint";
log_checkpoint(TRUE, FALSE);

/* Print progress message every 60 seconds during shutdown */
if (srv_shutdown_state > 0 && srv_print_verbose_log) {
srv_shutdown_print_master_pending(
last_print_time, n_tables_to_drop, n_bytes_merged);
}
do {
ut_ad(!srv_read_only_mode);
ut_ad(srv_shutdown_state == SRV_SHUTDOWN_CLEANUP);
++srv_main_shutdown_loops;

/* FIXME: Remove the background DROP TABLE queue; it is not
crash-safe and breaks ACID. */
srv_main_thread_op_info = "doing background drop tables";
n_tables_to_drop = row_drop_tables_for_mysql_in_background();

if (ibuf_merge) {
srv_main_thread_op_info = "checking free log space";
log_free_check();
srv_main_thread_op_info = "doing insert buffer merge";
n_bytes_merged = ibuf_merge_in_background(true);

/* Flush logs if needed */
srv_sync_log_buffer_in_background();
}

return(n_bytes_merged || n_tables_to_drop);
/* Print progress message every 60 seconds during shutdown */
if (srv_print_verbose_log) {
srv_shutdown_print_master_pending(
&now, n_tables_to_drop, n_bytes_merged);
}
} while (n_bytes_merged || n_tables_to_drop);
}

/*********************************************************************//**
Expand Down Expand Up @@ -2485,7 +2453,6 @@ DECLARE_THREAD(srv_master_thread)(

srv_slot_t* slot;
ulint old_activity_count = srv_get_activity_count();
ib_time_t last_print_time;

ut_ad(!srv_read_only_mode);

Expand All @@ -2504,7 +2471,6 @@ DECLARE_THREAD(srv_master_thread)(
slot = srv_reserve_slot(SRV_MASTER);
ut_a(slot == srv_sys.sys_threads);

last_print_time = ut_time();
loop:
if (srv_force_recovery >= SRV_FORCE_NO_BACKGROUND) {
goto suspend_thread;
Expand All @@ -2524,13 +2490,26 @@ DECLARE_THREAD(srv_master_thread)(
}
}

while (srv_master_do_shutdown_tasks(&last_print_time)) {

/* Shouldn't loop here in case of very fast shutdown */
ut_ad(srv_fast_shutdown < 2);
suspend_thread:
switch (srv_shutdown_state) {
case SRV_SHUTDOWN_NONE:
break;
case SRV_SHUTDOWN_FLUSH_PHASE:
case SRV_SHUTDOWN_LAST_PHASE:
ut_ad(0);
/* fall through */
case SRV_SHUTDOWN_EXIT_THREADS:
/* srv_init_abort() must have been invoked */
case SRV_SHUTDOWN_CLEANUP:
if (srv_shutdown_state == SRV_SHUTDOWN_CLEANUP
&& srv_fast_shutdown < 2) {
srv_shutdown(srv_fast_shutdown == 1);
}
srv_suspend_thread(slot);
my_thread_end();
os_thread_exit(NULL);
}

suspend_thread:
srv_main_thread_op_info = "suspending";

srv_suspend_thread(slot);
Expand All @@ -2542,15 +2521,7 @@ DECLARE_THREAD(srv_master_thread)(
srv_main_thread_op_info = "waiting for server activity";

srv_resume_thread(slot);

if (srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS) {
my_thread_end();
os_thread_exit(NULL);
}

goto loop;

OS_THREAD_DUMMY_RETURN; /* Not reached, avoid compiler warning */
}

/*********************************************************************//**
Expand Down

0 comments on commit 4abc2dd

Please sign in to comment.