Skip to content

Commit

Permalink
Merge #62163
Browse files Browse the repository at this point in the history
62163: contention: properly protect AddContentionEvent by mutex r=yuzefovich a=yuzefovich

Whenever we're adding a contention event to the registry, we need to
acquire the lock. Previously, we correctly did so for SQL keys but
forgot to do so for non-SQL keys (the support for which has been
recently added). This commit fixes that issue.

Fixes: #62160.

Release note: None (no stable release with the bug)

Co-authored-by: Yahor Yuzefovich <[email protected]>
  • Loading branch information
craig[bot] and yuzefovich committed Mar 17, 2021
2 parents 9a132fa + 9debdbf commit 5766c37
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/contention/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ func NewRegistry() *Registry {

// AddContentionEvent adds a new ContentionEvent to the Registry.
func (r *Registry) AddContentionEvent(c roachpb.ContentionEvent) {
r.globalLock.Lock()
defer r.globalLock.Unlock()
_, rawTableID, rawIndexID, err := keys.DecodeTableIDIndexID(c.Key)
if err != nil {
// The key is not a valid SQL key, so we store it in a separate cache.
Expand All @@ -254,8 +256,6 @@ func (r *Registry) AddContentionEvent(c roachpb.ContentionEvent) {
}
tableID := descpb.ID(rawTableID)
indexID := descpb.IndexID(rawIndexID)
r.globalLock.Lock()
defer r.globalLock.Unlock()
if v, ok := r.indexMap.get(tableID, indexID); !ok {
// This is the first contention event seen for the given tableID/indexID
// pair.
Expand Down

0 comments on commit 5766c37

Please sign in to comment.