github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/interlock/set_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package interlock_test 15 16 import ( 17 "bytes" 18 "context" 19 "errors" 20 "fmt" 21 "io/ioutil" 22 "net/http" 23 "strconv" 24 25 . "github.com/whtcorpsinc/check" 26 "github.com/whtcorpsinc/BerolinaSQL/allegrosql" 27 "github.com/whtcorpsinc/BerolinaSQL/terror" 28 "github.com/whtcorpsinc/milevadb/config" 29 "github.com/whtcorpsinc/milevadb/interlock" 30 "github.com/whtcorpsinc/milevadb/memex" 31 "github.com/whtcorpsinc/milevadb/schemareplicant" 32 "github.com/whtcorpsinc/milevadb/stochastikctx" 33 "github.com/whtcorpsinc/milevadb/stochastikctx/variable" 34 "github.com/whtcorpsinc/milevadb/types" 35 "github.com/whtcorpsinc/milevadb/soliton/mock" 36 "github.com/whtcorpsinc/milevadb/soliton/testkit" 37 "github.com/whtcorpsinc/milevadb/soliton/solitonutil" 38 ) 39 40 func (s *testSuite5) TestSetVar(c *C) { 41 tk := testkit.NewTestKit(c, s.causetstore) 42 testALLEGROSQL := "SET @a = 1;" 43 tk.MustInterDirc(testALLEGROSQL) 44 45 testALLEGROSQL = `SET @a = "1";` 46 tk.MustInterDirc(testALLEGROSQL) 47 48 testALLEGROSQL = "SET @a = null;" 49 tk.MustInterDirc(testALLEGROSQL) 50 51 testALLEGROSQL = "SET @@global.autocommit = 1;" 52 tk.MustInterDirc(testALLEGROSQL) 53 54 // TODO: this test case should returns error. 55 // testALLEGROSQL = "SET @@global.autocommit = null;" 56 // _, err := tk.InterDirc(testALLEGROSQL) 57 // c.Assert(err, NotNil) 58 59 testALLEGROSQL = "SET @@autocommit = 1;" 60 tk.MustInterDirc(testALLEGROSQL) 61 62 testALLEGROSQL = "SET @@autocommit = null;" 63 _, err := tk.InterDirc(testALLEGROSQL) 64 c.Assert(err, NotNil) 65 66 errTestALLEGROSQL := "SET @@date_format = 1;" 67 _, err = tk.InterDirc(errTestALLEGROSQL) 68 c.Assert(err, NotNil) 69 70 errTestALLEGROSQL = "SET @@rewriter_enabled = 1;" 71 _, err = tk.InterDirc(errTestALLEGROSQL) 72 c.Assert(err, NotNil) 73 74 errTestALLEGROSQL = "SET xxx = abcd;" 75 _, err = tk.InterDirc(errTestALLEGROSQL) 76 c.Assert(err, NotNil) 77 78 errTestALLEGROSQL = "SET @@global.a = 1;" 79 _, err = tk.InterDirc(errTestALLEGROSQL) 80 c.Assert(err, NotNil) 81 82 errTestALLEGROSQL = "SET @@global.timestamp = 1;" 83 _, err = tk.InterDirc(errTestALLEGROSQL) 84 c.Assert(err, NotNil) 85 86 // For issue 998 87 testALLEGROSQL = "SET @issue998a=1, @issue998b=5;" 88 tk.MustInterDirc(testALLEGROSQL) 89 tk.MustQuery(`select @issue998a, @issue998b;`).Check(testkit.Events("1 5")) 90 testALLEGROSQL = "SET @@autocommit=0, @issue998a=2;" 91 tk.MustInterDirc(testALLEGROSQL) 92 tk.MustQuery(`select @issue998a, @@autocommit;`).Check(testkit.Events("2 0")) 93 testALLEGROSQL = "SET @@global.autocommit=1, @issue998b=6;" 94 tk.MustInterDirc(testALLEGROSQL) 95 tk.MustQuery(`select @issue998b, @@global.autocommit;`).Check(testkit.Events("6 1")) 96 97 // For issue 4302 98 testALLEGROSQL = "use test;drop causet if exists x;create causet x(a int);insert into x value(1);" 99 tk.MustInterDirc(testALLEGROSQL) 100 testALLEGROSQL = "SET @issue4302=(select a from x limit 1);" 101 tk.MustInterDirc(testALLEGROSQL) 102 tk.MustQuery(`select @issue4302;`).Check(testkit.Events("1")) 103 104 // Set default 105 // {ScopeGlobal | ScopeStochastik, "low_priority_uFIDelates", "OFF"}, 106 // For global var 107 tk.MustQuery(`select @@global.low_priority_uFIDelates;`).Check(testkit.Events("0")) 108 tk.MustInterDirc(`set @@global.low_priority_uFIDelates="ON";`) 109 tk.MustQuery(`select @@global.low_priority_uFIDelates;`).Check(testkit.Events("1")) 110 tk.MustInterDirc(`set @@global.low_priority_uFIDelates=DEFAULT;`) // It will be set to compiled-in default value. 111 tk.MustQuery(`select @@global.low_priority_uFIDelates;`).Check(testkit.Events("0")) 112 // For stochastik 113 tk.MustQuery(`select @@stochastik.low_priority_uFIDelates;`).Check(testkit.Events("0")) 114 tk.MustInterDirc(`set @@global.low_priority_uFIDelates="ON";`) 115 tk.MustInterDirc(`set @@stochastik.low_priority_uFIDelates=DEFAULT;`) // It will be set to global var value. 116 tk.MustQuery(`select @@stochastik.low_priority_uFIDelates;`).Check(testkit.Events("1")) 117 118 // For allegrosql jdbc driver issue. 119 tk.MustQuery(`select @@stochastik.tx_read_only;`).Check(testkit.Events("0")) 120 121 // Test stochastik variable states. 122 vars := tk.Se.(stochastikctx.Context).GetStochastikVars() 123 tk.Se.CommitTxn(context.TODO()) 124 tk.MustInterDirc("set @@autocommit = 1") 125 c.Assert(vars.InTxn(), IsFalse) 126 c.Assert(vars.IsAutocommit(), IsTrue) 127 tk.MustInterDirc("set @@autocommit = 0") 128 c.Assert(vars.IsAutocommit(), IsFalse) 129 130 tk.MustInterDirc("set @@sql_mode = 'strict_trans_blocks'") 131 c.Assert(vars.StrictALLEGROSQLMode, IsTrue) 132 tk.MustInterDirc("set @@sql_mode = ''") 133 c.Assert(vars.StrictALLEGROSQLMode, IsFalse) 134 135 tk.MustInterDirc("set names utf8") 136 charset, defCauslation := vars.GetCharsetInfo() 137 c.Assert(charset, Equals, "utf8") 138 c.Assert(defCauslation, Equals, "utf8_bin") 139 140 tk.MustInterDirc("set names latin1 defCauslate latin1_swedish_ci") 141 charset, defCauslation = vars.GetCharsetInfo() 142 c.Assert(charset, Equals, "latin1") 143 c.Assert(defCauslation, Equals, "latin1_swedish_ci") 144 145 tk.MustInterDirc("set names utf8 defCauslate default") 146 charset, defCauslation = vars.GetCharsetInfo() 147 c.Assert(charset, Equals, "utf8") 148 c.Assert(defCauslation, Equals, "utf8_bin") 149 150 expectErrMsg := "[dbs:1273]Unknown defCauslation: 'non_exist_defCauslation'" 151 tk.MustGetErrMsg("set names utf8 defCauslate non_exist_defCauslation", expectErrMsg) 152 tk.MustGetErrMsg("set @@stochastik.defCauslation_server='non_exist_defCauslation'", expectErrMsg) 153 tk.MustGetErrMsg("set @@stochastik.defCauslation_database='non_exist_defCauslation'", expectErrMsg) 154 tk.MustGetErrMsg("set @@stochastik.defCauslation_connection='non_exist_defCauslation'", expectErrMsg) 155 tk.MustGetErrMsg("set @@global.defCauslation_server='non_exist_defCauslation'", expectErrMsg) 156 tk.MustGetErrMsg("set @@global.defCauslation_database='non_exist_defCauslation'", expectErrMsg) 157 tk.MustGetErrMsg("set @@global.defCauslation_connection='non_exist_defCauslation'", expectErrMsg) 158 159 tk.MustInterDirc("set character_set_results = NULL") 160 tk.MustQuery("select @@character_set_results").Check(testkit.Events("")) 161 162 tk.MustInterDirc("set @@stochastik.dbs_slow_threshold=12345") 163 tk.MustQuery("select @@stochastik.dbs_slow_threshold").Check(testkit.Events("12345")) 164 c.Assert(variable.DBSSlowOprThreshold, Equals, uint32(12345)) 165 tk.MustInterDirc("set stochastik dbs_slow_threshold=\"54321\"") 166 tk.MustQuery("show variables like 'dbs_slow_threshold'").Check(testkit.Events("dbs_slow_threshold 54321")) 167 c.Assert(variable.DBSSlowOprThreshold, Equals, uint32(54321)) 168 169 // Test set transaction isolation level, which is equivalent to setting variable "tx_isolation". 170 tk.MustInterDirc("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED") 171 tk.MustQuery("select @@stochastik.tx_isolation").Check(testkit.Events("READ-COMMITTED")) 172 tk.MustQuery("select @@stochastik.transaction_isolation").Check(testkit.Events("READ-COMMITTED")) 173 // error 174 _, err = tk.InterDirc("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED") 175 c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedIsolationLevel), IsTrue, Commentf("err %v", err)) 176 tk.MustQuery("select @@stochastik.tx_isolation").Check(testkit.Events("READ-COMMITTED")) 177 tk.MustQuery("select @@stochastik.transaction_isolation").Check(testkit.Events("READ-COMMITTED")) 178 // Fails 179 _, err = tk.InterDirc("SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE") 180 c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedIsolationLevel), IsTrue, Commentf("err %v", err)) 181 tk.MustQuery("select @@global.tx_isolation").Check(testkit.Events("REPEATABLE-READ")) 182 tk.MustQuery("select @@global.transaction_isolation").Check(testkit.Events("REPEATABLE-READ")) 183 184 // test synonyms variables 185 tk.MustInterDirc("SET SESSION tx_isolation = 'READ-COMMITTED'") 186 tk.MustQuery("select @@stochastik.tx_isolation").Check(testkit.Events("READ-COMMITTED")) 187 tk.MustQuery("select @@stochastik.transaction_isolation").Check(testkit.Events("READ-COMMITTED")) 188 189 _, err = tk.InterDirc("SET SESSION tx_isolation = 'READ-UNCOMMITTED'") 190 c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedIsolationLevel), IsTrue, Commentf("err %v", err)) 191 tk.MustQuery("select @@stochastik.tx_isolation").Check(testkit.Events("READ-COMMITTED")) 192 tk.MustQuery("select @@stochastik.transaction_isolation").Check(testkit.Events("READ-COMMITTED")) 193 194 // fails 195 _, err = tk.InterDirc("SET SESSION transaction_isolation = 'SERIALIZABLE'") 196 c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedIsolationLevel), IsTrue, Commentf("err %v", err)) 197 tk.MustQuery("select @@stochastik.tx_isolation").Check(testkit.Events("READ-COMMITTED")) 198 tk.MustQuery("select @@stochastik.transaction_isolation").Check(testkit.Events("READ-COMMITTED")) 199 200 // fails 201 _, err = tk.InterDirc("SET GLOBAL transaction_isolation = 'SERIALIZABLE'") 202 c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedIsolationLevel), IsTrue, Commentf("err %v", err)) 203 tk.MustQuery("select @@global.tx_isolation").Check(testkit.Events("REPEATABLE-READ")) 204 tk.MustQuery("select @@global.transaction_isolation").Check(testkit.Events("REPEATABLE-READ")) 205 206 _, err = tk.InterDirc("SET GLOBAL transaction_isolation = 'READ-UNCOMMITTED'") 207 c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedIsolationLevel), IsTrue, Commentf("err %v", err)) 208 tk.MustQuery("select @@global.tx_isolation").Check(testkit.Events("REPEATABLE-READ")) 209 tk.MustQuery("select @@global.transaction_isolation").Check(testkit.Events("REPEATABLE-READ")) 210 211 _, err = tk.InterDirc("SET GLOBAL tx_isolation = 'SERIALIZABLE'") 212 c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedIsolationLevel), IsTrue, Commentf("err %v", err)) 213 tk.MustQuery("select @@global.tx_isolation").Check(testkit.Events("REPEATABLE-READ")) 214 tk.MustQuery("select @@global.transaction_isolation").Check(testkit.Events("REPEATABLE-READ")) 215 216 tk.MustInterDirc("SET SESSION tx_read_only = 1") 217 tk.MustInterDirc("SET SESSION tx_read_only = 0") 218 tk.MustQuery("select @@stochastik.tx_read_only").Check(testkit.Events("0")) 219 tk.MustQuery("select @@stochastik.transaction_read_only").Check(testkit.Events("0")) 220 221 tk.MustInterDirc("SET GLOBAL tx_read_only = 1") 222 tk.MustInterDirc("SET GLOBAL tx_read_only = 0") 223 tk.MustQuery("select @@global.tx_read_only").Check(testkit.Events("0")) 224 tk.MustQuery("select @@global.transaction_read_only").Check(testkit.Events("0")) 225 226 tk.MustInterDirc("SET SESSION transaction_read_only = 1") 227 tk.MustInterDirc("SET SESSION transaction_read_only = 0") 228 tk.MustQuery("select @@stochastik.tx_read_only").Check(testkit.Events("0")) 229 tk.MustQuery("select @@stochastik.transaction_read_only").Check(testkit.Events("0")) 230 231 tk.MustInterDirc("SET SESSION transaction_read_only = 1") 232 tk.MustQuery("select @@stochastik.tx_read_only").Check(testkit.Events("1")) 233 tk.MustQuery("select @@stochastik.transaction_read_only").Check(testkit.Events("1")) 234 235 tk.MustInterDirc("SET GLOBAL transaction_read_only = 1") 236 tk.MustInterDirc("SET GLOBAL transaction_read_only = 0") 237 tk.MustQuery("select @@global.tx_read_only").Check(testkit.Events("0")) 238 tk.MustQuery("select @@global.transaction_read_only").Check(testkit.Events("0")) 239 240 tk.MustInterDirc("SET GLOBAL transaction_read_only = 1") 241 tk.MustQuery("select @@global.tx_read_only").Check(testkit.Events("1")) 242 tk.MustQuery("select @@global.transaction_read_only").Check(testkit.Events("1")) 243 244 // Even the transaction fail, set stochastik variable would success. 245 tk.MustInterDirc("BEGIN") 246 tk.MustInterDirc("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED") 247 _, err = tk.InterDirc(`INSERT INTO t VALUES ("sdfsdf")`) 248 c.Assert(err, NotNil) 249 tk.MustInterDirc("COMMIT") 250 tk.MustQuery("select @@stochastik.tx_isolation").Check(testkit.Events("READ-COMMITTED")) 251 252 tk.MustInterDirc("set global avoid_temporal_upgrade = on") 253 tk.MustQuery(`select @@global.avoid_temporal_upgrade;`).Check(testkit.Events("1")) 254 tk.MustInterDirc("set @@global.avoid_temporal_upgrade = off") 255 tk.MustQuery(`select @@global.avoid_temporal_upgrade;`).Check(testkit.Events("0")) 256 tk.MustInterDirc("set stochastik sql_log_bin = on") 257 tk.MustQuery(`select @@stochastik.sql_log_bin;`).Check(testkit.Events("1")) 258 tk.MustInterDirc("set sql_log_bin = off") 259 tk.MustQuery(`select @@stochastik.sql_log_bin;`).Check(testkit.Events("0")) 260 tk.MustInterDirc("set @@sql_log_bin = on") 261 tk.MustQuery(`select @@stochastik.sql_log_bin;`).Check(testkit.Events("1")) 262 263 tk.MustQuery(`select @@global.log_bin;`).Check(testkit.Events(variable.BoolToIntStr(config.GetGlobalConfig().Binlog.Enable))) 264 tk.MustQuery(`select @@log_bin;`).Check(testkit.Events(variable.BoolToIntStr(config.GetGlobalConfig().Binlog.Enable))) 265 266 tk.MustInterDirc("set @@milevadb_general_log = 1") 267 tk.MustInterDirc("set @@milevadb_general_log = 0") 268 269 tk.MustInterDirc("set @@milevadb_pprof_sql_cpu = 1") 270 tk.MustInterDirc("set @@milevadb_pprof_sql_cpu = 0") 271 272 tk.MustInterDirc(`set milevadb_force_priority = "no_priority"`) 273 tk.MustQuery(`select @@milevadb_force_priority;`).Check(testkit.Events("NO_PRIORITY")) 274 tk.MustInterDirc(`set milevadb_force_priority = "low_priority"`) 275 tk.MustQuery(`select @@milevadb_force_priority;`).Check(testkit.Events("LOW_PRIORITY")) 276 tk.MustInterDirc(`set milevadb_force_priority = "high_priority"`) 277 tk.MustQuery(`select @@milevadb_force_priority;`).Check(testkit.Events("HIGH_PRIORITY")) 278 tk.MustInterDirc(`set milevadb_force_priority = "delayed"`) 279 tk.MustQuery(`select @@milevadb_force_priority;`).Check(testkit.Events("DELAYED")) 280 tk.MustInterDirc(`set milevadb_force_priority = "abc"`) 281 tk.MustQuery(`select @@milevadb_force_priority;`).Check(testkit.Events("NO_PRIORITY")) 282 _, err = tk.InterDirc(`set global milevadb_force_priority = ""`) 283 c.Assert(err, NotNil) 284 285 tk.MustInterDirc("set milevadb_constraint_check_in_place = 1") 286 tk.MustQuery(`select @@stochastik.milevadb_constraint_check_in_place;`).Check(testkit.Events("1")) 287 tk.MustInterDirc("set global milevadb_constraint_check_in_place = 0") 288 tk.MustQuery(`select @@global.milevadb_constraint_check_in_place;`).Check(testkit.Events("0")) 289 290 tk.MustInterDirc("set milevadb_batch_commit = 0") 291 tk.MustQuery("select @@stochastik.milevadb_batch_commit;").Check(testkit.Events("0")) 292 tk.MustInterDirc("set milevadb_batch_commit = 1") 293 tk.MustQuery("select @@stochastik.milevadb_batch_commit;").Check(testkit.Events("1")) 294 _, err = tk.InterDirc("set global milevadb_batch_commit = 0") 295 c.Assert(err, NotNil) 296 _, err = tk.InterDirc("set global milevadb_batch_commit = 2") 297 c.Assert(err, NotNil) 298 299 // test skip isolation level check: init 300 tk.MustInterDirc("SET GLOBAL milevadb_skip_isolation_level_check = 0") 301 tk.MustInterDirc("SET SESSION milevadb_skip_isolation_level_check = 0") 302 tk.MustInterDirc("SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED") 303 tk.MustInterDirc("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED") 304 tk.MustQuery("select @@global.tx_isolation").Check(testkit.Events("READ-COMMITTED")) 305 tk.MustQuery("select @@global.transaction_isolation").Check(testkit.Events("READ-COMMITTED")) 306 tk.MustQuery("select @@stochastik.tx_isolation").Check(testkit.Events("READ-COMMITTED")) 307 tk.MustQuery("select @@stochastik.transaction_isolation").Check(testkit.Events("READ-COMMITTED")) 308 309 // test skip isolation level check: error 310 _, err = tk.InterDirc("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE") 311 c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedIsolationLevel), IsTrue, Commentf("err %v", err)) 312 tk.MustQuery("select @@stochastik.tx_isolation").Check(testkit.Events("READ-COMMITTED")) 313 tk.MustQuery("select @@stochastik.transaction_isolation").Check(testkit.Events("READ-COMMITTED")) 314 315 _, err = tk.InterDirc("SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE") 316 c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedIsolationLevel), IsTrue, Commentf("err %v", err)) 317 tk.MustQuery("select @@global.tx_isolation").Check(testkit.Events("READ-COMMITTED")) 318 tk.MustQuery("select @@global.transaction_isolation").Check(testkit.Events("READ-COMMITTED")) 319 320 // test skip isolation level check: success 321 tk.MustInterDirc("SET GLOBAL milevadb_skip_isolation_level_check = 1") 322 tk.MustInterDirc("SET SESSION milevadb_skip_isolation_level_check = 1") 323 tk.MustInterDirc("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE") 324 tk.MustQuery("show warnings").Check(testkit.Events( 325 "Warning 8048 The isolation level 'SERIALIZABLE' is not supported. Set milevadb_skip_isolation_level_check=1 to skip this error")) 326 tk.MustQuery("select @@stochastik.tx_isolation").Check(testkit.Events("SERIALIZABLE")) 327 tk.MustQuery("select @@stochastik.transaction_isolation").Check(testkit.Events("SERIALIZABLE")) 328 329 // test skip isolation level check: success 330 tk.MustInterDirc("SET GLOBAL milevadb_skip_isolation_level_check = 0") 331 tk.MustInterDirc("SET SESSION milevadb_skip_isolation_level_check = 1") 332 tk.MustInterDirc("SET GLOBAL TRANSACTION ISOLATION LEVEL READ UNCOMMITTED") 333 tk.MustQuery("show warnings").Check(testkit.Events( 334 "Warning 8048 The isolation level 'READ-UNCOMMITTED' is not supported. Set milevadb_skip_isolation_level_check=1 to skip this error")) 335 tk.MustQuery("select @@global.tx_isolation").Check(testkit.Events("READ-UNCOMMITTED")) 336 tk.MustQuery("select @@global.transaction_isolation").Check(testkit.Events("READ-UNCOMMITTED")) 337 338 // test skip isolation level check: reset 339 tk.MustInterDirc("SET GLOBAL transaction_isolation='REPEATABLE-READ'") // should reset tx_isolation back to rr before reset milevadb_skip_isolation_level_check 340 tk.MustInterDirc("SET GLOBAL milevadb_skip_isolation_level_check = 0") 341 tk.MustInterDirc("SET SESSION milevadb_skip_isolation_level_check = 0") 342 343 tk.MustInterDirc("set global read_only = 0") 344 tk.MustQuery("select @@global.read_only;").Check(testkit.Events("0")) 345 tk.MustInterDirc("set global read_only = off") 346 tk.MustQuery("select @@global.read_only;").Check(testkit.Events("0")) 347 tk.MustInterDirc("set global read_only = 1") 348 tk.MustQuery("select @@global.read_only;").Check(testkit.Events("1")) 349 tk.MustInterDirc("set global read_only = on") 350 tk.MustQuery("select @@global.read_only;").Check(testkit.Events("1")) 351 _, err = tk.InterDirc("set global read_only = abc") 352 c.Assert(err, NotNil) 353 354 // test for milevadb_wait_split_region_finish 355 tk.MustQuery(`select @@stochastik.milevadb_wait_split_region_finish;`).Check(testkit.Events("1")) 356 tk.MustInterDirc("set milevadb_wait_split_region_finish = 1") 357 tk.MustQuery(`select @@stochastik.milevadb_wait_split_region_finish;`).Check(testkit.Events("1")) 358 tk.MustInterDirc("set milevadb_wait_split_region_finish = 0") 359 tk.MustQuery(`select @@stochastik.milevadb_wait_split_region_finish;`).Check(testkit.Events("0")) 360 361 // test for milevadb_scatter_region 362 tk.MustQuery(`select @@global.milevadb_scatter_region;`).Check(testkit.Events("0")) 363 tk.MustInterDirc("set global milevadb_scatter_region = 1") 364 tk.MustQuery(`select @@global.milevadb_scatter_region;`).Check(testkit.Events("1")) 365 tk.MustInterDirc("set global milevadb_scatter_region = 0") 366 tk.MustQuery(`select @@global.milevadb_scatter_region;`).Check(testkit.Events("0")) 367 _, err = tk.InterDirc("set stochastik milevadb_scatter_region = 0") 368 c.Assert(err, NotNil) 369 _, err = tk.InterDirc(`select @@stochastik.milevadb_scatter_region;`) 370 c.Assert(err, NotNil) 371 372 // test for milevadb_wait_split_region_timeout 373 tk.MustQuery(`select @@stochastik.milevadb_wait_split_region_timeout;`).Check(testkit.Events(strconv.Itoa(variable.DefWaitSplitRegionTimeout))) 374 tk.MustInterDirc("set milevadb_wait_split_region_timeout = 1") 375 tk.MustQuery(`select @@stochastik.milevadb_wait_split_region_timeout;`).Check(testkit.Events("1")) 376 _, err = tk.InterDirc("set milevadb_wait_split_region_timeout = 0") 377 c.Assert(err, NotNil) 378 c.Assert(err.Error(), Equals, "milevadb_wait_split_region_timeout(0) cannot be smaller than 1") 379 tk.MustQuery(`select @@stochastik.milevadb_wait_split_region_timeout;`).Check(testkit.Events("1")) 380 381 tk.MustInterDirc("set stochastik milevadb_backoff_weight = 3") 382 tk.MustQuery("select @@stochastik.milevadb_backoff_weight;").Check(testkit.Events("3")) 383 tk.MustInterDirc("set stochastik milevadb_backoff_weight = 20") 384 tk.MustQuery("select @@stochastik.milevadb_backoff_weight;").Check(testkit.Events("20")) 385 _, err = tk.InterDirc("set stochastik milevadb_backoff_weight = -1") 386 c.Assert(err, NotNil) 387 _, err = tk.InterDirc("set global milevadb_backoff_weight = 0") 388 c.Assert(err, NotNil) 389 tk.MustInterDirc("set global milevadb_backoff_weight = 10") 390 tk.MustQuery("select @@global.milevadb_backoff_weight;").Check(testkit.Events("10")) 391 392 tk.MustInterDirc("set @@milevadb_expensive_query_time_threshold=70") 393 tk.MustQuery("select @@milevadb_expensive_query_time_threshold;").Check(testkit.Events("70")) 394 395 tk.MustQuery("select @@milevadb_store_limit;").Check(testkit.Events("0")) 396 tk.MustInterDirc("set @@milevadb_store_limit = 100") 397 tk.MustQuery("select @@milevadb_store_limit;").Check(testkit.Events("100")) 398 tk.MustQuery("select @@stochastik.milevadb_store_limit;").Check(testkit.Events("100")) 399 tk.MustQuery("select @@global.milevadb_store_limit;").Check(testkit.Events("0")) 400 tk.MustInterDirc("set @@milevadb_store_limit = 0") 401 402 tk.MustInterDirc("set global milevadb_store_limit = 100") 403 tk.MustQuery("select @@milevadb_store_limit;").Check(testkit.Events("0")) 404 tk.MustQuery("select @@stochastik.milevadb_store_limit;").Check(testkit.Events("0")) 405 tk.MustQuery("select @@global.milevadb_store_limit;").Check(testkit.Events("100")) 406 407 tk.MustQuery("select @@milevadb_enable_change_defCausumn_type;").Check(testkit.Events("0")) 408 tk.MustInterDirc("set global milevadb_enable_change_defCausumn_type = 1") 409 tk.MustQuery("select @@milevadb_enable_change_defCausumn_type;").Check(testkit.Events("1")) 410 tk.MustInterDirc("set global milevadb_enable_change_defCausumn_type = off") 411 tk.MustQuery("select @@milevadb_enable_change_defCausumn_type;").Check(testkit.Events("0")) 412 413 tk.MustQuery("select @@stochastik.milevadb_metric_query_step;").Check(testkit.Events("60")) 414 tk.MustInterDirc("set @@stochastik.milevadb_metric_query_step = 120") 415 _, err = tk.InterDirc("set @@stochastik.milevadb_metric_query_step = 9") 416 c.Assert(err, NotNil) 417 c.Assert(err.Error(), Equals, "milevadb_metric_query_step(9) cannot be smaller than 10 or larger than 216000") 418 tk.MustQuery("select @@stochastik.milevadb_metric_query_step;").Check(testkit.Events("120")) 419 420 tk.MustQuery("select @@stochastik.milevadb_metric_query_range_duration;").Check(testkit.Events("60")) 421 tk.MustInterDirc("set @@stochastik.milevadb_metric_query_range_duration = 120") 422 _, err = tk.InterDirc("set @@stochastik.milevadb_metric_query_range_duration = 9") 423 c.Assert(err, NotNil) 424 c.Assert(err.Error(), Equals, "milevadb_metric_query_range_duration(9) cannot be smaller than 10 or larger than 216000") 425 tk.MustQuery("select @@stochastik.milevadb_metric_query_range_duration;").Check(testkit.Events("120")) 426 427 // test for milevadb_slow_log_masking 428 tk.MustQuery(`select @@global.milevadb_slow_log_masking;`).Check(testkit.Events("0")) 429 tk.MustInterDirc("set global milevadb_slow_log_masking = 1") 430 tk.MustQuery(`select @@global.milevadb_slow_log_masking;`).Check(testkit.Events("1")) 431 tk.MustInterDirc("set global milevadb_slow_log_masking = 0") 432 tk.MustQuery(`select @@global.milevadb_slow_log_masking;`).Check(testkit.Events("0")) 433 _, err = tk.InterDirc("set stochastik milevadb_slow_log_masking = 0") 434 c.Assert(err, NotNil) 435 _, err = tk.InterDirc(`select @@stochastik.milevadb_slow_log_masking;`) 436 c.Assert(err, NotNil) 437 438 tk.MustQuery("select @@milevadb_dml_batch_size;").Check(testkit.Events("0")) 439 tk.MustInterDirc("set @@stochastik.milevadb_dml_batch_size = 120") 440 tk.MustQuery("select @@milevadb_dml_batch_size;").Check(testkit.Events("120")) 441 c.Assert(tk.InterDircToErr("set @@stochastik.milevadb_dml_batch_size = -120"), NotNil) 442 c.Assert(tk.InterDircToErr("set @@global.milevadb_dml_batch_size = 200"), IsNil) // now permitted due to MilevaDB #19809 443 tk.MustQuery("select @@milevadb_dml_batch_size;").Check(testkit.Events("120")) // global only applies to new stochastik 444 445 _, err = tk.InterDirc("set milevadb_enable_parallel_apply=-1") 446 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue) 447 } 448 449 func (s *testSuite5) TestTruncateIncorrectIntStochastikVar(c *C) { 450 tk := testkit.NewTestKit(c, s.causetstore) 451 452 testCases := []struct { 453 stochastikVarName string 454 minValue int 455 maxValue int 456 }{ 457 {"auto_increment_increment", 1, 65535}, 458 {"auto_increment_offset", 1, 65535}, 459 } 460 461 for _, tc := range testCases { 462 name := tc.stochastikVarName 463 selectALLEGROSQL := fmt.Sprintf("select @@%s;", name) 464 validValue := tc.minValue + (tc.maxValue-tc.minValue)/2 465 tk.MustInterDirc(fmt.Sprintf("set @@%s = %d", name, validValue)) 466 tk.MustQuery(selectALLEGROSQL).Check(testkit.Events(fmt.Sprintf("%d", validValue))) 467 468 tk.MustInterDirc(fmt.Sprintf("set @@%s = %d", name, tc.minValue-1)) 469 warnMsg := fmt.Sprintf("Warning 1292 Truncated incorrect %s value: '%d'", name, tc.minValue-1) 470 tk.MustQuery("show warnings").Check(testkit.Events(warnMsg)) 471 tk.MustQuery(selectALLEGROSQL).Check(testkit.Events(fmt.Sprintf("%d", tc.minValue))) 472 473 tk.MustInterDirc(fmt.Sprintf("set @@%s = %d", name, tc.maxValue+1)) 474 warnMsg = fmt.Sprintf("Warning 1292 Truncated incorrect %s value: '%d'", name, tc.maxValue+1) 475 tk.MustQuery("show warnings").Check(testkit.Events(warnMsg)) 476 tk.MustQuery(selectALLEGROSQL).Check(testkit.Events(fmt.Sprintf("%d", tc.maxValue))) 477 } 478 } 479 480 func (s *testSuite5) TestSetCharset(c *C) { 481 tk := testkit.NewTestKitWithInit(c, s.causetstore) 482 ctx := tk.Se.(stochastikctx.Context) 483 stochastikVars := ctx.GetStochastikVars() 484 485 var characterSetVariables = []string{ 486 "character_set_client", 487 "character_set_connection", 488 "character_set_results", 489 "character_set_server", 490 "character_set_database", 491 "character_set_system", 492 "character_set_filesystem", 493 } 494 495 check := func(args ...string) { 496 for i, v := range characterSetVariables { 497 sVar, err := variable.GetStochastikSystemVar(stochastikVars, v) 498 c.Assert(err, IsNil) 499 c.Assert(sVar, Equals, args[i], Commentf("%d: %s", i, characterSetVariables[i])) 500 } 501 } 502 503 check( 504 "utf8mb4", 505 "utf8mb4", 506 "utf8mb4", 507 "utf8mb4", 508 "utf8mb4", 509 "utf8", 510 "binary", 511 ) 512 513 tk.MustInterDirc(`SET NAMES latin1`) 514 check( 515 "latin1", 516 "latin1", 517 "latin1", 518 "utf8mb4", 519 "utf8mb4", 520 "utf8", 521 "binary", 522 ) 523 524 tk.MustInterDirc(`SET NAMES default`) 525 check( 526 "utf8mb4", 527 "utf8mb4", 528 "utf8mb4", 529 "utf8mb4", 530 "utf8mb4", 531 "utf8", 532 "binary", 533 ) 534 535 // Issue #1523 536 tk.MustInterDirc(`SET NAMES binary`) 537 check( 538 "binary", 539 "binary", 540 "binary", 541 "utf8mb4", 542 "utf8mb4", 543 "utf8", 544 "binary", 545 ) 546 547 tk.MustInterDirc(`SET NAMES utf8`) 548 check( 549 "utf8", 550 "utf8", 551 "utf8", 552 "utf8mb4", 553 "utf8mb4", 554 "utf8", 555 "binary", 556 ) 557 558 tk.MustInterDirc(`SET CHARACTER SET latin1`) 559 check( 560 "latin1", 561 "utf8mb4", 562 "latin1", 563 "utf8mb4", 564 "utf8mb4", 565 "utf8", 566 "binary", 567 ) 568 569 tk.MustInterDirc(`SET CHARACTER SET default`) 570 check( 571 "utf8mb4", 572 "utf8mb4", 573 "utf8mb4", 574 "utf8mb4", 575 "utf8mb4", 576 "utf8", 577 "binary", 578 ) 579 } 580 581 func (s *testSuite5) TestValidateSetVar(c *C) { 582 tk := testkit.NewTestKit(c, s.causetstore) 583 584 _, err := tk.InterDirc("set global milevadb_allegrosql_scan_concurrency='fff';") 585 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue, Commentf("err %v", err)) 586 587 _, err = tk.InterDirc("set global milevadb_allegrosql_scan_concurrency=-2;") 588 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 589 590 _, err = tk.InterDirc("set @@milevadb_allegrosql_scan_concurrency='fff';") 591 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue, Commentf("err %v", err)) 592 593 _, err = tk.InterDirc("set @@milevadb_allegrosql_scan_concurrency=-2;") 594 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 595 596 _, err = tk.InterDirc("set @@milevadb_batch_delete='ok';") 597 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 598 599 tk.MustInterDirc("set @@milevadb_batch_delete='On';") 600 tk.MustQuery("select @@milevadb_batch_delete;").Check(testkit.Events("1")) 601 tk.MustInterDirc("set @@milevadb_batch_delete='oFf';") 602 tk.MustQuery("select @@milevadb_batch_delete;").Check(testkit.Events("0")) 603 tk.MustInterDirc("set @@milevadb_batch_delete=1;") 604 tk.MustQuery("select @@milevadb_batch_delete;").Check(testkit.Events("1")) 605 tk.MustInterDirc("set @@milevadb_batch_delete=0;") 606 tk.MustQuery("select @@milevadb_batch_delete;").Check(testkit.Events("0")) 607 608 tk.MustInterDirc("set @@milevadb_opt_agg_push_down=off;") 609 tk.MustQuery("select @@milevadb_opt_agg_push_down;").Check(testkit.Events("0")) 610 611 tk.MustInterDirc("set @@milevadb_constraint_check_in_place=on;") 612 tk.MustQuery("select @@milevadb_constraint_check_in_place;").Check(testkit.Events("1")) 613 614 tk.MustInterDirc("set @@milevadb_general_log=0;") 615 tk.MustQuery("select @@milevadb_general_log;").Check(testkit.Events("0")) 616 617 tk.MustInterDirc("set @@milevadb_pprof_sql_cpu=1;") 618 tk.MustQuery("select @@milevadb_pprof_sql_cpu;").Check(testkit.Events("1")) 619 tk.MustInterDirc("set @@milevadb_pprof_sql_cpu=0;") 620 tk.MustQuery("select @@milevadb_pprof_sql_cpu;").Check(testkit.Events("0")) 621 622 tk.MustInterDirc("set @@milevadb_enable_streaming=1;") 623 tk.MustQuery("select @@milevadb_enable_streaming;").Check(testkit.Events("1")) 624 625 _, err = tk.InterDirc("set @@milevadb_batch_delete=3;") 626 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 627 628 tk.MustInterDirc("set @@group_concat_max_len=1") 629 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect group_concat_max_len value: '1'")) 630 result := tk.MustQuery("select @@group_concat_max_len;") 631 result.Check(testkit.Events("4")) 632 633 _, err = tk.InterDirc("set @@group_concat_max_len = 18446744073709551616") 634 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue, Commentf("err %v", err)) 635 636 // Test illegal type 637 _, err = tk.InterDirc("set @@group_concat_max_len='hello'") 638 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue, Commentf("err %v", err)) 639 640 tk.MustInterDirc("set @@default_week_format=-1") 641 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect default_week_format value: '-1'")) 642 result = tk.MustQuery("select @@default_week_format;") 643 result.Check(testkit.Events("0")) 644 645 tk.MustInterDirc("set @@default_week_format=9") 646 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect default_week_format value: '9'")) 647 result = tk.MustQuery("select @@default_week_format;") 648 result.Check(testkit.Events("7")) 649 650 _, err = tk.InterDirc("set @@error_count = 0") 651 c.Assert(terror.ErrorEqual(err, variable.ErrReadOnly), IsTrue, Commentf("err %v", err)) 652 653 _, err = tk.InterDirc("set @@warning_count = 0") 654 c.Assert(terror.ErrorEqual(err, variable.ErrReadOnly), IsTrue, Commentf("err %v", err)) 655 656 tk.MustInterDirc("set time_zone='SySTeM'") 657 result = tk.MustQuery("select @@time_zone;") 658 result.Check(testkit.Events("SYSTEM")) 659 660 // The following cases test value out of range and illegal type when setting system variables. 661 // See https://dev.allegrosql.com/doc/refman/5.7/en/server-system-variables.html for more details. 662 tk.MustInterDirc("set @@global.max_connections=100001") 663 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect max_connections value: '100001'")) 664 result = tk.MustQuery("select @@global.max_connections;") 665 result.Check(testkit.Events("100000")) 666 667 tk.MustInterDirc("set @@global.max_connections=-1") 668 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect max_connections value: '-1'")) 669 result = tk.MustQuery("select @@global.max_connections;") 670 result.Check(testkit.Events("1")) 671 672 _, err = tk.InterDirc("set @@global.max_connections='hello'") 673 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) 674 675 tk.MustInterDirc("set @@global.thread_pool_size=65") 676 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect thread_pool_size value: '65'")) 677 result = tk.MustQuery("select @@global.thread_pool_size;") 678 result.Check(testkit.Events("64")) 679 680 tk.MustInterDirc("set @@global.thread_pool_size=-1") 681 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect thread_pool_size value: '-1'")) 682 result = tk.MustQuery("select @@global.thread_pool_size;") 683 result.Check(testkit.Events("1")) 684 685 _, err = tk.InterDirc("set @@global.thread_pool_size='hello'") 686 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) 687 688 tk.MustInterDirc("set @@global.max_allowed_packet=-1") 689 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect max_allowed_packet value: '-1'")) 690 result = tk.MustQuery("select @@global.max_allowed_packet;") 691 result.Check(testkit.Events("1024")) 692 693 _, err = tk.InterDirc("set @@global.max_allowed_packet='hello'") 694 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) 695 696 tk.MustInterDirc("set @@global.max_connect_errors=18446744073709551615") 697 698 tk.MustInterDirc("set @@global.max_connect_errors=-1") 699 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect max_connect_errors value: '-1'")) 700 result = tk.MustQuery("select @@global.max_connect_errors;") 701 result.Check(testkit.Events("1")) 702 703 _, err = tk.InterDirc("set @@global.max_connect_errors=18446744073709551616") 704 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) 705 706 tk.MustInterDirc("set @@global.max_connections=100001") 707 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect max_connections value: '100001'")) 708 result = tk.MustQuery("select @@global.max_connections;") 709 result.Check(testkit.Events("100000")) 710 711 tk.MustInterDirc("set @@global.max_connections=-1") 712 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect max_connections value: '-1'")) 713 result = tk.MustQuery("select @@global.max_connections;") 714 result.Check(testkit.Events("1")) 715 716 _, err = tk.InterDirc("set @@global.max_connections='hello'") 717 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) 718 719 tk.MustInterDirc("set @@max_sort_length=1") 720 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect max_sort_length value: '1'")) 721 result = tk.MustQuery("select @@max_sort_length;") 722 result.Check(testkit.Events("4")) 723 724 tk.MustInterDirc("set @@max_sort_length=-100") 725 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect max_sort_length value: '-100'")) 726 result = tk.MustQuery("select @@max_sort_length;") 727 result.Check(testkit.Events("4")) 728 729 tk.MustInterDirc("set @@max_sort_length=8388609") 730 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect max_sort_length value: '8388609'")) 731 result = tk.MustQuery("select @@max_sort_length;") 732 result.Check(testkit.Events("8388608")) 733 734 _, err = tk.InterDirc("set @@max_sort_length='hello'") 735 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) 736 737 tk.MustInterDirc("set @@global.block_definition_cache=399") 738 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect block_definition_cache value: '399'")) 739 result = tk.MustQuery("select @@global.block_definition_cache;") 740 result.Check(testkit.Events("400")) 741 742 tk.MustInterDirc("set @@global.block_definition_cache=-1") 743 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect block_definition_cache value: '-1'")) 744 result = tk.MustQuery("select @@global.block_definition_cache;") 745 result.Check(testkit.Events("400")) 746 747 tk.MustInterDirc("set @@global.block_definition_cache=524289") 748 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect block_definition_cache value: '524289'")) 749 result = tk.MustQuery("select @@global.block_definition_cache;") 750 result.Check(testkit.Events("524288")) 751 752 _, err = tk.InterDirc("set @@global.block_definition_cache='hello'") 753 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) 754 755 tk.MustInterDirc("set @@old_passwords=-1") 756 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect old_passwords value: '-1'")) 757 result = tk.MustQuery("select @@old_passwords;") 758 result.Check(testkit.Events("0")) 759 760 tk.MustInterDirc("set @@old_passwords=3") 761 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect old_passwords value: '3'")) 762 result = tk.MustQuery("select @@old_passwords;") 763 result.Check(testkit.Events("2")) 764 765 _, err = tk.InterDirc("set @@old_passwords='hello'") 766 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) 767 768 tk.MustInterDirc("set @@tmp_block_size=-1") 769 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect tmp_block_size value: '-1'")) 770 result = tk.MustQuery("select @@tmp_block_size;") 771 result.Check(testkit.Events("1024")) 772 773 tk.MustInterDirc("set @@tmp_block_size=1020") 774 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect tmp_block_size value: '1020'")) 775 result = tk.MustQuery("select @@tmp_block_size;") 776 result.Check(testkit.Events("1024")) 777 778 tk.MustInterDirc("set @@tmp_block_size=167772161") 779 result = tk.MustQuery("select @@tmp_block_size;") 780 result.Check(testkit.Events("167772161")) 781 782 tk.MustInterDirc("set @@tmp_block_size=18446744073709551615") 783 result = tk.MustQuery("select @@tmp_block_size;") 784 result.Check(testkit.Events("18446744073709551615")) 785 786 _, err = tk.InterDirc("set @@tmp_block_size=18446744073709551616") 787 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) 788 789 _, err = tk.InterDirc("set @@tmp_block_size='hello'") 790 c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue) 791 792 tk.MustInterDirc("set @@global.connect_timeout=1") 793 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect connect_timeout value: '1'")) 794 result = tk.MustQuery("select @@global.connect_timeout;") 795 result.Check(testkit.Events("2")) 796 797 tk.MustInterDirc("set @@global.connect_timeout=31536000") 798 result = tk.MustQuery("select @@global.connect_timeout;") 799 result.Check(testkit.Events("31536000")) 800 801 tk.MustInterDirc("set @@global.connect_timeout=31536001") 802 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect connect_timeout value: '31536001'")) 803 result = tk.MustQuery("select @@global.connect_timeout;") 804 result.Check(testkit.Events("31536000")) 805 806 result = tk.MustQuery("select @@sql_select_limit;") 807 result.Check(testkit.Events("18446744073709551615")) 808 tk.MustInterDirc("set @@sql_select_limit=default") 809 result = tk.MustQuery("select @@sql_select_limit;") 810 result.Check(testkit.Events("18446744073709551615")) 811 812 tk.MustInterDirc("set @@sql_auto_is_null=00") 813 result = tk.MustQuery("select @@sql_auto_is_null;") 814 result.Check(testkit.Events("0")) 815 816 tk.MustInterDirc("set @@sql_warnings=001") 817 result = tk.MustQuery("select @@sql_warnings;") 818 result.Check(testkit.Events("1")) 819 820 tk.MustInterDirc("set @@sql_warnings=000") 821 result = tk.MustQuery("select @@sql_warnings;") 822 result.Check(testkit.Events("0")) 823 824 tk.MustInterDirc("set @@global.super_read_only=-0") 825 result = tk.MustQuery("select @@global.super_read_only;") 826 result.Check(testkit.Events("0")) 827 828 _, err = tk.InterDirc("set @@global.super_read_only=-1") 829 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 830 831 tk.MustInterDirc("set @@global.innodb_status_output_locks=-1") 832 result = tk.MustQuery("select @@global.innodb_status_output_locks;") 833 result.Check(testkit.Events("1")) 834 835 tk.MustInterDirc("set @@global.innodb_ft_enable_stopword=0000000") 836 result = tk.MustQuery("select @@global.innodb_ft_enable_stopword;") 837 result.Check(testkit.Events("0")) 838 839 tk.MustInterDirc("set @@global.innodb_stats_on_spacetimedata=1") 840 result = tk.MustQuery("select @@global.innodb_stats_on_spacetimedata;") 841 result.Check(testkit.Events("1")) 842 843 tk.MustInterDirc("set @@global.innodb_file_per_block=-50") 844 result = tk.MustQuery("select @@global.innodb_file_per_block;") 845 result.Check(testkit.Events("1")) 846 847 _, err = tk.InterDirc("set @@global.innodb_ft_enable_stopword=2") 848 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 849 850 tk.MustInterDirc("set @@query_cache_type=0") 851 result = tk.MustQuery("select @@query_cache_type;") 852 result.Check(testkit.Events("OFF")) 853 854 tk.MustInterDirc("set @@query_cache_type=2") 855 result = tk.MustQuery("select @@query_cache_type;") 856 result.Check(testkit.Events("DEMAND")) 857 858 tk.MustInterDirc("set @@global.sync_binlog=-1") 859 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect sync_binlog value: '-1'")) 860 861 tk.MustInterDirc("set @@global.sync_binlog=4294967299") 862 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect sync_binlog value: '4294967299'")) 863 864 tk.MustInterDirc("set @@global.flush_time=31536001") 865 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect flush_time value: '31536001'")) 866 867 tk.MustInterDirc("set @@global.interactive_timeout=31536001") 868 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect interactive_timeout value: '31536001'")) 869 870 tk.MustInterDirc("set @@global.innodb_commit_concurrency = -1") 871 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect innodb_commit_concurrency value: '-1'")) 872 873 tk.MustInterDirc("set @@global.innodb_commit_concurrency = 1001") 874 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect innodb_commit_concurrency value: '1001'")) 875 876 tk.MustInterDirc("set @@global.innodb_fast_shutdown = -1") 877 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect innodb_fast_shutdown value: '-1'")) 878 879 tk.MustInterDirc("set @@global.innodb_fast_shutdown = 3") 880 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect innodb_fast_shutdown value: '3'")) 881 882 tk.MustInterDirc("set @@global.innodb_lock_wait_timeout = 0") 883 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect innodb_lock_wait_timeout value: '0'")) 884 885 tk.MustInterDirc("set @@global.innodb_lock_wait_timeout = 1073741825") 886 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect innodb_lock_wait_timeout value: '1073741825'")) 887 888 tk.MustInterDirc("set @@innodb_lock_wait_timeout = 0") 889 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect innodb_lock_wait_timeout value: '0'")) 890 891 tk.MustInterDirc("set @@innodb_lock_wait_timeout = 1073741825") 892 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect innodb_lock_wait_timeout value: '1073741825'")) 893 894 tk.MustInterDirc("set @@global.validate_password_number_count=-1") 895 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect validate_password_number_count value: '-1'")) 896 897 tk.MustInterDirc("set @@global.validate_password_length=-1") 898 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", "Warning|1292|Truncated incorrect validate_password_length value: '-1'")) 899 900 tk.MustInterDirc("set @@global.validate_password_length=8") 901 tk.MustQuery("show warnings").Check(testkit.Events()) 902 903 _, err = tk.InterDirc("set @@tx_isolation=''") 904 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 905 906 _, err = tk.InterDirc("set global tx_isolation=''") 907 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 908 909 _, err = tk.InterDirc("set @@transaction_isolation=''") 910 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 911 912 _, err = tk.InterDirc("set global transaction_isolation=''") 913 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 914 915 _, err = tk.InterDirc("set global tx_isolation='REPEATABLE-READ1'") 916 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 917 918 tk.MustInterDirc("set @@tx_isolation='READ-COMMITTED'") 919 result = tk.MustQuery("select @@tx_isolation;") 920 result.Check(testkit.Events("READ-COMMITTED")) 921 922 tk.MustInterDirc("set @@tx_isolation='read-COMMITTED'") 923 result = tk.MustQuery("select @@tx_isolation;") 924 result.Check(testkit.Events("READ-COMMITTED")) 925 926 tk.MustInterDirc("set @@tx_isolation='REPEATABLE-READ'") 927 result = tk.MustQuery("select @@tx_isolation;") 928 result.Check(testkit.Events("REPEATABLE-READ")) 929 930 tk.MustInterDirc("SET GLOBAL milevadb_skip_isolation_level_check = 0") 931 tk.MustInterDirc("SET SESSION milevadb_skip_isolation_level_check = 0") 932 _, err = tk.InterDirc("set @@tx_isolation='SERIALIZABLE'") 933 c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedIsolationLevel), IsTrue, Commentf("err %v", err)) 934 935 tk.MustInterDirc("set global allow_auto_random_explicit_insert=on;") 936 tk.MustQuery("select @@global.allow_auto_random_explicit_insert;").Check(testkit.Events("1")) 937 } 938 939 func (s *testSuite5) TestSelectGlobalVar(c *C) { 940 tk := testkit.NewTestKit(c, s.causetstore) 941 942 tk.MustQuery("select @@global.max_connections;").Check(testkit.Events("151")) 943 tk.MustQuery("select @@max_connections;").Check(testkit.Events("151")) 944 945 tk.MustInterDirc("set @@global.max_connections=100;") 946 947 tk.MustQuery("select @@global.max_connections;").Check(testkit.Events("100")) 948 tk.MustQuery("select @@max_connections;").Check(testkit.Events("100")) 949 950 tk.MustInterDirc("set @@global.max_connections=151;") 951 952 // test for unknown variable. 953 err := tk.InterDircToErr("select @@invalid") 954 c.Assert(terror.ErrorEqual(err, variable.ErrUnknownSystemVar), IsTrue, Commentf("err %v", err)) 955 err = tk.InterDircToErr("select @@global.invalid") 956 c.Assert(terror.ErrorEqual(err, variable.ErrUnknownSystemVar), IsTrue, Commentf("err %v", err)) 957 } 958 959 func (s *testSuite5) TestSetConcurrency(c *C) { 960 tk := testkit.NewTestKit(c, s.causetstore) 961 962 // test default value 963 tk.MustQuery("select @@milevadb_interlock_concurrency;").Check(testkit.Events(strconv.Itoa(variable.DefInterlockingDirectorateConcurrency))) 964 965 tk.MustQuery("select @@milevadb_index_lookup_concurrency;").Check(testkit.Events(strconv.Itoa(variable.ConcurrencyUnset))) 966 tk.MustQuery("select @@milevadb_index_lookup_join_concurrency;").Check(testkit.Events(strconv.Itoa(variable.ConcurrencyUnset))) 967 tk.MustQuery("select @@milevadb_hash_join_concurrency;").Check(testkit.Events(strconv.Itoa(variable.ConcurrencyUnset))) 968 tk.MustQuery("select @@milevadb_hashagg_partial_concurrency;").Check(testkit.Events(strconv.Itoa(variable.ConcurrencyUnset))) 969 tk.MustQuery("select @@milevadb_hashagg_final_concurrency;").Check(testkit.Events(strconv.Itoa(variable.ConcurrencyUnset))) 970 tk.MustQuery("select @@milevadb_window_concurrency;").Check(testkit.Events(strconv.Itoa(variable.ConcurrencyUnset))) 971 tk.MustQuery("select @@milevadb_projection_concurrency;").Check(testkit.Events(strconv.Itoa(variable.ConcurrencyUnset))) 972 tk.MustQuery("select @@milevadb_allegrosql_scan_concurrency;").Check(testkit.Events(strconv.Itoa(variable.DefDistALLEGROSQLScanConcurrency))) 973 974 tk.MustQuery("select @@milevadb_index_serial_scan_concurrency;").Check(testkit.Events(strconv.Itoa(variable.DefIndexSerialScanConcurrency))) 975 976 vars := tk.Se.(stochastikctx.Context).GetStochastikVars() 977 c.Assert(vars.InterlockingDirectorateConcurrency, Equals, variable.DefInterlockingDirectorateConcurrency) 978 c.Assert(vars.IndexLookupConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 979 c.Assert(vars.IndexLookupJoinConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 980 c.Assert(vars.HashJoinConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 981 c.Assert(vars.HashAggPartialConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 982 c.Assert(vars.HashAggFinalConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 983 c.Assert(vars.WindowConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 984 c.Assert(vars.ProjectionConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 985 c.Assert(vars.DistALLEGROSQLScanConcurrency(), Equals, variable.DefDistALLEGROSQLScanConcurrency) 986 987 c.Assert(vars.IndexSerialScanConcurrency(), Equals, variable.DefIndexSerialScanConcurrency) 988 989 // test setting deprecated variables 990 warnTpl := "Warning 1287 '%s' is deprecated and will be removed in a future release. Please use milevadb_interlock_concurrency instead" 991 992 checkSet := func(v string) { 993 tk.MustInterDirc(fmt.Sprintf("set @@%s=1;", v)) 994 tk.MustQuery("show warnings").Check(solitonutil.EventsWithSep("|", fmt.Sprintf(warnTpl, v))) 995 tk.MustQuery(fmt.Sprintf("select @@%s;", v)).Check(testkit.Events("1")) 996 } 997 998 checkSet(variable.MilevaDBIndexLookupConcurrency) 999 c.Assert(vars.IndexLookupConcurrency(), Equals, 1) 1000 1001 checkSet(variable.MilevaDBIndexLookupJoinConcurrency) 1002 c.Assert(vars.IndexLookupJoinConcurrency(), Equals, 1) 1003 1004 checkSet(variable.MilevaDBHashJoinConcurrency) 1005 c.Assert(vars.HashJoinConcurrency(), Equals, 1) 1006 1007 checkSet(variable.MilevaDBHashAggPartialConcurrency) 1008 c.Assert(vars.HashAggPartialConcurrency(), Equals, 1) 1009 1010 checkSet(variable.MilevaDBHashAggFinalConcurrency) 1011 c.Assert(vars.HashAggFinalConcurrency(), Equals, 1) 1012 1013 checkSet(variable.MilevaDBProjectionConcurrency) 1014 c.Assert(vars.ProjectionConcurrency(), Equals, 1) 1015 1016 checkSet(variable.MilevaDBWindowConcurrency) 1017 c.Assert(vars.WindowConcurrency(), Equals, 1) 1018 1019 tk.MustInterDirc(fmt.Sprintf("set @@%s=1;", variable.MilevaDBDistALLEGROSQLScanConcurrency)) 1020 tk.MustQuery(fmt.Sprintf("select @@%s;", variable.MilevaDBDistALLEGROSQLScanConcurrency)).Check(testkit.Events("1")) 1021 c.Assert(vars.DistALLEGROSQLScanConcurrency(), Equals, 1) 1022 1023 tk.MustInterDirc("set @@milevadb_index_serial_scan_concurrency=4") 1024 tk.MustQuery("show warnings").Check(testkit.Events()) 1025 tk.MustQuery("select @@milevadb_index_serial_scan_concurrency;").Check(testkit.Events("4")) 1026 c.Assert(vars.IndexSerialScanConcurrency(), Equals, 4) 1027 1028 // test setting deprecated value unset 1029 tk.MustInterDirc("set @@milevadb_index_lookup_concurrency=-1;") 1030 tk.MustInterDirc("set @@milevadb_index_lookup_join_concurrency=-1;") 1031 tk.MustInterDirc("set @@milevadb_hash_join_concurrency=-1;") 1032 tk.MustInterDirc("set @@milevadb_hashagg_partial_concurrency=-1;") 1033 tk.MustInterDirc("set @@milevadb_hashagg_final_concurrency=-1;") 1034 tk.MustInterDirc("set @@milevadb_window_concurrency=-1;") 1035 tk.MustInterDirc("set @@milevadb_projection_concurrency=-1;") 1036 1037 c.Assert(vars.IndexLookupConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 1038 c.Assert(vars.IndexLookupJoinConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 1039 c.Assert(vars.HashJoinConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 1040 c.Assert(vars.HashAggPartialConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 1041 c.Assert(vars.HashAggFinalConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 1042 c.Assert(vars.WindowConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 1043 c.Assert(vars.ProjectionConcurrency(), Equals, variable.DefInterlockingDirectorateConcurrency) 1044 1045 _, err := tk.InterDirc("set @@milevadb_interlock_concurrency=-1;") 1046 c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err)) 1047 } 1048 1049 func (s *testSuite5) TestEnableNoopFunctionsVar(c *C) { 1050 tk := testkit.NewTestKit(c, s.causetstore) 1051 1052 // test for milevadb_enable_noop_functions 1053 tk.MustQuery(`select @@global.milevadb_enable_noop_functions;`).Check(testkit.Events("0")) 1054 tk.MustQuery(`select @@milevadb_enable_noop_functions;`).Check(testkit.Events("0")) 1055 1056 _, err := tk.InterDirc(`select get_lock('lock1', 2);`) 1057 c.Assert(terror.ErrorEqual(err, memex.ErrFunctionsNoopImpl), IsTrue, Commentf("err %v", err)) 1058 _, err = tk.InterDirc(`select release_lock('lock1');`) 1059 c.Assert(terror.ErrorEqual(err, memex.ErrFunctionsNoopImpl), IsTrue, Commentf("err %v", err)) 1060 1061 // change stochastik var to 1 1062 tk.MustInterDirc(`set milevadb_enable_noop_functions=1;`) 1063 tk.MustQuery(`select @@milevadb_enable_noop_functions;`).Check(testkit.Events("1")) 1064 tk.MustQuery(`select @@global.milevadb_enable_noop_functions;`).Check(testkit.Events("0")) 1065 tk.MustQuery(`select get_lock("dagger", 10)`).Check(testkit.Events("1")) 1066 tk.MustQuery(`select release_lock("dagger")`).Check(testkit.Events("1")) 1067 1068 // restore to 0 1069 tk.MustInterDirc(`set milevadb_enable_noop_functions=0;`) 1070 tk.MustQuery(`select @@milevadb_enable_noop_functions;`).Check(testkit.Events("0")) 1071 tk.MustQuery(`select @@global.milevadb_enable_noop_functions;`).Check(testkit.Events("0")) 1072 1073 _, err = tk.InterDirc(`select get_lock('lock2', 10);`) 1074 c.Assert(terror.ErrorEqual(err, memex.ErrFunctionsNoopImpl), IsTrue, Commentf("err %v", err)) 1075 _, err = tk.InterDirc(`select release_lock('lock2');`) 1076 c.Assert(terror.ErrorEqual(err, memex.ErrFunctionsNoopImpl), IsTrue, Commentf("err %v", err)) 1077 1078 // set test 1079 _, err = tk.InterDirc(`set milevadb_enable_noop_functions='abc'`) 1080 c.Assert(err, NotNil) 1081 _, err = tk.InterDirc(`set milevadb_enable_noop_functions=11`) 1082 c.Assert(err, NotNil) 1083 tk.MustInterDirc(`set milevadb_enable_noop_functions="off";`) 1084 tk.MustQuery(`select @@milevadb_enable_noop_functions;`).Check(testkit.Events("0")) 1085 tk.MustInterDirc(`set milevadb_enable_noop_functions="on";`) 1086 tk.MustQuery(`select @@milevadb_enable_noop_functions;`).Check(testkit.Events("1")) 1087 tk.MustInterDirc(`set milevadb_enable_noop_functions=0;`) 1088 tk.MustQuery(`select @@milevadb_enable_noop_functions;`).Check(testkit.Events("0")) 1089 } 1090 1091 func (s *testSuite5) TestSetClusterConfig(c *C) { 1092 tk := testkit.NewTestKit(c, s.causetstore) 1093 tk.MustInterDirc("use test") 1094 1095 serversInfo := []schemareplicant.ServerInfo{ 1096 {ServerType: "milevadb", Address: "127.0.0.1:1111", StatusAddr: "127.0.0.1:1111"}, 1097 {ServerType: "milevadb", Address: "127.0.0.1:2222", StatusAddr: "127.0.0.1:2222"}, 1098 {ServerType: "fidel", Address: "127.0.0.1:3333", StatusAddr: "127.0.0.1:3333"}, 1099 {ServerType: "fidel", Address: "127.0.0.1:4444", StatusAddr: "127.0.0.1:4444"}, 1100 {ServerType: "einsteindb", Address: "127.0.0.1:5555", StatusAddr: "127.0.0.1:5555"}, 1101 {ServerType: "einsteindb", Address: "127.0.0.1:6666", StatusAddr: "127.0.0.1:6666"}, 1102 } 1103 var serverInfoErr error 1104 serverInfoFunc := func(stochastikctx.Context) ([]schemareplicant.ServerInfo, error) { 1105 return serversInfo, serverInfoErr 1106 } 1107 tk.Se.SetValue(interlock.TestSetConfigServerInfoKey, serverInfoFunc) 1108 1109 c.Assert(tk.InterDircToErr("set config xxx log.level='info'"), ErrorMatches, "unknown type xxx") 1110 c.Assert(tk.InterDircToErr("set config milevadb log.level='info'"), ErrorMatches, "MilevaDB doesn't support to change configs online, please use ALLEGROALLEGROSQL variables") 1111 c.Assert(tk.InterDircToErr("set config '127.0.0.1:1111' log.level='info'"), ErrorMatches, "MilevaDB doesn't support to change configs online, please use ALLEGROALLEGROSQL variables") 1112 c.Assert(tk.InterDircToErr("set config '127.a.b.c:1234' log.level='info'"), ErrorMatches, "invalid instance 127.a.b.c:1234") 1113 c.Assert(tk.InterDircToErr("set config einsteindb log.level=null"), ErrorMatches, "can't set config to null") 1114 c.Assert(tk.InterDircToErr("set config '1.1.1.1:1111' log.level='info'"), ErrorMatches, "instance 1.1.1.1:1111 is not found in this cluster") 1115 1116 httpCnt := 0 1117 tk.Se.SetValue(interlock.TestSetConfigHTTPHandlerKey, func(*http.Request) (*http.Response, error) { 1118 httpCnt++ 1119 return &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(nil)}, nil 1120 }) 1121 tk.MustInterDirc("set config einsteindb log.level='info'") 1122 c.Assert(httpCnt, Equals, 2) 1123 1124 httpCnt = 0 1125 tk.MustInterDirc("set config '127.0.0.1:5555' log.level='info'") 1126 c.Assert(httpCnt, Equals, 1) 1127 1128 httpCnt = 0 1129 tk.Se.SetValue(interlock.TestSetConfigHTTPHandlerKey, func(*http.Request) (*http.Response, error) { 1130 return nil, errors.New("something wrong") 1131 }) 1132 tk.MustInterDirc("set config einsteindb log.level='info'") 1133 tk.MustQuery("show warnings").Check(testkit.Events( 1134 "Warning 1105 something wrong", "Warning 1105 something wrong")) 1135 1136 tk.Se.SetValue(interlock.TestSetConfigHTTPHandlerKey, func(*http.Request) (*http.Response, error) { 1137 return &http.Response{StatusCode: http.StatusBadRequest, Body: ioutil.NopCloser(bytes.NewBufferString("WRONG"))}, nil 1138 }) 1139 tk.MustInterDirc("set config einsteindb log.level='info'") 1140 tk.MustQuery("show warnings").Check(testkit.Events( 1141 "Warning 1105 bad request to http://127.0.0.1:5555/config: WRONG", "Warning 1105 bad request to http://127.0.0.1:6666/config: WRONG")) 1142 } 1143 1144 func (s *testSuite5) TestSetClusterConfigJSONData(c *C) { 1145 var d types.MyDecimal 1146 c.Assert(d.FromFloat64(123.456), IsNil) 1147 tyBool := types.NewFieldType(allegrosql.TypeTiny) 1148 tyBool.Flag |= allegrosql.IsBooleanFlag 1149 cases := []struct { 1150 val memex.Expression 1151 result string 1152 succ bool 1153 }{ 1154 {&memex.Constant{Value: types.NewIntCauset(1), RetType: tyBool}, `{"k":true}`, true}, 1155 {&memex.Constant{Value: types.NewIntCauset(0), RetType: tyBool}, `{"k":false}`, true}, 1156 {&memex.Constant{Value: types.NewIntCauset(2333), RetType: types.NewFieldType(allegrosql.TypeLong)}, `{"k":2333}`, true}, 1157 {&memex.Constant{Value: types.NewFloat64Causet(23.33), RetType: types.NewFieldType(allegrosql.TypeDouble)}, `{"k":23.33}`, true}, 1158 {&memex.Constant{Value: types.NewStringCauset("abcd"), RetType: types.NewFieldType(allegrosql.TypeString)}, `{"k":"abcd"}`, true}, 1159 {&memex.Constant{Value: types.NewDecimalCauset(&d), RetType: types.NewFieldType(allegrosql.TypeNewDecimal)}, `{"k":123.456}`, true}, 1160 {&memex.Constant{Value: types.NewCauset(nil), RetType: types.NewFieldType(allegrosql.TypeLonglong)}, "", false}, 1161 {&memex.Constant{RetType: types.NewFieldType(allegrosql.TypeJSON)}, "", false}, // unsupported type 1162 {nil, "", false}, 1163 } 1164 1165 ctx := mock.NewContext() 1166 for _, t := range cases { 1167 result, err := interlock.ConvertConfigItem2JSON(ctx, "k", t.val) 1168 if t.succ { 1169 c.Assert(t.result, Equals, result) 1170 } else { 1171 c.Assert(err, NotNil) 1172 } 1173 } 1174 }