From b4f8a7be51bcde887f1dde184cadb70bf52a92c9 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Wed, 26 Jul 2023 16:13:38 +0200 Subject: [PATCH] server: Remove Lock/Unlock from ReadTx Signed-off-by: Marek Siarkowicz --- server/storage/backend/batch_tx.go | 2 ++ server/storage/backend/read_tx.go | 7 ------- server/storage/schema/confstate_test.go | 8 ++++---- 3 files changed, 6 insertions(+), 11 deletions(-) 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)) }) }