(t *testing.T)
| 38 | ) |
| 39 | |
| 40 | func TestCursorFetchErrorInFetch(t *testing.T) { |
| 41 | tmpStoragePath := t.TempDir() |
| 42 | restore := config.RestoreFunc() |
| 43 | defer restore() |
| 44 | config.UpdateGlobal(func(conf *config.Config) { |
| 45 | conf.TempStoragePath = tmpStoragePath |
| 46 | }) |
| 47 | |
| 48 | store, dom := testkit.CreateMockStoreAndDomain(t) |
| 49 | srv := server2.CreateMockServer(t, store) |
| 50 | srv.SetDomain(dom) |
| 51 | defer srv.Close() |
| 52 | |
| 53 | appendUint32 := binary.LittleEndian.AppendUint32 |
| 54 | ctx := context.Background() |
| 55 | c := server2.CreateMockConn(t, srv) |
| 56 | |
| 57 | tk := testkit.NewTestKitWithSession(t, store, c.Context().Session) |
| 58 | tk.MustExec("use test") |
| 59 | tk.MustExec("drop table if exists t") |
| 60 | tk.MustExec("create table t(id int, payload BLOB)") |
| 61 | payload := make([]byte, 512) |
| 62 | for i := 0; i < 2048; i++ { |
| 63 | rand.Read(payload) |
| 64 | tk.MustExec("insert into t values (?, ?)", i, payload) |
| 65 | } |
| 66 | |
| 67 | tk.MustExec("set global tidb_enable_tmp_storage_on_oom = ON") |
| 68 | tk.MustExec("set global tidb_mem_oom_action = 'CANCEL'") |
| 69 | defer tk.MustExec("set global tidb_mem_oom_action= DEFAULT") |
| 70 | require.Len(t, tk.Session().GetSessionVars().MemTracker.GetChildrenForTest(), 1) |
| 71 | |
| 72 | // execute a normal statement, it'll spill to disk |
| 73 | stmt, _, _, err := c.Context().Prepare("select * from t") |
| 74 | require.NoError(t, err) |
| 75 | |
| 76 | tk.MustExec(fmt.Sprintf("set tidb_mem_quota_query=%d", 1)) |
| 77 | |
| 78 | require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/util/chunk/get-chunk-error", "return(true)")) |
| 79 | defer func() { |
| 80 | require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/util/chunk/get-chunk-error")) |
| 81 | }() |
| 82 | |
| 83 | require.NoError(t, c.Dispatch(ctx, append( |
| 84 | appendUint32([]byte{tmysql.ComStmtExecute}, uint32(stmt.ID())), |
| 85 | tmysql.CursorTypeReadOnly, 0x1, 0x0, 0x0, 0x0, |
| 86 | ))) |
| 87 | |
| 88 | require.ErrorContains(t, c.Dispatch(ctx, appendUint32(appendUint32([]byte{tmysql.ComStmtFetch}, uint32(stmt.ID())), 1024)), "fail to get chunk for test") |
| 89 | // after getting a failed FETCH, the cursor should have been reseted |
| 90 | require.False(t, stmt.GetCursorActive()) |
| 91 | require.Len(t, tk.Session().GetSessionVars().MemTracker.GetChildrenForTest(), 0) |
| 92 | require.Len(t, tk.Session().GetSessionVars().DiskTracker.GetChildrenForTest(), 0) |
| 93 | } |
| 94 | |
| 95 | func TestCursorFetchShouldSpill(t *testing.T) { |
| 96 | restore := config.RestoreFunc() |
nothing calls this directly
no test coverage detected