Skip to content
Permalink
Browse files
Merge 10.1 into 10.2
  • Loading branch information
dr-m committed Jun 6, 2018
2 parents 738c5c8 + 1d4e1d3 commit df42830
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 566 deletions.
@@ -1,4 +1,4 @@
call mtr.add_suppression("InnoDB: The log sequence numbers [0-9]+ and [0-9]+ in ibdata files do not match the log sequence number [0-9]+ in the ib_logfiles!");
FLUSH TABLES;
CREATE TABLE t1 (a INT PRIMARY KEY, b TEXT) ENGINE=InnoDB;
CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t3 (a INT PRIMARY KEY, b TEXT, c TEXT) ENGINE=InnoDB;
@@ -1,6 +1,13 @@
SET @innodb_defragment_orig=@@GLOBAL.innodb_defragment;
SET @innodb_optimize_fulltext_orig=@@GLOBAL.innodb_optimize_fulltext_only;
SET GLOBAL innodb_defragment = 1;
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256), KEY(a, b)) ENGINE=INNODB;
SET GLOBAL innodb_optimize_fulltext_only = 0;
#
# MDEV-12198 innodb_defragment=1 crashes server on
# OPTIMIZE TABLE when FULLTEXT index exists
#
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256),
KEY(a, b), FULLTEXT KEY(b)) ENGINE=INNODB;
OPTIMIZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
@@ -11,12 +18,15 @@ INSERT INTO t1 VALUES (400000, REPEAT('A', 256));
OPTIMIZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
DROP TABLE t1;
#
# MDEV-12198 innodb_defragment=1 crashes server on
# OPTIMIZE TABLE when FULLTEXT index exists
# MDEV-15824 innodb_defragment=ON trumps
# innodb_optimize_fulltext_only=ON in OPTIMIZE TABLE
#
CREATE TABLE t1 (c TEXT, FULLTEXT KEY (c)) ENGINE=InnoDB;
SET GLOBAL innodb_optimize_fulltext_only = 1;
OPTIMIZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
SET GLOBAL innodb_defragment = 0;
OPTIMIZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
@@ -27,3 +37,4 @@ Table Op Msg_type Msg_text
test.t1 optimize status OK
DROP TABLE t1;
SET GLOBAL innodb_defragment = @innodb_defragment_orig;
SET GLOBAL innodb_optimize_fulltext_only = @innodb_optimize_fulltext_orig;
@@ -6,13 +6,13 @@
# The 7000 in this test is a bit less than half the innodb_page_size.
--source include/have_innodb_16k.inc

# DEBUG_SYNC must be compiled in.
--source include/have_debug.inc
--source include/have_debug_sync.inc

# Embedded server does not support restarting
--source include/not_embedded.inc

call mtr.add_suppression("InnoDB: The log sequence numbers [0-9]+ and [0-9]+ in ibdata files do not match the log sequence number [0-9]+ in the ib_logfiles!");
FLUSH TABLES;

CREATE TABLE t1 (a INT PRIMARY KEY, b TEXT) ENGINE=InnoDB;
CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
@@ -1,10 +1,17 @@
--source include/have_innodb.inc

SET @innodb_defragment_orig=@@GLOBAL.innodb_defragment;
SET @innodb_optimize_fulltext_orig=@@GLOBAL.innodb_optimize_fulltext_only;
SET GLOBAL innodb_defragment = 1;
SET GLOBAL innodb_optimize_fulltext_only = 0;

# Small tests copied from innodb.innodb_defragment
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256), KEY(a, b)) ENGINE=INNODB;
--echo #
--echo # MDEV-12198 innodb_defragment=1 crashes server on
--echo # OPTIMIZE TABLE when FULLTEXT index exists
--echo #

CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256),
KEY(a, b), FULLTEXT KEY(b)) ENGINE=INNODB;
OPTIMIZE TABLE t1;

INSERT INTO t1 VALUES (100000, REPEAT('A', 256));
@@ -13,20 +20,22 @@ INSERT INTO t1 VALUES (300000, REPEAT('A', 256));
INSERT INTO t1 VALUES (400000, REPEAT('A', 256));

OPTIMIZE TABLE t1;
DROP TABLE t1;

--echo #
--echo # MDEV-12198 innodb_defragment=1 crashes server on
--echo # OPTIMIZE TABLE when FULLTEXT index exists
--echo # MDEV-15824 innodb_defragment=ON trumps
--echo # innodb_optimize_fulltext_only=ON in OPTIMIZE TABLE
--echo #

