server: Remove Lock/Unlock from ReadTx

Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
Marek Siarkowicz 2023-07-26 16:13:38 +02:00
parent 424ced9ff3
commit b4f8a7be51
3 changed files with 6 additions and 11 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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))
})
}