Skip to content

Commit

Permalink
session: make min start ts reporter aware of internal session from `g…
Browse files Browse the repository at this point in the history
…et_lock()` (pingcap#38790)

close pingcap#38706
  • Loading branch information
tangenta authored Nov 2, 2022
1 parent 5cdfea6 commit caa26a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion session/advisory_locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 9 additions & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -1856,6 +1859,7 @@ func (s *session) ReleaseAllAdvisoryLocks() int {
lock.Close()
count += lock.ReferenceCount()
delete(s.advisoryLocks, lockName)
infosync.DeleteInternalSession(lock.session)
}
return count
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit caa26a4

Please sign in to comment.