From df558cbe6b8e0375ebf1982ed70664ad11971fc1 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 18 Nov 2020 14:54:59 +0300 Subject: [PATCH] [#176] shard: Get rid of using the global RW lock In previous implementation each shard operation locked RW shard mutex. With this approach RW operations were executed one-by-one and blocked the execution of RO operations. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/shard/delete.go | 3 --- pkg/local_object_storage/shard/exists.go | 3 --- pkg/local_object_storage/shard/get.go | 3 --- pkg/local_object_storage/shard/put.go | 3 --- pkg/local_object_storage/shard/select.go | 3 --- pkg/local_object_storage/shard/shard.go | 5 ----- 6 files changed, 20 deletions(-) diff --git a/pkg/local_object_storage/shard/delete.go b/pkg/local_object_storage/shard/delete.go index fd1df58ba..462dc2b58 100644 --- a/pkg/local_object_storage/shard/delete.go +++ b/pkg/local_object_storage/shard/delete.go @@ -31,9 +31,6 @@ func (p *DeletePrm) WithAddress(addr *objectSDK.Address) *DeletePrm { // Returns any error encountered that did not allow to completely // mark the object to delete. func (s *Shard) Delete(prm *DeletePrm) (*DeleteRes, error) { - s.mtx.Lock() - defer s.mtx.Unlock() - // mark object to delete in metabase if err := s.metaBase.Delete(prm.addr); err != nil { s.log.Warn("could not mark object to delete in metabase", diff --git a/pkg/local_object_storage/shard/exists.go b/pkg/local_object_storage/shard/exists.go index 02d93b727..9fa5e73a1 100644 --- a/pkg/local_object_storage/shard/exists.go +++ b/pkg/local_object_storage/shard/exists.go @@ -33,9 +33,6 @@ func (p *ExistsRes) Exists() bool { // Returns any error encountered that does not allow to // unambiguously determine the presence of an object. func (s *Shard) Exists(prm *ExistsPrm) (*ExistsRes, error) { - s.mtx.RLock() - defer s.mtx.RUnlock() - // FIXME: implement me return &ExistsRes{ ex: false, diff --git a/pkg/local_object_storage/shard/get.go b/pkg/local_object_storage/shard/get.go index 82f08dd99..7c8f1052e 100644 --- a/pkg/local_object_storage/shard/get.go +++ b/pkg/local_object_storage/shard/get.go @@ -71,9 +71,6 @@ func (r *GetRes) Object() *object.Object { // // Returns ErrObjectNotFound if requested object is missing in shard. func (s *Shard) Get(prm *GetPrm) (*GetRes, error) { - s.mtx.RLock() - defer s.mtx.RUnlock() - if prm.ln < 0 { // try to read from WriteCache // TODO: implement diff --git a/pkg/local_object_storage/shard/put.go b/pkg/local_object_storage/shard/put.go index 83daa45f4..411581dc3 100644 --- a/pkg/local_object_storage/shard/put.go +++ b/pkg/local_object_storage/shard/put.go @@ -28,9 +28,6 @@ func (p *PutPrm) WithObject(obj *object.Object) *PutPrm { // Returns any error encountered that // did not allow to completely save the object. func (s *Shard) Put(prm *PutPrm) (*PutRes, error) { - s.mtx.Lock() - defer s.mtx.Unlock() - // check object existence ex, err := s.metaBase.Exists(prm.obj.Address()) if err != nil { diff --git a/pkg/local_object_storage/shard/select.go b/pkg/local_object_storage/shard/select.go index 676681613..d79e834ab 100644 --- a/pkg/local_object_storage/shard/select.go +++ b/pkg/local_object_storage/shard/select.go @@ -34,9 +34,6 @@ func (r *SelectRes) AddressList() []*objectSDK.Address { // Returns any error encountered that // did not allow to completely select the objects. func (s *Shard) Select(prm *SelectPrm) (*SelectRes, error) { - s.mtx.RLock() - defer s.mtx.RUnlock() - addrList, err := s.metaBase.Select(prm.filters) if err != nil { return nil, errors.Wrap(err, "could not select objects from metabase") diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index 3601e2f5c..54bcb7336 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -1,8 +1,6 @@ package shard import ( - "sync" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/util/logger" @@ -12,8 +10,6 @@ import ( type Shard struct { *cfg - mtx *sync.RWMutex - weight WeightValues blobStor *blobstor.BlobStor @@ -48,7 +44,6 @@ func New(opts ...Option) *Shard { return &Shard{ cfg: c, - mtx: new(sync.RWMutex), blobStor: blobstor.New(c.blobOpts...), metaBase: meta.NewDB(c.metaOpts...), }