| 1 |
# include/socket_event.inc |
| 2 |
# |
| 3 |
# Auxiliary routine running |
| 4 |
# - some statement in connection con1 |
| 5 |
# or |
| 6 |
# - connect/disconnect |
| 7 |
# $loop_rounds times and checking if the changes to values caused by the action |
| 8 |
# are reasonable. |
| 9 |
# |
| 10 |
# Requirements: |
| 11 |
# 1. Have socket_summary_by_instance_func running |
| 12 |
# 2a. Have a connection con1 |
| 13 |
# @con1_object_instance_begin needs to be the OBJECT_INSTANCE_BEGIN |
| 14 |
# value of the "client_connction" entry belonging to con1 within |
| 15 |
# socket_summary_by_instance. |
| 16 |
# $statement needs to contain the statement to be executed by con1. |
| 17 |
# or |
| 18 |
# 2b. Have assigned values to the following variables |
| 19 |
# $connect_host $connect_db $connect_user |
| 20 |
# |
| 21 |
|
| 22 |
let $my_errno= 0; |
| 23 |
|
| 24 |
let $loop_round= 1; |
| 25 |
while($loop_round <= $loop_rounds) |
| 26 |
{ |
| 27 |
|
| 28 |
--disable_query_log |
| 29 |
|
| 30 |
# Collect the current state |
| 31 |
#========================== |
| 32 |
eval $truncate; |
| 33 |
eval $insert_before; |
| 34 |
|
| 35 |
# Run the operation |
| 36 |
#================== |
| 37 |
if($is_connect) |
| 38 |
{ |
| 39 |
let $statement= Connect (con*,$connect_host,$connect_user,,$connect_db,,); |
| 40 |
# Some statements fail with ER_ACCESS_DENIED_ERROR |
| 41 |
--disable_abort_on_error |
| 42 |
--connect (con$loop_round,$connect_host,$connect_user,,$connect_db,,) |
| 43 |
--enable_abort_on_error |
| 44 |
let $my_errno= $mysql_errno; |
| 45 |
if(!$my_errno) |
| 46 |
{ |
| 47 |
# Note(mleich): |
| 48 |
# We are aware that this additional statement is overhead. |
| 49 |
# But it ensures that SUM_NUMBER_OF_BYTES_READ and |
| 50 |
# SUM_NUMBER_OF_BYTES_WRITE are updated. |
| 51 |
# And this avoids the instabilities found when running |
| 52 |
# the connect without this additional statement. |
| 53 |
DO 1; |
| 54 |
} |
| 55 |
--connection default |
| 56 |
} |
| 57 |
if(!$is_connect) |
| 58 |
{ |
| 59 |
--connection con1 |
| 60 |
# Print the statement outcome once. |
| 61 |
if($loop_round == 1) |
| 62 |
{ |
| 63 |
--enable_query_log |
| 64 |
--enable_result_log |
| 65 |
--horizontal_results |
| 66 |
} |
| 67 |
# One of the statements to be checked is expected to fail with ER_NO_SUCH_TABLE. |
| 68 |
--disable_abort_on_error |
| 69 |
eval $statement; |
| 70 |
--connection default |
| 71 |
--enable_abort_on_error |
| 72 |
--disable_query_log |
| 73 |
--disable_result_log |
| 74 |
} |
| 75 |
|
| 76 |
# Wait till the operation is really finished. We expect that there will be no |
| 77 |
# changes to the statistics of the additional connection after this point of time. |
| 78 |
#================================================================================= |
| 79 |
--connection default |
| 80 |
# Variants: |
| 81 |
#---------- |
| 82 |
# 1. Connect failed ($my_errno <> 0) |
| 83 |
# no entry in performance_schema.threads -> wait_till_sleep.inc cannot be used |
| 84 |
# short life entry in socket_summary_by_instance -> wait till it doesn't exist |
| 85 |
# 2. Connect with success ($my_errno = 0) |
| 86 |
# entry in performance_schema.threads -> wait_till_sleep.inc can be used |
| 87 |
# entry in socket_summary_by_instance -> wait till it does exist |
| 88 |
# 3. SQL command failed ($my_errno <> 0) |
| 89 |
# entry in performance_schema.threads -> wait_till_sleep.inc can be used |
| 90 |
if($is_connect) |
| 91 |
{ |
| 92 |
let $part= |
| 93 |
FROM performance_schema.socket_summary_by_instance |
| 94 |
WHERE EVENT_NAME LIKE '%client_connection' |
| 95 |
AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin; |
| 96 |
|
| 97 |
if(!$my_errno) |
| 98 |
{ |
| 99 |
# Wait till the new connection is visible in performance_schema.threads |
| 100 |
# and processlist_command is 'Sleep'. |
| 101 |
--source ../include/wait_till_sleep.inc |
| 102 |
|
| 103 |
# A successful connect causes that a new second row in |
| 104 |
# performance_schema.socket_summary_by_instance shows up. |
| 105 |
# Wait till this row is there. |
| 106 |
let $wait_timeout= 10; |
| 107 |
let $wait_condition= |
| 108 |
SELECT COUNT(*) = 1 |
| 109 |
$part; |
| 110 |
--source include/wait_condition.inc |
| 111 |
if (!$success) |
| 112 |
{ |
| 113 |
--echo # Error: We did not reach the expected state where a new |
| 114 |
--echo # row in socket_summary_by_instance is visible |
| 115 |
eval |
| 116 |
SELECT * |
| 117 |
$part; |
| 118 |
--echo # abort |
| 119 |
exit; |
| 120 |
} |
| 121 |
} |
| 122 |
if($my_errno) |
| 123 |
{ |
| 124 |
# Experiments with high parallel load showed that there is a very |
| 125 |
# period of time where a "client_connection" entry for a failing |
| 126 |
# Connect is visible. |
| 127 |
# We hope that sleep 1 is long enough so that PERFORMANCE_SCHEMA |
| 128 |
# can remove this row before we collect the after action state. |
| 129 |
let $wait_timeout= 5; |
| 130 |
let $wait_condition= |
| 131 |
SELECT COUNT(*) = 0 |
| 132 |
$part; |
| 133 |
--source include/wait_condition.inc |
| 134 |
if(!$success) |
| 135 |
{ |
| 136 |
--echo # Error: We did not reach the expected state. |
| 137 |
--echo # A failing connect causes a "client_connection" entry |
| 138 |
--echo # within socket_summary_by_instance having an extreme |
| 139 |
--echo # short lifetime. |
| 140 |
--echo # This entry must have now disappeared. |
| 141 |
eval |
| 142 |
SELECT * |
| 143 |
$part; |
| 144 |
--echo # abort |
| 145 |
exit; |
| 146 |
} |
| 147 |
} |
| 148 |
# --sleep 3 |
| 149 |
} |
| 150 |
if(!$is_connect) |
| 151 |
{ |
| 152 |
--source ../include/wait_till_sleep.inc |
| 153 |
} |
| 154 |
|
| 155 |
# Various checks |
| 156 |
#=============== |
| 157 |
# 1. Check statistics in general |
| 158 |
#------------------------------- |
| 159 |
# ../include/socket_summary_check.inc also inserts the 'After' state into |
| 160 |
# mysqltest.my_socket_summary_by_instance. |
| 161 |
--source ../include/socket_summary_check.inc |
| 162 |
--disable_query_log |
| 163 |
--disable_result_log |
| 164 |
|
| 165 |
if($is_connect) |
| 166 |
{ |
| 167 |
eval $get_object_instance_begin; |
| 168 |
eval $insert_pseudo_before; |
| 169 |
} |
| 170 |
|
| 171 |
eval $insert_delta; |
| 172 |
# Correct the values of the columns statement and run |
| 173 |
eval |
| 174 |
UPDATE mysqltest.socket_summary_by_instance_detail |
| 175 |
SET statement = '$statement' |
| 176 |
WHERE statement IS NULL; |
| 177 |
eval |
| 178 |
UPDATE mysqltest.socket_summary_by_instance_detail |
| 179 |
SET run = $loop_round |
| 180 |
WHERE run IS NULL; |
| 181 |
|
| 182 |
if($is_connect) |
| 183 |
{ |
| 184 |
# Only in case the connect was successful ($my_errno = 0) than we have to disconnect. |
| 185 |
if(!$my_errno) |
| 186 |
{ |
| 187 |
--disconnect con$loop_round |
| 188 |
# Wait till the connection using the DB = 'mysqltest' or |
| 189 |
# 'mysqlsupertest' has disappeared from performance_schema.threads |
| 190 |
let $part= |
| 191 |
FROM performance_schema.threads |
| 192 |
WHERE processlist_db IN ('mysqltest','mysqlsupertest'); |
| 193 |
let $wait_timeout= 10; |
| 194 |
let $wait_condition= |
| 195 |
SELECT COUNT(*) = 0 |
| 196 |
$part; |
| 197 |
--source include/wait_condition.inc |
| 198 |
if (!$success) |
| 199 |
{ |
| 200 |
--echo # Error: The disconnect of the connection with processlist_db |
| 201 |
--echo # IN ('mysqltest','mysqlsupertest') failed |
| 202 |
SELECT * |
| 203 |
$part; |
| 204 |
--echo # abort |
| 205 |
exit; |
| 206 |
} |
| 207 |
# Wait in addition till the corresponding 'client_connection' entry of |
| 208 |
# the connection using the DB = 'mysqltest' or 'mysqlsupertest' has disappeared. |
| 209 |
let $part= |
| 210 |
FROM performance_schema.socket_summary_by_instance |
| 211 |
WHERE EVENT_NAME LIKE '%client_connection' |
| 212 |
AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin; |
| 213 |
let $wait_timeout= 10; |
| 214 |
let $wait_condition= |
| 215 |
SELECT COUNT(*) = 0 |
| 216 |
$part; |
| 217 |
--source include/wait_condition.inc |
| 218 |
if (!$success) |
| 219 |
{ |
| 220 |
--echo # Error: The entry of the disconnectd connection with processlist_db |
| 221 |
--echo # IN ('mysqltest','mysqlsupertest') did not disappear |
| 222 |
SELECT * |
| 223 |
$part; |
| 224 |
--echo # abort |
| 225 |
exit; |
| 226 |
} |
| 227 |
} |
| 228 |
# --sleep 3 |
| 229 |
} |
| 230 |
inc $loop_round; |
| 231 |
|
| 232 |
} |
| 233 |
|
| 234 |
--enable_query_log |
| 235 |
--enable_result_log |
| 236 |
|