@@ -21,13 +21,17 @@ import (
21
21
"fmt"
22
22
"io"
23
23
"math/rand"
24
+ "os"
24
25
"testing"
26
+ "time"
25
27
26
28
mysqlcursor "github.com/YangKeao/go-mysql-driver"
27
29
"github.com/pingcap/failpoint"
28
30
"github.com/pingcap/tidb/pkg/config"
31
+ "github.com/pingcap/tidb/pkg/executor"
29
32
tmysql "github.com/pingcap/tidb/pkg/parser/mysql"
30
33
server2 "github.com/pingcap/tidb/pkg/server"
34
+ util2 "github.com/pingcap/tidb/pkg/server/internal/util"
31
35
"github.com/pingcap/tidb/pkg/server/tests/servertestkit"
32
36
"github.com/pingcap/tidb/pkg/testkit"
33
37
"github.com/stretchr/testify/require"
@@ -506,3 +510,51 @@ outerLoop:
506
510
}
507
511
}
508
512
}
513
+
514
+ func TestCursorExceedQuota (t * testing.T ) {
515
+ cfg := util2 .NewTestConfig ()
516
+ cfg .TempStoragePath = t .TempDir ()
517
+
518
+ cfg .Port = 0
519
+ cfg .Status .StatusPort = 0
520
+ cfg .TempStorageQuota = 1000
521
+ executor .GlobalDiskUsageTracker .SetBytesLimit (cfg .TempStorageQuota )
522
+ ts := servertestkit .CreateTidbTestSuiteWithCfg (t , cfg )
523
+
524
+ mysqldriver := & mysqlcursor.MySQLDriver {}
525
+ rawConn , err := mysqldriver .Open (ts .GetDSNWithCursor (10 ))
526
+ require .NoError (t , err )
527
+ conn := rawConn .(mysqlcursor.Connection )
528
+
529
+ _ , err = conn .ExecContext (context .Background (), "drop table if exists t1" , nil )
530
+ require .NoError (t , err )
531
+ _ , err = conn .ExecContext (context .Background (), "CREATE TABLE `t1` (`c1` varchar(100));" , nil )
532
+ require .NoError (t , err )
533
+ rowCount := 1000
534
+ for i := 0 ; i < rowCount ; i ++ {
535
+ _ , err = conn .ExecContext (context .Background (), "insert into t1 (c1) values ('201801');" , nil )
536
+ require .NoError (t , err )
537
+ }
538
+
539
+ _ , err = conn .ExecContext (context .Background (), "set tidb_mem_quota_query = 1;" , nil )
540
+ require .NoError (t , err )
541
+ _ , err = conn .ExecContext (context .Background (), "set global tidb_enable_tmp_storage_on_oom = 'ON'" , nil )
542
+ require .NoError (t , err )
543
+
544
+ rawStmt , err := conn .Prepare ("SELECT * FROM test.t1" )
545
+ require .NoError (t , err )
546
+ stmt := rawStmt .(mysqlcursor.Statement )
547
+
548
+ _ , err = stmt .QueryContext (context .Background (), nil )
549
+ require .Error (t , err )
550
+ require .Contains (t , err .Error (), "Out Of Quota For Local Temporary Space!" )
551
+
552
+ require .NoError (t , conn .Close ())
553
+
554
+ time .Sleep (time .Second )
555
+
556
+ tempStoragePath := cfg .TempStoragePath
557
+ files , err := os .ReadDir (tempStoragePath )
558
+ require .NoError (t , err )
559
+ require .Empty (t , files )
560
+ }
0 commit comments