diff --git a/session/advisory_locks.go b/session/advisory_locks.go index f51bb061a119c..aff3d80ed7e88 100644 --- a/session/advisory_locks.go +++ b/session/advisory_locks.go @@ -50,7 +50,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 1d3e8c17753e6..a0b19481c77c2 100644 --- a/session/session.go +++ b/session/session.go @@ -46,6 +46,7 @@ import ( "github.com/pingcap/tidb/ddl" "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/expression" @@ -1815,10 +1816,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 { @@ -1840,6 +1842,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 } @@ -1856,6 +1859,7 @@ func (s *session) ReleaseAllAdvisoryLocks() int { lock.Close() count += lock.ReferenceCount() delete(s.advisoryLocks, lockName) + infosync.DeleteInternalSession(lock.session) } return count } @@ -3024,6 +3028,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) }