CREATE TABLE t1 (c TEXT, FULLTEXT KEY (c)) ENGINE=InnoDB;

SET GLOBAL innodb_optimize_fulltext_only = 1;
OPTIMIZE TABLE t1;
SET GLOBAL innodb_defragment = 0;
OPTIMIZE TABLE t1;

DROP TABLE t1;

CREATE TABLE t1 (c POINT PRIMARY KEY, SPATIAL INDEX(c)) ENGINE=InnoDB;
OPTIMIZE TABLE t1;
DROP TABLE t1;

SET GLOBAL innodb_defragment = @innodb_defragment_orig;
SET GLOBAL innodb_optimize_fulltext_only = @innodb_optimize_fulltext_orig;
@@ -40,57 +40,6 @@ Modified 30/07/2014 Jan Lindström jan.lindstrom@mariadb.com

#include <list>

/**************************************************//**
Custom nullptr implementation for under g++ 4.6
*******************************************************/
// #pragma once
/*
namespace std
{
// based on SC22/WG21/N2431 = J16/07-0301
struct nullptr_t
{
template<typename any> operator any * () const
{
return 0;
}
template<class any, typename T> operator T any:: * () const
{
return 0;
}
#ifdef _MSC_VER
struct pad {};
pad __[sizeof(void*)/sizeof(pad)];
#else
char __[sizeof(void*)];
#endif
private:
// nullptr_t();// {}
// nullptr_t(const nullptr_t&);
// void operator = (const nullptr_t&);
void operator &() const;
template<typename any> void operator +(any) const
{
// I Love MSVC 2005!
}
template<typename any> void operator -(any) const
{
// I Love MSVC 2005!
}
};
static const nullptr_t __nullptr = {};
}
#ifndef nullptr
#define nullptr std::__nullptr
#endif
*/

/**************************************************//**
End of Custom nullptr implementation for under g++ 4.6
*******************************************************/

