Skip to content

Commit 8acfef8

Browse files
authored
domain: separate session pool for DXF service (pingcap#62855)
ref pingcap#61702
1 parent 2d07f5c commit 8acfef8

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

pkg/domain/domain.go

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ var (
127127
)
128128

129129
const (
130-
indexUsageGCDuration = 30 * time.Minute
130+
indexUsageGCDuration = 30 * time.Minute
131+
systemSessionPoolSize = 200
132+
dxfSessionPoolSize = 100
131133
)
132134

133135
// NewMockDomain is only used for test
@@ -162,6 +164,7 @@ type Domain struct {
162164
// Otherwise, the session will be leaked. Because there is a strong reference from the domain to the session.
163165
// Deprecated: Use `advancedSysSessionPool` instead.
164166
sysSessionPool util.DestroyableSessionPool
167+
dxfSessionPool util.DestroyableSessionPool
165168
exit chan struct{}
166169
// `etcdClient` must be used when keyspace is not set, or when the logic to each etcd path needs to be separated by keyspace.
167170
etcdClient *clientv3.Client
@@ -508,6 +511,7 @@ func (do *Domain) Close() {
508511
}
509512

510513
do.sysSessionPool.Close()
514+
do.dxfSessionPool.Close()
511515
do.advancedSysSessionPool.Close()
512516
variable.UnregisterStatistics(do.BindingHandle())
513517
if do.onClose != nil {
@@ -546,31 +550,11 @@ func NewDomainWithEtcdClient(
546550
etcdClient *clientv3.Client,
547551
) *Domain {
548552
intest.Assert(schemaLease > 0, "schema lease should be a positive duration")
549-
capacity := 200 // capacity of the sysSessionPool size
550553
do := &Domain{
551-
store: store,
552-
exit: make(chan struct{}),
553-
sysSessionPool: util.NewSessionPool(
554-
capacity, factory,
555-
func(r pools.Resource) {
556-
_, ok := r.(sessionctx.Context)
557-
intest.Assert(ok)
558-
infosync.StoreInternalSession(r)
559-
},
560-
func(r pools.Resource) {
561-
sctx, ok := r.(sessionctx.Context)
562-
intest.Assert(ok)
563-
intest.AssertFunc(func() bool {
564-
txn, _ := sctx.Txn(false)
565-
return txn == nil || !txn.Valid()
566-
})
567-
infosync.DeleteInternalSession(r)
568-
},
569-
func(r pools.Resource) {
570-
intest.Assert(r != nil)
571-
infosync.DeleteInternalSession(r)
572-
},
573-
),
554+
store: store,
555+
exit: make(chan struct{}),
556+
sysSessionPool: createInternelSessionPool(systemSessionPoolSize, factory),
557+
dxfSessionPool: createInternelSessionPool(dxfSessionPoolSize, factory),
574558
statsLease: statsLease,
575559
schemaLease: schemaLease,
576560
slowQuery: newTopNSlowQueries(config.GetGlobalConfig().InMemSlowQueryTopNNum, time.Hour*24*7, config.GetGlobalConfig().InMemSlowQueryRecentNum),
@@ -579,7 +563,7 @@ func NewDomainWithEtcdClient(
579563
crossKSSessFactoryGetter: crossKSSessFactoryGetter,
580564
}
581565

582-
do.advancedSysSessionPool = syssession.NewAdvancedSessionPool(capacity, func() (syssession.SessionContext, error) {
566+
do.advancedSysSessionPool = syssession.NewAdvancedSessionPool(systemSessionPoolSize, func() (syssession.SessionContext, error) {
583567
r, err := factory()
584568
if err != nil {
585569
return nil, err
@@ -614,6 +598,30 @@ func NewDomainWithEtcdClient(
614598
return do
615599
}
616600

601+
func createInternelSessionPool(capacity int, factory pools.Factory) util.DestroyableSessionPool {
602+
return util.NewSessionPool(
603+
capacity, factory,
604+
func(r pools.Resource) {
605+
_, ok := r.(sessionctx.Context)
606+
intest.Assert(ok)
607+
infosync.StoreInternalSession(r)
608+
},
609+
func(r pools.Resource) {
610+
sctx, ok := r.(sessionctx.Context)
611+
intest.Assert(ok)
612+
intest.AssertFunc(func() bool {
613+
txn, _ := sctx.Txn(false)
614+
return txn == nil || !txn.Valid()
615+
})
616+
infosync.DeleteInternalSession(r)
617+
},
618+
func(r pools.Resource) {
619+
intest.Assert(r != nil)
620+
infosync.DeleteInternalSession(r)
621+
},
622+
)
623+
}
624+
617625
const serverIDForStandalone = 1 // serverID for standalone deployment.
618626

619627
// Init initializes a domain. after return, session can be used to do DMLs but not
@@ -1042,7 +1050,7 @@ func (do *Domain) InitDistTaskLoop() error {
10421050
}
10431051
})
10441052

1045-
taskManager := storage.NewTaskManager(do.sysSessionPool)
1053+
taskManager := storage.NewTaskManager(do.dxfSessionPool)
10461054
storage.SetTaskManager(taskManager)
10471055

10481056
if keyspace.IsRunningOnUser() {

0 commit comments

Comments
 (0)