| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# 1. Verify that a system variable has the expected value when |
| 4 |
# reading the @@variable. |
| 5 |
# 2. Verify that a system variable has the expected value when |
| 6 |
# reading it from the performance_schema table. |
| 7 |
# 3. Verify that a system variable has the expected VARIABLE_SOURCE |
| 8 |
# in performance_schema.variables.info. |
| 9 |
# 4. Verify that a system variable has the expected value in |
| 10 |
# performance_schema.persisted_variables. |
| 11 |
# 5. Verify that a system variable has the expected value in the |
| 12 |
# persisted variables file. |
| 13 |
# |
| 14 |
# ==== Usage ==== |
| 15 |
# |
| 16 |
# --let $variable = NAME |
| 17 |
# --let $scope = {global|session} |
| 18 |
# --let $expect_value = VARIABLE_VALUE |
| 19 |
# [--let $value_map = JSON_OBJECT] |
| 20 |
# [--let $ps_value_map = JSON_OBJECT] |
| 21 |
# [--let $mask_value = 1] |
| 22 |
# [--let $expect_persisted_ps = {exists|noexists}] |
| 23 |
# [--let $expect_persisted_json = {exists|noexists}] |
| 24 |
# [--let $persisted_json = JSON_OBJECT | LOAD] |
| 25 |
# [--let $expect_source = SOURCE] |
| 26 |
# [--let $expect_persisted_value = {VALUE|SAME_AS_VALUE}] |
| 27 |
# [--let $rpl_debug = 1] |
| 28 |
# --source assertions_for_sysvar_value.inc |
| 29 |
# |
| 30 |
# Parameters: |
| 31 |
# $variable |
| 32 |
# The name of the variable. |
| 33 |
# |
| 34 |
# $scope |
| 35 |
# The scope where the variable should be checked. |
| 36 |
# See also scenarios_for_dynamic_sysvar.inc. |
| 37 |
# |
| 38 |
# $value_map, $ps_value_map, $mask_value |
| 39 |
# See json_sysvar_spec.inc |
| 40 |
# |
| 41 |
# $expect_value |
| 42 |
# The value that was set for the variable. |
| 43 |
# |
| 44 |
# $expect_persisted_ps |
| 45 |
# If set to 'exists', assert that the variable exists in |
| 46 |
# performance_schema.persisted_variables. If set to 'noexists', |
| 47 |
# assert that the variable does not exist in |
| 48 |
# performance_schema.persisted_variables. If not set, perform no |
| 49 |
# such check. |
| 50 |
# |
| 51 |
# $expect_persisted_json |
| 52 |
# If set to 'exists', assert that the variable exists in |
| 53 |
# $persisted_json (see below). If set to 'noexists', assert that |
| 54 |
# the variable does not exist in $persisted_json. If not set, |
| 55 |
# perform no such check. |
| 56 |
# |
| 57 |
# $persisted_json |
| 58 |
# If $expect_persisted_json is set, this should be set to the full |
| 59 |
# file contents of the persisted variables file, with single |
| 60 |
# quotes and backslashes escaped. Use load_persisted_json.inc. Or |
| 61 |
# set it to LOAD to automatically load the file. |
| 62 |
# |
| 63 |
# $expect_source |
| 64 |
# If this is not empty, check that the VARIABLE_SOURCE field in |
| 65 |
# performance_schema.variables_info has this value. |
| 66 |
# |
| 67 |
# $expect_persisted_value |
| 68 |
# Expect that the persisted value is this. Use SAME_AS_VALUE if it |
| 69 |
# is expected to be the same as $expect_value. This will be |
| 70 |
# passed through $value_map and $ps_value_map just like |
| 71 |
# $expect_value. |
| 72 |
# |
| 73 |
# $rpl_debug |
| 74 |
# Print extra debug info. |
| 75 |
|
| 76 |
--let $assert_escape = 1 |
| 77 |
|
| 78 |
# 1. @@GLOBAL.NAME |
| 79 |
|
| 80 |
# Get "actual" expected value from map. |
| 81 |
# |
| 82 |
# $expect_value should be the value that was previously set with a SET |
| 83 |
# statement. Usually, you see the same value in SELECT, but not |
| 84 |
# always: e.g., after "SET variable = TRUE", "SELECT variable" will |
| 85 |
# return 1. And after "SET variable = 'x'" with quotes around x, |
| 86 |
# "SELECT variable" will return x without quotes. For such cases, the |
| 87 |
# caller should include the transformation as an entry in $value_map, |
| 88 |
# where the key is the value that was used in SET and the value is |
| 89 |
# what you expect to see in SELECT. |
| 90 |
--let $json_key = $expect_value |
| 91 |
--let $json_object = $value_map |
| 92 |
--let $json_lookup_output_single_quote_escaped = 1 |
| 93 |
--source include/json_lookup.inc |
| 94 |
--let $_csv_expect_value = $json_value |
| 95 |
|
| 96 |
# Get value from @@variable |
| 97 |
--let $_csv_value = `SELECT @@$scope.$variable` |
| 98 |
--let $_csv_value = escape(\',$_csv_value) |
| 99 |
|
| 100 |
# Verify that value is expected |
| 101 |
--let $assert_cond = '$_csv_value' = '$_csv_expect_value' |
| 102 |
if ($mask_value) { |
| 103 |
--let $assert_text = @@$scope.$variable should have the expected value |
| 104 |
} |
| 105 |
if (!$mask_value) { |
| 106 |
--let $assert_text = @@$scope.$variable should be $_csv_expect_value |
| 107 |
} |
| 108 |
--source include/assert.inc |
| 109 |
|
| 110 |
# 2. PERFORMANCE_SCHEMA.GLOBAL_VARIABLES |
| 111 |
|
| 112 |
# Get "actual" expected value from map. |
| 113 |
--let $json_key = $_csv_expect_value |
| 114 |
--let $json_object = $ps_value_map |
| 115 |
--source include/json_lookup.inc |
| 116 |
--let $_csv_expect_value_ps = $json_value |
| 117 |
|
| 118 |
# Get value from performance_schema |
| 119 |
--let $_csv_table = _variables |
| 120 |
--let $_csv_table = $scope$_csv_table |
| 121 |
--let $_csv_value_ps = `SELECT VARIABLE_VALUE FROM performance_schema.$_csv_table WHERE VARIABLE_NAME = '$variable'` |
| 122 |
--let $_csv_value_ps = escape(\',$_csv_value_ps) |
| 123 |
|
| 124 |
# Verify that value is expected |
| 125 |
--let $assert_cond = '$_csv_value_ps' = '$_csv_expect_value_ps' |
| 126 |
if ($mask_value) { |
| 127 |
--let $assert_text = $variable should have the expected value in P_S.$_csv_table |
| 128 |
} |
| 129 |
if (!$mask_value) { |
| 130 |
--let $assert_text = $variable should be $_csv_expect_value in P_S.$_csv_table |
| 131 |
} |
| 132 |
--source include/assert.inc |
| 133 |
|
| 134 |
# 3. PERFORMANCE_SCHEMA.VARIABLES_INFO/SOURCE |
| 135 |
|
| 136 |
if ($expect_source) { |
| 137 |
--let $assert_cond = '[SELECT VARIABLE_SOURCE FROM performance_schema.variables_info WHERE VARIABLE_NAME = '$variable']' = '$expect_source' |
| 138 |
--let $assert_text = $variable should have source $expect_source in P_S.variables_info |
| 139 |
--source include/assert.inc |
| 140 |
} |
| 141 |
|
| 142 |
# 4. PERFORMANCE_SCHEMA.PERSISTED_VARIABLES |
| 143 |
|
| 144 |
# Get expected persisted value (may be different from expected global |
| 145 |
# value in case of set persist_only or set global). |
| 146 |
--let $_csv_expect_persisted_value = $_csv_expect_value_ps |
| 147 |
if ($rpl_debug) { |
| 148 |
--echo DEBUG: assertions_for_sysvar_value: expect_persisted_value=<$expect_persisted_value> |
| 149 |
} |
| 150 |
if ($expect_persisted_value != SAME_AS_VALUE) { |
| 151 |
--let $json_key = $expect_persisted_value |
| 152 |
--let $json_object = $value_map |
| 153 |
--let $json_lookup_output_single_quote_escaped = 0 |
| 154 |
--source include/json_lookup.inc |
| 155 |
--let $json_key = $json_value |
| 156 |
--let $json_object = $ps_value_map |
| 157 |
--let $json_lookup_output_single_quote_escaped = 1 |
| 158 |
--source include/json_lookup.inc |
| 159 |
--let $_csv_expect_persisted_value = $json_value |
| 160 |
} |
| 161 |
if ($rpl_debug) { |
| 162 |
--echo DEBUG: assertions_for_sysvar_value: _csv_expect_persisted_value=<$_csv_expect_persisted_value> |
| 163 |
} |
| 164 |
|
| 165 |
if ($expect_persisted_ps == exists) { |
| 166 |
# Get value from performance_schema |
| 167 |
--let $_csv_value_ps = `SELECT VARIABLE_VALUE FROM performance_schema.persisted_variables WHERE VARIABLE_NAME = '$variable'` |
| 168 |
--let $_csv_value_ps = escape(\',$_csv_value_ps) |
| 169 |
--let $assert_cond = '$_csv_value_ps' = '$_csv_expect_persisted_value' |
| 170 |
if ($mask_value) { |
| 171 |
--let $assert_text = $variable should have the expected value in P_S.persisted_variables |
| 172 |
} |
| 173 |
if (!$mask_value) { |
| 174 |
--let $assert_text = $variable should be $_csv_expect_persisted_value in P_S.persisted_variables |
| 175 |
} |
| 176 |
--source include/assert.inc |
| 177 |
} |
| 178 |
if ($expect_persisted_ps == noexists) { |
| 179 |
# Get count from performance_schema |
| 180 |
--let $_csv_count = `SELECT COUNT(*) FROM performance_schema.persisted_variables WHERE VARIABLE_NAME = '$variable'` |
| 181 |
--let $assert_cond = '$_csv_count' = '0' |
| 182 |
--let $assert_text = $variable should not exist in P_S.persisted_variables |
| 183 |
--source include/assert.inc |
| 184 |
} |
| 185 |
|
| 186 |
# 5. PERSISTED VARIABLES FILE |
| 187 |
|
| 188 |
if ($expect_persisted_json != '') { |
| 189 |
# Read JSON from file, if required |
| 190 |
--let $_csv_persisted_json = $persisted_json |
| 191 |
if ($persisted_json == LOAD) { |
| 192 |
--source load_persisted_json.inc |
| 193 |
--let $_csv_persisted_json = $persisted_json |
| 194 |
--let $persisted_json = LOAD |
| 195 |
} |
| 196 |
# Verify that value exists. |
| 197 |
if ($expect_persisted_json == exists) { |
| 198 |
if ($mask_value) { |
| 199 |
--let $assert_text = $variable should have the expected value in the persist file |
| 200 |
} |
| 201 |
if (!$mask_value) { |
| 202 |
--let $assert_text = $variable should have value $_csv_expect_persisted_value in the persist file |
| 203 |
} |
| 204 |
|
| 205 |
# Variables tagged as "PERSIST_AS_READONLY" are stored in a |
| 206 |
# sub-document. |
| 207 |
if ($persist_as_readonly) { |
| 208 |
--let $subsection = mysql_static_variables |
| 209 |
} |
| 210 |
if (!$persist_as_readonly) { |
| 211 |
--let $subsection = mysql_dynamic_variables |
| 212 |
} |
| 213 |
--let $actual_value = `SELECT JSON_UNQUOTE(JSON_EXTRACT('$_csv_persisted_json', '$.$subsection.$variable.Value'))` |
| 214 |
--let $actual_value = escape(\',$actual_value) |
| 215 |
--let $assert_cond = '$actual_value' = '$_csv_expect_persisted_value' |
| 216 |
--source include/assert.inc |
| 217 |
} |
| 218 |
# Verify that value does not exist. |
| 219 |
if ($expect_persisted_json == noexists) { |
| 220 |
--let $assert_text = $variable should not exist in the persist file |
| 221 |
--let $assert_cond = JSON_CONTAINS_PATH('$_csv_persisted_json', 'one', '$.mysql_dynamic_variables.$variable') = 0 |
| 222 |
--source include/assert.inc |
| 223 |
} |
| 224 |
} |