Skip to content

Commit

Permalink
Merge 10.1 into 10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed May 10, 2019
2 parents 136a27d + 3e8cab5 commit b2f3755
Show file tree
Hide file tree
Showing 41 changed files with 851 additions and 986 deletions.
24 changes: 24 additions & 0 deletions mysql-test/suite/innodb/r/foreign-keys.result
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ CREATE TABLE t2 (b INT, KEY(b)) ENGINE=InnoDB;
INSERT INTO t2 VALUES(2);
ALTER TABLE t2 ADD FOREIGN KEY(b) REFERENCES t1(a), LOCK=EXCLUSIVE;
DROP TABLE t2, t1;
#
# MDEV-16060 - InnoDB: Failing assertion: ut_strcmp(index->name, key->name)
#
CREATE TABLE t1 (`pk` INT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t2 LIKE t1;
FLUSH TABLES;
SET debug_sync='alter_table_intermediate_table_created SIGNAL ready WAIT_FOR go';
ALTER TABLE t1 ADD FOREIGN KEY(pk) REFERENCES t2(pk) ON UPDATE CASCADE;
connect con1, localhost, root;
SET debug_sync='now WAIT_FOR ready';
SET lock_wait_timeout=1;
UPDATE t2 SET pk=10 WHERE pk=1;
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
PREPARE stmt FROM 'UPDATE t2 SET pk=10 WHERE pk=1';
DEALLOCATE PREPARE stmt;
FLUSH TABLE t2;
SET debug_sync='now SIGNAL go';
connection default;
disconnect con1;
connection default;
SET debug_sync='reset';
SHOW OPEN TABLES FROM test;
Database Table In_use Name_locked
DROP TABLE t1, t2;
create table t1 (a int primary key, b int) engine=innodb;
create table t2 (c int primary key, d int,
foreign key (d) references t1 (a) on update cascade) engine=innodb;
Expand Down
32 changes: 32 additions & 0 deletions mysql-test/suite/innodb/t/foreign-keys.test
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,38 @@ INSERT INTO t2 VALUES(2);
ALTER TABLE t2 ADD FOREIGN KEY(b) REFERENCES t1(a), LOCK=EXCLUSIVE;
DROP TABLE t2, t1;


--echo #
--echo # MDEV-16060 - InnoDB: Failing assertion: ut_strcmp(index->name, key->name)
--echo #
CREATE TABLE t1 (`pk` INT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t2 LIKE t1;
FLUSH TABLES;

SET debug_sync='alter_table_intermediate_table_created SIGNAL ready WAIT_FOR go';
send ALTER TABLE t1 ADD FOREIGN KEY(pk) REFERENCES t2(pk) ON UPDATE CASCADE;

connect con1, localhost, root;
SET debug_sync='now WAIT_FOR ready';
SET lock_wait_timeout=1; # change to 0 in 10.3
--error ER_LOCK_WAIT_TIMEOUT
UPDATE t2 SET pk=10 WHERE pk=1;
PREPARE stmt FROM 'UPDATE t2 SET pk=10 WHERE pk=1';
DEALLOCATE PREPARE stmt;
FLUSH TABLE t2;
SET debug_sync='now SIGNAL go';

connection default;
reap;

# Cleanup
disconnect con1;

connection default;
SET debug_sync='reset';
SHOW OPEN TABLES FROM test;
DROP TABLE t1, t2;

#
# FK and prelocking:
# child table accesses (reads and writes) wait for locks.
Expand Down
3 changes: 2 additions & 1 deletion sql/mysql_upgrade_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ static void die(const char *fmt, ...)

#define WRITE_LOG(fmt,...) {\
char log_buf[1024]; \
DWORD nbytes; \
snprintf(log_buf,sizeof(log_buf), fmt, __VA_ARGS__);\
WriteFile(logfile_handle,log_buf, strlen(log_buf), 0 , 0);\
WriteFile(logfile_handle,log_buf, strlen(log_buf), &nbytes , 0);\
}

/*
Expand Down
2 changes: 1 addition & 1 deletion sql/mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
#define OPT_SESSION SHOW_OPT_SESSION
#define OPT_GLOBAL SHOW_OPT_GLOBAL

extern MY_TIMER_INFO sys_timer_info;
extern MYSQL_PLUGIN_IMPORT MY_TIMER_INFO sys_timer_info;

/*
Values for --slave-parallel-mode
Expand Down
95 changes: 46 additions & 49 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2016, Oracle and/or its affiliates.
Copyright (c) 2010, 2018, MariaDB
Copyright (c) 2010, 2019, MariaDB
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
Expand Down Expand Up @@ -8504,6 +8504,50 @@ static bool fk_prepare_copy_alter_table(THD *thd, TABLE *table,
}
}

/*
Normally, an attempt to modify an FK parent table will cause
FK children to be prelocked, so the table-being-altered cannot
be modified by a cascade FK action, because ALTER holds a lock
and prelocking will wait.
But if a new FK is being added by this very ALTER, then the target
table is not locked yet (it's a temporary table). So, we have to
lock FK parents explicitly.
*/
if (alter_info->flags & Alter_info::ADD_FOREIGN_KEY)
{
List_iterator<Key> fk_list_it(alter_info->key_list);

while (Key *key= fk_list_it++)
{
if (key->type != Key::FOREIGN_KEY)
continue;

Foreign_key *fk= static_cast<Foreign_key*>(key);
char dbuf[NAME_LEN];
char tbuf[NAME_LEN];
const char *ref_db= fk->ref_db.str ? fk->ref_db.str : alter_ctx->new_db;
const char *ref_table= fk->ref_table.str;
MDL_request mdl_request;

if (lower_case_table_names)
{
strmake_buf(dbuf, ref_db);
my_casedn_str(system_charset_info, dbuf);
strmake_buf(tbuf, ref_table);
my_casedn_str(system_charset_info, tbuf);
ref_db= dbuf;
ref_table= tbuf;
}

mdl_request.init(MDL_key::TABLE, ref_db, ref_table, MDL_SHARED_NO_WRITE,
MDL_TRANSACTION);
if (thd->mdl_context.acquire_lock(&mdl_request,
thd->variables.lock_wait_timeout))
DBUG_RETURN(true);
}
}

DBUG_RETURN(false);
}

