Skip to content

Commit

Permalink
Merge #88841
Browse files Browse the repository at this point in the history
88841: contentionutils: further document ConcurrentBufferGuard r=matthewtodd a=matthewtodd

Fixes #83080

Release note: None

Co-authored-by: Matthew Todd <[email protected]>
  • Loading branch information
craig[bot] and matthewtodd committed Sep 29, 2022
2 parents fbda8c0 + 6b382a1 commit 4780ee1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/sql/contention/contentionutils/concurrent_buffer_guard.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,15 @@ func (c *ConcurrentBufferGuard) ForceSync() {
func (c *ConcurrentBufferGuard) syncRLocked() {
// We upgrade the read-lock to a write-lock, then when we are done flushing,
// the lock is downgraded to a read-lock.
// Note: this looks incorrect, see https://github.com/cockroachdb/cockroach/issues/83080
//
// This code looks dangerous (upgrading a read-lock to a write-lock is not
// an atomic operation), but it is safe here because the atomic add in
// reserveMsgBlockIndex ensures that only one goroutine writing into the
// buffer (the one that reserves the index just beyond the buffer's length)
// will attempt to perform the flush. The other goroutines will either
// write into the buffer and release their locks (if they reserved an index
// within the buffer's length) or release their locks and wait on the
// flushDone condition to try again.
c.flushSyncLock.RUnlock()
defer c.flushSyncLock.RLock()
c.flushSyncLock.Lock()
Expand Down

0 comments on commit 4780ee1

Please sign in to comment.