Skip to content

Commit

Permalink
vecstore: disable deadlock linting for inMemoryLock
Browse files Browse the repository at this point in the history
Do not use syncutil.RWMutex in the inMemoryLock class, because deadlock
detection reports spurious failures. Different partitions in the vector
index can be locked in different orders by merge, split, format and other
operations. In all these cases, we first acquire the in-memory store's
structure lock to prevent deadlocks. But the deadlock detection package
is not smart enough to realize this and reports false positives.

Epic: CRDB-42943

Release note: None
  • Loading branch information
andy-kimball committed Dec 13, 2024
1 parent 32886df commit 86ffeec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/sql/vecindex/vecstore/in_memory_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@
package vecstore

import (
"sync"
"sync/atomic"

"github.com/cockroachdb/cockroach/pkg/util/syncutil"
)

// inMemoryLock wraps a read-write lock, adding support for reentrancy and
// ownership tracking.
// NOTE: This is only used in testing and benchmarking code.
type inMemoryLock struct {
mu struct {
syncutil.RWMutex
// NOTE: Do not use syncutil.RWMutex here, because deadlock detection
// reports spurious failures. Different partitions in the vector index
// can be locked in different orders by merge, split, format and other
// operations. In all these cases, we first acquire the in-memory store's
// structure lock to prevent deadlocks. But the deadlock detection package
// is not smart enough to realize this and reports false positives.
sync.RWMutex

// reentrancy counts how many times the same owner has acquired the same
// lock.
Expand Down
2 changes: 2 additions & 0 deletions pkg/testutils/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,8 @@ func TestLint(t *testing.T) {
":!testutils/lint/passes/deferunlockcheck/testdata/src/github.com/cockroachdb/cockroach/pkg/util/syncutil/mutex_sync.go",
// Exception needed for goroutineStalledStates.
":!kv/kvserver/concurrency/concurrency_manager_test.go",
// See comment in inMemoryLock class.
":!sql/vecindex/vecstore/in_memory_lock.go",
)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 86ffeec

Please sign in to comment.