/* When there's no work, either because defragment is disabled, or because no
query is submitted, thread checks state every BTR_DEFRAGMENT_SLEEP_IN_USECS.*/
#define BTR_DEFRAGMENT_SLEEP_IN_USECS 1000000
@@ -1140,7 +1140,7 @@ fil_mutex_enter_and_prepare_for_io(
/*===============================*/
ulint space_id) /*!< in: space id */
{
for (ulint count = 0, count2 = 0;;) {
for (ulint count = 0;;) {
mutex_enter(&fil_system->mutex);

if (space_id >= SRV_LOG_SPACE_FIRST_ID) {
@@ -1154,41 +1154,6 @@ fil_mutex_enter_and_prepare_for_io(
break;
}

if (space->stop_ios) {
ut_ad(space->id != 0);
/* We are going to do a rename file and want to stop
new i/o's for a while. */

if (count2 > 20000) {
ib::warn() << "Tablespace " << space->name
<< " has i/o ops stopped for a long"
" time " << count2;
}

mutex_exit(&fil_system->mutex);

/* Wake the i/o-handler threads to make sure pending
i/o's are performed */
os_aio_simulated_wake_handler_threads();

/* The sleep here is just to give IO helper threads a
bit of time to do some work. It is not required that
all IO related to the tablespace being renamed must
be flushed here as we do fil_flush() in
fil_rename_tablespace() as well. */
os_thread_sleep(20000);

/* Flush tablespaces so that we can close modified
files in the LRU list */
fil_flush_file_spaces(FIL_TYPE_TABLESPACE);

os_thread_sleep(20000);

count2++;

continue;
}

fil_node_t* node = UT_LIST_GET_LAST(space->chain);
ut_ad(space->id == 0
|| node == UT_LIST_GET_FIRST(space->chain));
@@ -3497,31 +3462,16 @@ fil_rename_tablespace(
const char* new_name,
const char* new_path_in)
{
bool sleep = false;
bool flush = false;
fil_space_t* space;
fil_node_t* node;
ulint count = 0;
ut_a(id != 0);

ut_ad(strchr(new_name, '/') != NULL);
retry:
count++;

if (!(count % 1000)) {
ib::warn() << "Cannot rename file " << old_path
<< " (space id " << id << "), retried " << count
<< " times."
" There are either pending IOs or flushes or"
" the file is being extended.";
}

mutex_enter(&fil_system->mutex);

space = fil_space_get_by_id(id);

DBUG_EXECUTE_IF("fil_rename_tablespace_failure_1", space = NULL; );

if (space == NULL) {
ib::error() << "Cannot find space id " << id
<< " in the tablespace memory cache, though the file '"
@@ -3532,64 +3482,26 @@ fil_rename_tablespace(
return(false);
}

if (count > 25000) {
space->stop_ios = false;
goto func_exit;
}
if (space != fil_space_get_by_name(space->name)) {
ib::error() << "Cannot find " << space->name
<< " in tablespace memory cache";
space->stop_ios = false;
goto func_exit;
}

if (fil_space_get_by_name(new_name)) {
ib::error() << new_name
<< " is already in tablespace memory cache";
space->stop_ios = false;
goto func_exit;
}

/* We temporarily close the .ibd file because we do not trust that
operating systems can rename an open file. For the closing we have to
wait until there are no pending i/o's or flushes on the file. */

space->stop_ios = true;

/* The following code must change when InnoDB supports
multiple datafiles per tablespace. */
ut_a(UT_LIST_GET_LEN(space->chain) == 1);
node = UT_LIST_GET_FIRST(space->chain);

if (node->n_pending > 0
|| node->n_pending_flushes > 0
|| node->being_extended) {
/* There are pending i/o's or flushes or the file is
currently being extended, sleep for a while and
retry */
sleep = true;
} else if (node->modification_counter > node->flush_counter) {
/* Flush the space */
sleep = flush = true;
} else if (node->is_open()) {
/* Close the file */

fil_node_close_file(node);
}
space->n_pending_ops++;

mutex_exit(&fil_system->mutex);

if (sleep) {
os_thread_sleep(20000);

if (flush) {
fil_flush(id);
}

sleep = flush = false;
goto retry;
}
ut_ad(space->stop_ios);
char* new_file_name = new_path_in == NULL
? fil_make_filepath(NULL, new_name, IBD, false)
: mem_strdup(new_path_in);
@@ -3615,23 +3527,17 @@ fil_rename_tablespace(
/* log_sys->mutex is above fil_system->mutex in the latching order */
ut_ad(log_mutex_own());
mutex_enter(&fil_system->mutex);
ut_ad(space->n_pending_ops);
space->n_pending_ops--;
ut_ad(space->name == old_space_name);
/* We already checked these. */
ut_ad(space == fil_space_get_by_name(old_space_name));
ut_ad(!fil_space_get_by_name(new_space_name));
ut_ad(node->name == old_file_name);

bool success;

DBUG_EXECUTE_IF("fil_rename_tablespace_failure_2",
goto skip_rename; );

success = os_file_rename(
bool success = os_file_rename(
innodb_data_file_key, old_file_name, new_file_name);

DBUG_EXECUTE_IF("fil_rename_tablespace_failure_2",
skip_rename: success = false; );

ut_ad(node->name == old_file_name);

if (success) {
@@ -3656,8 +3562,6 @@ fil_rename_tablespace(
old_space_name = new_space_name;
}

ut_ad(space->stop_ios);
space->stop_ios = false;
mutex_exit(&fil_system->mutex);

ut_free(old_file_name);
@@ -14626,6 +14626,7 @@ ha_innobase::optimize(

This works OK otherwise, but MySQL locks the entire table during
calls to OPTIMIZE, which is undesirable. */
bool try_alter = true;

/* TODO: Defragment is disabled for now */
if (srv_defragment) {
@@ -14634,17 +14635,15 @@ ha_innobase::optimize(
err = defragment_table(m_prebuilt->table->name.m_name, NULL, false);

if (err == 0) {
return (HA_ADMIN_OK);
try_alter = false;
} else {
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
err,
"InnoDB: Cannot defragment table %s: returned error code %d\n",
m_prebuilt->table->name, err);

if (err == ER_SP_ALREADY_EXISTS) {
return (HA_ADMIN_OK);
} else {
return (HA_ADMIN_TRY_ALTER);
if(err == ER_SP_ALREADY_EXISTS) {
try_alter = false;
}
}
}
@@ -14655,11 +14654,10 @@ ha_innobase::optimize(
fts_sync_table(m_prebuilt->table, false, true, false);
fts_optimize_table(m_prebuilt->table);
}
return(HA_ADMIN_OK);
} else {

return(HA_ADMIN_TRY_ALTER);
try_alter = false;
}

return try_alter ? HA_ADMIN_TRY_ALTER : HA_ADMIN_OK;
}

/*******************************************************************//**

0 comments on commit df42830

Please sign in to comment.