diff --git a/server/storage/backend/batch_tx.go b/server/storage/backend/batch_tx.go index 0d12a0868dd..2fdba37bcf8 100644 --- a/server/storage/backend/batch_tx.go +++ b/server/storage/backend/batch_tx.go @@ -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) diff --git a/server/storage/backend/read_tx.go b/server/storage/backend/read_tx.go index 592e301a0f6..8b4e48e83c2 100644 --- a/server/storage/backend/read_tx.go +++ b/server/storage/backend/read_tx.go @@ -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() diff --git a/server/storage/schema/confstate_test.go b/server/storage/schema/confstate_test.go index c82a4487ee8..11131e40579 100644 --- a/server/storage/schema/confstate_test.go +++ b/server/storage/schema/confstate_test.go @@ -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)) }) @@ -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)) }) }