Expand Down Expand Up @@ -9504,6 +9548,7 @@ do_continue:;

/* Mark that we have created table in storage engine. */
no_ha_table= false;
DEBUG_SYNC(thd, "alter_table_intermediate_table_created");

new_table=
thd->create_and_open_tmp_table(new_db_type, &frm, alter_ctx.get_tmp_path(),
Expand All @@ -9517,54 +9562,6 @@ do_continue:;
/* in case of alter temp table send the tracker in OK packet */
SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL);
}
else
{
/*
Normally, an attempt to modify an FK parent table will cause
FK children to be prelocked, so the table-being-altered cannot
be modified by a cascade FK action, because ALTER holds a lock
and prelocking will wait.
But if a new FK is being added by this very ALTER, then the target
table is not locked yet (it's a temporary table). So, we have to
lock FK parents explicitly.
*/
if (alter_info->flags & Alter_info::ADD_FOREIGN_KEY)
{
List <FOREIGN_KEY_INFO> fk_list;
List_iterator<FOREIGN_KEY_INFO> fk_list_it(fk_list);
FOREIGN_KEY_INFO *fk;

/* tables_opened can be > 1 only for MERGE tables */
DBUG_ASSERT(tables_opened == 1);
DBUG_ASSERT(&table_list->next_global == thd->lex->query_tables_last);

new_table->file->get_foreign_key_list(thd, &fk_list);
while ((fk= fk_list_it++))
{
MDL_request mdl_request;

if (lower_case_table_names)
{
char buf[NAME_LEN];
uint len;
strmake_buf(buf, fk->referenced_db->str);
len = my_casedn_str(files_charset_info, buf);
thd->make_lex_string(fk->referenced_db, buf, len);
strmake_buf(buf, fk->referenced_table->str);
len = my_casedn_str(files_charset_info, buf);
thd->make_lex_string(fk->referenced_table, buf, len);
}

mdl_request.init(MDL_key::TABLE,
fk->referenced_db->str, fk->referenced_table->str,
MDL_SHARED_NO_WRITE, MDL_TRANSACTION);
if (thd->mdl_context.acquire_lock(&mdl_request,
thd->variables.lock_wait_timeout))
goto err_new_table_cleanup;
}
}
}

/*
Note: In case of MERGE table, we do not attach children. We do not
Expand Down
7 changes: 1 addition & 6 deletions storage/innobase/buf/buf0dblwr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -652,18 +652,13 @@ buf_dblwr_process()
ulint decomp = fil_page_decompress(buf, page);
if (!decomp || (decomp != srv_page_size
&& page_size.is_compressed())) {
goto bad_doublewrite;
continue;
}

if (expect_encrypted && mach_read_from_4(
page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION)
? !fil_space_verify_crypt_checksum(page, page_size)
: buf_page_is_corrupted(true, page, page_size, space)) {
if (!is_all_zero) {
bad_doublewrite:
ib::warn() << "A doublewrite copy of page "
<< page_id << " is corrupted.";
}
/* Theoretically we could have another good
copy for this page in the doublewrite
buffer. If not, we will report a fatal error
Expand Down
3 changes: 1 addition & 2 deletions storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2849,8 +2849,7 @@ but only by InnoDB table locks, which may be broken by
lock_remove_all_on_table().)
@param[in] table persistent table
checked @return whether the table is accessible */
bool
fil_table_accessible(const dict_table_t* table)
bool fil_table_accessible(const dict_table_t* table)
{
if (UNIV_UNLIKELY(!table->is_readable() || table->corrupted)) {
return(false);
Expand Down
9 changes: 6 additions & 3 deletions storage/innobase/fts/fts0config.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2007, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
Copyright (c) 2017, 2019, MariaDB Corporation.
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 the Free Software
Expand Down Expand Up @@ -215,8 +215,11 @@ fts_config_set_value(
pars_info_bind_varchar_literal(info, "value",
value->f_str, value->f_len);

const bool dict_locked = fts_table->table->fts->fts_status
& TABLE_DICT_LOCKED;

fts_table->suffix = "CONFIG";
fts_get_table_name(fts_table, table_name);
fts_get_table_name(fts_table, table_name, dict_locked);
pars_info_bind_id(info, true, "table_name", table_name);

graph = fts_parse_sql(
Expand Down Expand Up @@ -244,7 +247,7 @@ fts_config_set_value(
pars_info_bind_varchar_literal(
info, "value", value->f_str, value->f_len);

fts_get_table_name(fts_table, table_name);
fts_get_table_name(fts_table, table_name, dict_locked);
pars_info_bind_id(info, true, "table_name", table_name);

graph = fts_parse_sql(
Expand Down
Loading

0 comments on commit b2f3755

Please sign in to comment.