@@ -352,7 +352,100 @@ func TestResourceGroupRunaway(t *testing.T) {
352
352
tk .MustGetErrCode ("select /*+ resource_group(rg4) */ * from t" , mysql .ErrResourceGroupQueryRunawayQuarantine )
353
353
tk .EventuallyMustQueryAndCheck ("select SQL_NO_CACHE resource_group_name, watch_text from mysql.tidb_runaway_watch" , nil ,
354
354
testkit .Rows ("rg3 select /*+ resource_group(rg3) */ * from t" , "rg4 select /*+ resource_group(rg4) */ * from t" ), maxWaitDuration , tryInterval )
355
+ << << << < HEAD:pkg / ddl / tests / resourcegroup / resource_group_test .go
355
356
require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/store/copr/sleepCoprAfterReq" ))
357
+ == == == =
358
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/resourcegroup/runaway/checkThresholds" ))
359
+
360
+ tk .MustExec ("create resource group rg5 BURSTABLE=UNLIMITED RU_PER_SEC=2000 QUERY_LIMIT=(PROCESSED_KEYS=10 action KILL WATCH EXACT)" )
361
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/resourcegroup/runaway/checkThresholds" , "return(true)" ))
362
+ err = tk .QueryToErr ("select /*+ resource_group(rg5) */ * from t" )
363
+ require .ErrorContains (t , err , "Query execution was interrupted, identified as runaway query" )
364
+ tk .MustGetErrCode ("select /*+ resource_group(rg5) */ * from t" , mysql .ErrResourceGroupQueryRunawayQuarantine )
365
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/resourcegroup/runaway/checkThresholds" ))
366
+ }
367
+
368
+ func TestResourceGroupRunawayExceedTiDBSide (t * testing.T ) {
369
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/resourcegroup/runaway/FastRunawayGC" , `return(true)` ))
370
+ defer func () {
371
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/resourcegroup/runaway/FastRunawayGC" ))
372
+ }()
373
+ store , dom := testkit .CreateMockStoreAndDomain (t )
374
+ sv := server .CreateMockServer (t , store )
375
+ sv .SetDomain (dom )
376
+ defer sv .Close ()
377
+
378
+ conn1 := server .CreateMockConn (t , sv )
379
+ tk := testkit .NewTestKitWithSession (t , store , conn1 .Context ().Session )
380
+
381
+ go dom .ExpensiveQueryHandle ().SetSessionManager (sv ).Run ()
382
+ tk .MustExec ("set global tidb_enable_resource_control='on'" )
383
+ require .NoError (t , tk .Session ().Auth (& auth.UserIdentity {Username : "root" , Hostname : "localhost" }, nil , nil , nil ))
384
+
385
+ tk .MustExec ("use test" )
386
+ tk .MustExec ("create table t(a int)" )
387
+ tk .MustExec ("insert into t values(1)" )
388
+ tk .MustExec ("create resource group rg1 RU_PER_SEC=1000 QUERY_LIMIT=(EXEC_ELAPSED='50ms' ACTION=KILL)" )
389
+
390
+ err := tk .QueryToErr ("select /*+ resource_group(rg1) */ sleep(0.5) from t" )
391
+ require .ErrorContains (t , err , "[executor:8253]Query execution was interrupted, identified as runaway query" )
392
+
393
+ tryInterval := time .Millisecond * 100
394
+ maxWaitDuration := time .Second * 5
395
+ tk .EventuallyMustQueryAndCheck ("select SQL_NO_CACHE resource_group_name, sample_sql, match_type from mysql.tidb_runaway_queries" , nil ,
396
+ testkit .Rows ("rg1 select /*+ resource_group(rg1) */ sleep(0.5) from t identify" ), maxWaitDuration , tryInterval )
397
+ tk .EventuallyMustQueryAndCheck ("select SQL_NO_CACHE resource_group_name, sample_sql, start_time from mysql.tidb_runaway_queries" , nil ,
398
+ nil , maxWaitDuration , tryInterval )
399
+ }
400
+
401
+ func TestResourceGroupRunawayFlood (t * testing.T ) {
402
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/resourcegroup/runaway/FastRunawayGC" , `return(true)` ))
403
+ defer func () {
404
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/resourcegroup/runaway/FastRunawayGC" ))
405
+ }()
406
+ store := testkit .CreateMockStore (t )
407
+ tk := testkit .NewTestKit (t , store )
408
+ require .NoError (t , tk .Session ().Auth (& auth.UserIdentity {Username : "root" , Hostname : "localhost" }, nil , nil , nil ))
409
+
410
+ tk .MustExec ("use test" )
411
+ tk .MustExec ("create table t(a int)" )
412
+ tk .MustExec ("insert into t values(1)" )
413
+ tk .MustExec ("set global tidb_enable_resource_control='on'" )
414
+ tk .MustExec ("create resource group rg1 RU_PER_SEC=1000 QUERY_LIMIT=(EXEC_ELAPSED='50ms' ACTION=KILL)" )
415
+ tk .MustQuery ("select /*+ resource_group(rg1) */ * from t" ).Check (testkit .Rows ("1" ))
416
+
417
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/store/copr/sleepCoprRequest" , fmt .Sprintf ("return(%d)" , 60 )))
418
+ defer func () {
419
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/store/copr/sleepCoprRequest" ))
420
+ }()
421
+ err := tk .QueryToErr ("select /*+ resource_group(rg1) */ sleep(0.1) from t" )
422
+ require .ErrorContains (t , err , "Query execution was interrupted, identified as runaway query" )
423
+
424
+ tryInterval := time .Millisecond * 100
425
+ maxWaitDuration := time .Second * 5
426
+ tk .EventuallyMustQueryAndCheck ("select SQL_NO_CACHE resource_group_name, sample_sql, repeats, match_type from mysql.tidb_runaway_queries" , nil ,
427
+ testkit .Rows ("rg1 select /*+ resource_group(rg1) */ sleep(0.1) from t 1 identify" ), maxWaitDuration , tryInterval )
428
+ // wait for the runaway watch to be cleaned up
429
+ tk .EventuallyMustQueryAndCheck ("select SQL_NO_CACHE resource_group_name, sample_sql, repeats from mysql.tidb_runaway_queries" , nil ,
430
+ nil , maxWaitDuration , tryInterval )
431
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/resourcegroup/runaway/FastRunawayGC" ))
432
+
433
+ // check thrice to make sure the runaway query be regarded as a repeated query.
434
+ err = tk .QueryToErr ("select /*+ resource_group(rg1) */ sleep(0.2) from t" )
435
+ require .ErrorContains (t , err , "Query execution was interrupted, identified as runaway query" )
436
+ err = tk .QueryToErr ("select /*+ resource_group(rg1) */ sleep(0.3) from t" )
437
+ require .ErrorContains (t , err , "Query execution was interrupted, identified as runaway query" )
438
+ // using FastRunawayGC to trigger flush
439
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/resourcegroup/runaway/FastRunawayGC" , `return(true)` ))
440
+ err = tk .QueryToErr ("select /*+ resource_group(rg1) */ sleep(0.4) from t" )
441
+ require .ErrorContains (t , err , "Query execution was interrupted, identified as runaway query" )
442
+ // only have one runaway query
443
+ tk .EventuallyMustQueryAndCheck ("select SQL_NO_CACHE resource_group_name, sample_sql, repeats, match_type from mysql.tidb_runaway_queries" , nil ,
444
+ testkit .Rows ("rg1 select /*+ resource_group(rg1) */ sleep(0.2) from t 3 identify" ), maxWaitDuration , tryInterval )
445
+ // wait for the runaway watch to be cleaned up
446
+ tk .EventuallyMustQueryAndCheck ("select SQL_NO_CACHE resource_group_name, sample_sql, repeats from mysql.tidb_runaway_queries" , nil ,
447
+ nil , maxWaitDuration , tryInterval )
448
+ >> >> >> > 2 d0da8ee789 (fix (runaway ): resolve the dead channel in UpdateNewAndDoneWatch (#61795 )):pkg / resourcegroup / tests / resource_group_test .go
356
449
}
357
450
358
451
func TestAlreadyExistsDefaultResourceGroup (t * testing.T ) {
0 commit comments