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()` (#38790) (#38828)

close #38706
  • Loading branch information
ti-chi-bot authored Nov 3, 2022
1 parent dcc5cf7 commit c0dde4b
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 @@ -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
}
Expand Down
10 changes: 9 additions & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -1656,6 +1659,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 @@ -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)
}
Expand Down

0 comments on commit c0dde4b

Please sign in to comment.