forked from TrueCloudLab/frostfs-node
[#211] blobstor: Rename Delete to DeleteBig
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
b605ea3678
commit
65da2025e5
3 changed files with 49 additions and 57 deletions
|
@ -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)
|
|
||||||
}
|
|
44
pkg/local_object_storage/blobstor/delete_big.go
Normal file
44
pkg/local_object_storage/blobstor/delete_big.go
Normal file
|
@ -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)
|
||||||
|
}
|
|
@ -38,10 +38,11 @@ func (s *Shard) Delete(prm *DeletePrm) (*DeleteRes, error) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := s.blobStor.Delete(
|
// form DeleteBig parameters
|
||||||
new(blobstor.DeletePrm).
|
delBigPrm := new(blobstor.DeleteBigPrm)
|
||||||
WithAddress(prm.addr),
|
delBigPrm.SetAddress(prm.addr)
|
||||||
); err != nil {
|
|
||||||
|
if _, err := s.blobStor.DeleteBig(delBigPrm); err != nil {
|
||||||
return nil, errors.Wrap(err, "could not remove object from BLOB storage")
|
return nil, errors.Wrap(err, "could not remove object from BLOB storage")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue