Skip to content

Commit dee4b45

Browse files
authored
ddl: remove mock.Context ref in ddl/session/session_pool.go (#53378)
close #53377
1 parent 044f113 commit dee4b45

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

pkg/ddl/export_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"time"
2020

21+
"github.com/ngaut/pools"
2122
"github.com/pingcap/tidb/pkg/ddl/copr"
2223
"github.com/pingcap/tidb/pkg/ddl/internal/session"
2324
"github.com/pingcap/tidb/pkg/kv"
@@ -26,6 +27,7 @@ import (
2627
"github.com/pingcap/tidb/pkg/table"
2728
"github.com/pingcap/tidb/pkg/types"
2829
"github.com/pingcap/tidb/pkg/util/chunk"
30+
"github.com/pingcap/tidb/pkg/util/mock"
2931
)
3032

3133
type resultChanForTest struct {
@@ -47,14 +49,20 @@ func FetchChunk4Test(copCtx copr.CopContext, tbl table.PhysicalTable, startKey,
4749
}
4850
taskCh := make(chan *reorgBackfillTask, 5)
4951
resultCh := make(chan IndexRecordChunk, 5)
50-
sessPool := session.NewSessionPool(nil, store)
52+
resPool := pools.NewResourcePool(func() (pools.Resource, error) {
53+
ctx := mock.NewContext()
54+
ctx.Store = store
55+
return ctx, nil
56+
}, 8, 8, 0)
57+
sessPool := session.NewSessionPool(resPool, store)
5158
pool := newCopReqSenderPool(context.Background(), copCtx, store, taskCh, sessPool, nil)
5259
pool.chunkSender = &resultChanForTest{ch: resultCh}
5360
pool.adjustSize(1)
5461
pool.tasksCh <- task
5562
rs := <-resultCh
5663
close(taskCh)
5764
pool.close(false)
65+
sessPool.Close()
5866
return rs.Chunk
5967
}
6068

pkg/ddl/internal/session/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ go_library(
1818
"//pkg/sessionctx",
1919
"//pkg/sessiontxn",
2020
"//pkg/util/chunk",
21-
"//pkg/util/mock",
21+
"//pkg/util/intest",
2222
"//pkg/util/sqlexec",
2323
"@com_github_ngaut_pools//:pools",
2424
"@com_github_pingcap_errors//:errors",

pkg/ddl/internal/session/session_pool.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/pingcap/tidb/pkg/kv"
2626
"github.com/pingcap/tidb/pkg/parser/mysql"
2727
"github.com/pingcap/tidb/pkg/sessionctx"
28-
"github.com/pingcap/tidb/pkg/util/mock"
28+
"github.com/pingcap/tidb/pkg/util/intest"
2929
)
3030

3131
// Pool is used to new Session.
@@ -40,18 +40,14 @@ type Pool struct {
4040

4141
// NewSessionPool creates a new Session pool.
4242
func NewSessionPool(resPool *pools.ResourcePool, store kv.Storage) *Pool {
43+
intest.AssertNotNil(resPool)
44+
intest.AssertNotNil(store)
4345
return &Pool{resPool: resPool, store: store}
4446
}
4547

4648
// Get gets sessionCtx from context resource pool.
4749
// Please remember to call Put after you finished using sessionCtx.
4850
func (sg *Pool) Get() (sessionctx.Context, error) {
49-
if sg.resPool == nil {
50-
ctx := mock.NewContext()
51-
ctx.Store = sg.store
52-
return ctx, nil
53-
}
54-
5551
sg.mu.Lock()
5652
if sg.mu.closed {
5753
sg.mu.Unlock()
@@ -78,10 +74,6 @@ func (sg *Pool) Get() (sessionctx.Context, error) {
7874

7975
// Put returns sessionCtx to context resource pool.
8076
func (sg *Pool) Put(ctx sessionctx.Context) {
81-
if sg.resPool == nil {
82-
return
83-
}
84-
8577
// no need to protect sg.resPool, even the sg.resPool is closed, the ctx still need to
8678
// Put into resPool, because when resPool is closing, it will wait all the ctx returns, then resPool finish closing.
8779
sg.resPool.Put(ctx.(pools.Resource))
@@ -93,7 +85,7 @@ func (sg *Pool) Close() {
9385
sg.mu.Lock()
9486
defer sg.mu.Unlock()
9587
// prevent closing resPool twice.
96-
if sg.mu.closed || sg.resPool == nil {
88+
if sg.mu.closed {
9789
return
9890
}
9991
logutil.DDLLogger().Info("closing session pool")

0 commit comments

Comments
 (0)