@@ -21,13 +21,16 @@ import (
21
21
"fmt"
22
22
"io"
23
23
"math/rand"
24
+ "os"
24
25
"testing"
25
26
26
27
mysqlcursor "github.com/YangKeao/go-mysql-driver"
27
28
"github.com/pingcap/failpoint"
28
29
"github.com/pingcap/tidb/pkg/config"
30
+ "github.com/pingcap/tidb/pkg/executor"
29
31
tmysql "github.com/pingcap/tidb/pkg/parser/mysql"
30
32
server2 "github.com/pingcap/tidb/pkg/server"
33
+ util2 "github.com/pingcap/tidb/pkg/server/internal/util"
31
34
"github.com/pingcap/tidb/pkg/server/tests/servertestkit"
32
35
"github.com/pingcap/tidb/pkg/testkit"
33
36
"github.com/stretchr/testify/require"
@@ -506,3 +509,49 @@ outerLoop:
506
509
}
507
510
}
508
511
}
512
+
513
+ func TestCursorExceedQuota (t * testing.T ) {
514
+ cfg := util2 .NewTestConfig ()
515
+ require .NoError (t , os .RemoveAll (cfg .TempStoragePath ))
516
+ require .NoError (t , os .MkdirAll (cfg .TempStoragePath , 0o755 ))
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
+ // panic will close the connection, and the statement inside.
551
+ require .Contains (t , err .Error (), "Out Of Quota For Local Temporary Space!" )
552
+
553
+ tempStoragePath := cfg .TempStoragePath
554
+ files , err := os .ReadDir (tempStoragePath )
555
+ require .NoError (t , err )
556
+ require .Empty (t , files )
557
+ }
0 commit comments