| 1 |
--source include/have_debug.inc |
| 2 |
--source include/have_debug_sync.inc |
| 3 |
--source suite/federated/include/federated.inc |
| 4 |
--enable_connect_log |
| 5 |
|
| 6 |
--echo ########################################################### |
| 7 |
--echo # |
| 8 |
--echo # Test cases for wl#7593: Don't hold LOCK_open... |
| 9 |
--echo # |
| 10 |
--echo # Most of the tests related to this wl are in a different |
| 11 |
--echo # test file main.get_table_share.test. One scenario is relevant |
| 12 |
--echo # for the federated storage engine, which is why it is put into |
| 13 |
--echo # this file. |
| 14 |
--echo # |
| 15 |
--echo # This test case is based on two threads: One thread master |
| 16 |
--echo # opening table tb, being paused while opening the share, |
| 17 |
--echo # while another thread issues a ALTER and DROP SERVER commands |
| 18 |
--echo # to make sure the tables related to the dropped server are |
| 19 |
--echo # being closed. |
| 20 |
--echo # |
| 21 |
--echo # Please note that the include files federated.inc and |
| 22 |
--echo # federated_cleanup.inc creates an cleans up various resources |
| 23 |
--echo # related to the federated engine (connections, schemas, etc). |
| 24 |
--echo # |
| 25 |
|
| 26 |
--echo # |
| 27 |
--connection slave |
| 28 |
--echo # Create a database and the tables on the slave: |
| 29 |
CREATE DATABASE new_federated; |
| 30 |
CREATE TABLE federated.ta (pk integer primary key); |
| 31 |
CREATE TABLE federated.tb (pk integer primary key); |
| 32 |
CREATE TABLE new_federated.ta (pk integer primary key); |
| 33 |
CREATE TABLE new_federated.tb (pk integer primary key); |
| 34 |
|
| 35 |
--echo # |
| 36 |
--connection master |
| 37 |
--echo # Create one server and two local, federated tables on the master: |
| 38 |
--replace_result $SLAVE_MYPORT SLAVE_PORT |
| 39 |
eval CREATE SERVER s FOREIGN DATA WRAPPER 'mysql' OPTIONS |
| 40 |
(USER 'root', HOST '127.0.0.1', PORT $SLAVE_MYPORT, DATABASE 'federated'); |
| 41 |
CREATE TABLE federated.ta (pk integer primary key) |
| 42 |
ENGINE= FEDERATED CONNECTION= 's'; |
| 43 |
CREATE TABLE federated.tb (pk integer primary key) |
| 44 |
ENGINE= FEDERATED CONNECTION= 's'; |
| 45 |
|
| 46 |
--echo # |
| 47 |
--echo # Check that the server is created, and do an insert into ta to make |
| 48 |
--echo # sure it is open and in the cache, then show open federated tables: |
| 49 |
--replace_result $SLAVE_MYPORT SLAVE_PORT |
| 50 |
SELECT * from mysql.servers; |
| 51 |
INSERT INTO federated.ta VALUES(0); |
| 52 |
SELECT * from federated.ta; |
| 53 |
SHOW OPEN TABLES IN federated; |
| 54 |
|
| 55 |
--echo # |
| 56 |
--echo # Wait after releasing LOCK_open for tb, and make sure we never |
| 57 |
--echo # end up at the 'found_share' sync point: |
| 58 |
SET DEBUG_SYNC= 'get_share_before_open SIGNAL open_master WAIT_FOR cont_master'; |
| 59 |
SET DEBUG_SYNC= 'get_share_found_share HIT_LIMIT 1'; |
| 60 |
--send INSERT INTO federated.tb VALUES(1) |
| 61 |
|
| 62 |
--echo # |
| 63 |
--connection default |
| 64 |
--echo # Wait for open_master, then issue an ALTER SERVER command, which will |
| 65 |
--echo # close the tables for the server being altered. The table ta is open, |
| 66 |
--echo # and will be closed, while tb is in the process of being opened, and |
| 67 |
--echo # will therefore be skipped (i.e. not closed): |
| 68 |
SET DEBUG_SYNC= 'now WAIT_FOR open_master'; |
| 69 |
ALTER SERVER s OPTIONS (DATABASE 'new_federated'); |
| 70 |
|
| 71 |
--echo # |
| 72 |
--echo # Then, we show open federated tables to verify that neither tb nor |
| 73 |
--echo # ta are open, then we let the master open the tb share and insert, |
| 74 |
--echo # then we reap the master to be sure it is done with the insert: |
| 75 |
SHOW OPEN TABLES IN federated; |
| 76 |
SET DEBUG_SYNC= 'now SIGNAL cont_master'; |
| 77 |
--connection master |
| 78 |
--reap |
| 79 |
|
| 80 |
--echo # |
| 81 |
--connection default |
| 82 |
--echo # Now, tb should be open: |
| 83 |
SHOW OPEN TABLES IN federated; |
| 84 |
|
| 85 |
--echo # |
| 86 |
--echo # A select from tb will show the inserted data since the |
| 87 |
--echo # actual server information from after the ALTER SERVER is used |
| 88 |
--echo # to open the table: |
| 89 |
SELECT * from federated.tb; |
| 90 |
|
| 91 |
--echo # |
| 92 |
--echo # A select from ta will now be empty since we switched |
| 93 |
--echo # remote table: |
| 94 |
SELECT * from federated.ta; |
| 95 |
|
| 96 |
--echo # |
| 97 |
--echo # Now, both ta and tb should be open: |
| 98 |
--sorted_result |
| 99 |
SHOW OPEN TABLES IN federated; |
| 100 |
|
| 101 |
--echo # |
| 102 |
--connection master |
| 103 |
--echo # Back to the master, we flush table tb and do a new insert, |
| 104 |
--echo # pausing before opening the share, just like we did above: |
| 105 |
FLUSH TABLE federated.tb; |
| 106 |
SHOW OPEN TABLES IN federated; |
| 107 |
SET DEBUG_SYNC= 'get_share_before_open SIGNAL open_master WAIT_FOR cont_master'; |
| 108 |
SET DEBUG_SYNC= 'get_share_found_share HIT_LIMIT 1'; |
| 109 |
--send INSERT INTO federated.tb VALUES(2) |
| 110 |
|
| 111 |
--echo # |
| 112 |
--connection default |
| 113 |
--echo # Wait for open_master, then issue a DROP SERVER command: |
| 114 |
SET DEBUG_SYNC= 'now WAIT_FOR open_master'; |
| 115 |
DROP SERVER s; |
| 116 |
|
| 117 |
--echo # |
| 118 |
--echo # Let the master finish opening the tb share, and then reap it, which |
| 119 |
--echo # will fail since the server has been deleted: |
| 120 |
SET DEBUG_SYNC= 'now SIGNAL cont_master'; |
| 121 |
--connection master |
| 122 |
--error ER_FOREIGN_DATA_STRING_INVALID_CANT_CREATE |
| 123 |
--reap |
| 124 |
# Not resetting DEBUG_SYNC for "master" was resulting in failure of subsequent |
| 125 |
# statement execution. |
| 126 |
# Reason is, when table_open_cache_instances <> 1 then tables accessed including |
| 127 |
# mysql.* may not exists in the table open cache instance of "master". So while |
| 128 |
# opening those tables DEBUG_SYNC='get_share_found_share HIT_LIMIT 1' was hit |
| 129 |
# more than once and subsequent statements execution was failing. |
| 130 |
# This worked well with table_open_cache_instances=1 as tables opened by other |
| 131 |
# connections also exists in the single cache. |
| 132 |
SET DEBUG_SYNC= 'RESET'; |
| 133 |
|
| 134 |
--echo # |
| 135 |
--connection default |
| 136 |
--echo # Then, we show open tables to verify that tb is left opened, |
| 137 |
--echo # while ta is not open anymore: |
| 138 |
SHOW OPEN TABLES IN federated; |
| 139 |
|
| 140 |
--echo # |
| 141 |
--connection slave |
| 142 |
--echo # Drop remote tables and database: |
| 143 |
DROP TABLE federated.ta, federated.tb; |
| 144 |
DROP TABLE new_federated.ta, new_federated.tb; |
| 145 |
DROP DATABASE new_federated; |
| 146 |
|
| 147 |
--echo # |
| 148 |
--connection default |
| 149 |
--echo # Reset DEBUG_SYNC and drop local tables: |
| 150 |
SET DEBUG_SYNC= 'RESET'; |
| 151 |
DROP TABLE federated.ta, federated.tb; |
| 152 |
|
| 153 |
--echo # |
| 154 |
--echo # Disconnecting slave and master is handled in federated_cleanup.inc |
| 155 |
--disable_connect_log |
| 156 |
--source suite/federated/include/federated_cleanup.inc |