Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session: make min start ts reporter aware of internal session from get_lock() (#38790) #38828

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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