From 4c520be9f1fe7a14a28d64914434505543e7eb54 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 15 Aug 2024 15:39:22 +0300 Subject: [PATCH] [#1313] blobovnicza: Prevent concurrent Put/Close Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/blobovnicza/blobovnicza.go | 2 +- pkg/local_object_storage/blobovnicza/delete.go | 3 +++ pkg/local_object_storage/blobovnicza/exists.go | 3 +++ pkg/local_object_storage/blobovnicza/get.go | 3 +++ pkg/local_object_storage/blobovnicza/iterate.go | 3 +++ pkg/local_object_storage/blobovnicza/move.go | 3 +++ pkg/local_object_storage/blobovnicza/put.go | 3 +++ 7 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/blobovnicza/blobovnicza.go b/pkg/local_object_storage/blobovnicza/blobovnicza.go index c787f9d5e..d203ea077 100644 --- a/pkg/local_object_storage/blobovnicza/blobovnicza.go +++ b/pkg/local_object_storage/blobovnicza/blobovnicza.go @@ -22,7 +22,7 @@ type Blobovnicza struct { boltDB *bbolt.DB opened bool - controlMtx sync.Mutex + controlMtx sync.RWMutex } // Option is an option of Blobovnicza's constructor. diff --git a/pkg/local_object_storage/blobovnicza/delete.go b/pkg/local_object_storage/blobovnicza/delete.go index 5d6787897..60438b5c6 100644 --- a/pkg/local_object_storage/blobovnicza/delete.go +++ b/pkg/local_object_storage/blobovnicza/delete.go @@ -45,6 +45,9 @@ func (b *Blobovnicza) Delete(ctx context.Context, prm DeletePrm) (DeleteRes, err )) defer span.End() + b.controlMtx.RLock() + defer b.controlMtx.RUnlock() + addrKey := addressKey(prm.addr) found := false diff --git a/pkg/local_object_storage/blobovnicza/exists.go b/pkg/local_object_storage/blobovnicza/exists.go index f7bc84d4a..12a043295 100644 --- a/pkg/local_object_storage/blobovnicza/exists.go +++ b/pkg/local_object_storage/blobovnicza/exists.go @@ -21,6 +21,9 @@ func (b *Blobovnicza) Exists(ctx context.Context, addr oid.Address) (bool, error )) defer span.End() + b.controlMtx.RLock() + defer b.controlMtx.RUnlock() + addrKey := addressKey(addr) err := b.boltDB.View(func(tx *bbolt.Tx) error { diff --git a/pkg/local_object_storage/blobovnicza/get.go b/pkg/local_object_storage/blobovnicza/get.go index 600323f55..b73db8178 100644 --- a/pkg/local_object_storage/blobovnicza/get.go +++ b/pkg/local_object_storage/blobovnicza/get.go @@ -51,6 +51,9 @@ func (b *Blobovnicza) Get(ctx context.Context, prm GetPrm) (GetRes, error) { )) defer span.End() + b.controlMtx.RLock() + defer b.controlMtx.RUnlock() + var ( data []byte addrKey = addressKey(prm.addr) diff --git a/pkg/local_object_storage/blobovnicza/iterate.go b/pkg/local_object_storage/blobovnicza/iterate.go index 01e5529da..d52271674 100644 --- a/pkg/local_object_storage/blobovnicza/iterate.go +++ b/pkg/local_object_storage/blobovnicza/iterate.go @@ -128,6 +128,9 @@ func (b *Blobovnicza) Iterate(ctx context.Context, prm IteratePrm) (IterateRes, )) defer span.End() + b.controlMtx.RLock() + defer b.controlMtx.RUnlock() + var elem IterationElement if err := b.boltDB.View(func(tx *bbolt.Tx) error { diff --git a/pkg/local_object_storage/blobovnicza/move.go b/pkg/local_object_storage/blobovnicza/move.go index 420e22a48..3b56f6527 100644 --- a/pkg/local_object_storage/blobovnicza/move.go +++ b/pkg/local_object_storage/blobovnicza/move.go @@ -29,6 +29,9 @@ func (b *Blobovnicza) PutMoveInfo(ctx context.Context, prm MoveInfo) error { )) defer span.End() + b.controlMtx.RLock() + defer b.controlMtx.RUnlock() + key := addressKey(prm.Address) err := b.boltDB.Update(func(tx *bbolt.Tx) error { diff --git a/pkg/local_object_storage/blobovnicza/put.go b/pkg/local_object_storage/blobovnicza/put.go index ff223ba36..45073d9df 100644 --- a/pkg/local_object_storage/blobovnicza/put.go +++ b/pkg/local_object_storage/blobovnicza/put.go @@ -64,6 +64,9 @@ func (b *Blobovnicza) Put(ctx context.Context, prm PutPrm) (PutRes, error) { )) defer span.End() + b.controlMtx.RLock() + defer b.controlMtx.RUnlock() + sz := uint64(len(prm.objData)) bucketName := bucketForSize(sz) key := addressKey(prm.addr) -- 2.45.2