Skip to content

Commit

Permalink
Merge pull request #16312 from serathius/rlock
Browse files Browse the repository at this point in the history
server: Remove Lock/Unlock from ReadTx
  • Loading branch information
serathius authored Jul 27, 2023
2 parents 6981e48 + b4f8a7b commit 145cae3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 2 additions & 0 deletions server/storage/backend/batch_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type Bucket interface {

type BatchTx interface {
ReadTx
Lock()
Unlock()
UnsafeCreateBucket(bucket Bucket)
UnsafeDeleteBucket(bucket Bucket)
UnsafePut(bucket Bucket, key []byte, value []byte)
Expand Down
7 changes: 0 additions & 7 deletions server/storage/backend/read_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ import (
// is known to never overwrite any key so range is safe.

type ReadTx interface {
// Lock and Unlock should only be used in the following three cases:
// 1. When committing a transaction. Because it will reset the read tx, including the buffer;
// 2. When writing the pending data back to read buf, because obviously no reading is allowed when writing the read buffer;
// 3. When performing defragmentation, because again it will reset the read tx, including the read buffer.
Lock()
Unlock()
// RLock and RUnlock should be used for all other cases.
RLock()
RUnlock()

Expand Down
8 changes: 4 additions & 4 deletions server/storage/schema/confstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func TestMustUnsafeSaveConfStateToBackend(t *testing.T) {

t.Run("missing", func(t *testing.T) {
tx := be.ReadTx()
tx.Lock()
defer tx.Unlock()
tx.RLock()
defer tx.RUnlock()
assert.Nil(t, UnsafeConfStateFromBackend(lg, tx))
})

Expand All @@ -71,8 +71,8 @@ func TestMustUnsafeSaveConfStateToBackend(t *testing.T) {

t.Run("read", func(t *testing.T) {
tx := be.ReadTx()
tx.Lock()
defer tx.Unlock()
tx.RLock()
defer tx.RUnlock()
assert.Equal(t, confState, *UnsafeConfStateFromBackend(lg, tx))
})
}

0 comments on commit 145cae3

Please sign in to comment.