From 65da2025e595e66ec8459f3a0f81f674965e4476 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 24 Nov 2020 17:32:21 +0300 Subject: [PATCH] [#211] blobstor: Rename Delete to DeleteBig Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/blobstor/delete.go | 53 ------------------- .../blobstor/delete_big.go | 44 +++++++++++++++ pkg/local_object_storage/shard/delete.go | 9 ++-- 3 files changed, 49 insertions(+), 57 deletions(-) delete mode 100644 pkg/local_object_storage/blobstor/delete.go create mode 100644 pkg/local_object_storage/blobstor/delete_big.go diff --git a/pkg/local_object_storage/blobstor/delete.go b/pkg/local_object_storage/blobstor/delete.go deleted file mode 100644 index a7123148b..000000000 --- a/pkg/local_object_storage/blobstor/delete.go +++ /dev/null @@ -1,53 +0,0 @@ -package blobstor - -import ( - "os" - - "github.com/nspcc-dev/neofs-api-go/pkg/object" - "github.com/pkg/errors" -) - -// DeletePrm groups the parameters of Delete operation. -type DeletePrm struct { - addr *object.Address -} - -// DeleteRes groups resulting values of Delete operation. -type DeleteRes struct{} - -// WithAddress is a Delete option to set the address of the object to delete. -// -// Option is required. -func (p *DeletePrm) WithAddress(addr *object.Address) *DeletePrm { - if p != nil { - p.addr = addr - } - - return p -} - -// Delete removes object from BLOB storage. -// -// Returns any error encountered that did not allow -// to completely remove the object. -func (b *BlobStor) Delete(prm *DeletePrm) (*DeleteRes, error) { - b.mtx.Lock() - defer b.mtx.Unlock() - - err := b.fsTree.delete(prm.addr) - if errors.Is(err, errFileNotFound) { - err = nil - } - - return nil, err -} - -func (t *fsTree) delete(addr *object.Address) error { - p := t.treePath(addr) - - if _, err := os.Stat(p); os.IsNotExist(err) { - return errFileNotFound - } - - return os.Remove(p) -} diff --git a/pkg/local_object_storage/blobstor/delete_big.go b/pkg/local_object_storage/blobstor/delete_big.go new file mode 100644 index 000000000..22599471e --- /dev/null +++ b/pkg/local_object_storage/blobstor/delete_big.go @@ -0,0 +1,44 @@ +package blobstor + +import ( + "os" + + "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/pkg/errors" +) + +// DeleteBigPrm groups the parameters of DeleteBig operation. +type DeleteBigPrm struct { + address +} + +// DeleteBigRes groups resulting values of DeleteBig operation. +type DeleteBigRes struct{} + +// DeleteBig removes object from shallow dir of BLOB storage. +// +// Returns any error encountered that did not allow +// to completely remove the object. +// +// Returns ErrObjectNotFound if there is no object to delete. +func (b *BlobStor) DeleteBig(prm *DeleteBigPrm) (*DeleteBigRes, error) { + b.mtx.Lock() + defer b.mtx.Unlock() + + err := b.fsTree.delete(prm.addr) + if errors.Is(err, errFileNotFound) { + err = ErrObjectNotFound + } + + return nil, err +} + +func (t *fsTree) delete(addr *object.Address) error { + p := t.treePath(addr) + + if _, err := os.Stat(p); os.IsNotExist(err) { + return errFileNotFound + } + + return os.Remove(p) +} diff --git a/pkg/local_object_storage/shard/delete.go b/pkg/local_object_storage/shard/delete.go index 462dc2b58..25666397b 100644 --- a/pkg/local_object_storage/shard/delete.go +++ b/pkg/local_object_storage/shard/delete.go @@ -38,10 +38,11 @@ func (s *Shard) Delete(prm *DeletePrm) (*DeleteRes, error) { ) } - if _, err := s.blobStor.Delete( - new(blobstor.DeletePrm). - WithAddress(prm.addr), - ); err != nil { + // form DeleteBig parameters + delBigPrm := new(blobstor.DeleteBigPrm) + delBigPrm.SetAddress(prm.addr) + + if _, err := s.blobStor.DeleteBig(delBigPrm); err != nil { return nil, errors.Wrap(err, "could not remove object from BLOB storage") }