diff --git a/session/advisory_locks.go b/session/advisory_locks.go index aca6914de2029..2278d89cd3928 100644 --- a/session/advisory_locks.go +++ b/session/advisory_locks.go @@ -49,7 +49,7 @@ func (a *advisoryLock) DecrReferences() { a.referenceCount-- } -// References returns the current reference count for the advisory lock. +// ReferenceCount returns the current reference count for the advisory lock. func (a *advisoryLock) ReferenceCount() int { return a.referenceCount } diff --git a/session/session.go b/session/session.go index a31901f176d12..91b9c97ff765a 100644 --- a/session/session.go +++ b/session/session.go @@ -65,6 +65,7 @@ import ( "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl/placement" "github.com/pingcap/tidb/domain" + "github.com/pingcap/tidb/domain/infosync" "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/executor" "github.com/pingcap/tidb/infoschema" @@ -1615,10 +1616,11 @@ func (s *session) GetAdvisoryLock(lockName string, timeout int64) error { lock.IncrReferences() return nil } - sess, err := createSession(s.GetStore()) + sess, err := createSession(s.store) if err != nil { return err } + infosync.StoreInternalSession(sess) lock := &advisoryLock{session: sess, ctx: context.TODO()} err = lock.GetLock(lockName, timeout) if err != nil { @@ -1640,6 +1642,7 @@ func (s *session) ReleaseAdvisoryLock(lockName string) (released bool) { if lock.ReferenceCount() <= 0 { lock.Close() delete(s.advisoryLocks, lockName) + infosync.DeleteInternalSession(lock.session) } return true } @@ -1656,6 +1659,7 @@ func (s *session) ReleaseAllAdvisoryLocks() int { lock.Close() count += lock.ReferenceCount() delete(s.advisoryLocks, lockName) + infosync.DeleteInternalSession(lock.session) } return count } @@ -2976,6 +2980,10 @@ func createSessions(store kv.Storage, cnt int) ([]*session, error) { return ses, nil } +// createSession creates a new session. +// Please note that such a session is not tracked by the internal session list. +// This means the min ts reporter is not aware of it and may report a wrong min start ts. +// In most cases you should use a session pool in domain instead. func createSession(store kv.Storage) (*session, error) { return createSessionWithOpt(store, nil) }