2020-11-24 14:32:21 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
|
2022-07-06 11:59:35 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
2021-09-06 14:28:07 +00:00
|
|
|
storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log"
|
2022-03-17 08:03:58 +00:00
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2020-11-24 14:32:21 +00:00
|
|
|
)
|
|
|
|
|
2022-07-06 12:39:35 +00:00
|
|
|
func (b *BlobStor) Delete(prm common.DeletePrm) (common.DeleteRes, error) {
|
2022-07-06 14:09:50 +00:00
|
|
|
if prm.StorageID == nil {
|
2022-07-06 12:39:35 +00:00
|
|
|
// Nothing specified, try everything.
|
|
|
|
res, err := b.deleteBig(prm)
|
|
|
|
if err == nil || !errors.As(err, new(apistatus.ObjectNotFound)) {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
return b.deleteSmall(prm)
|
|
|
|
}
|
2022-07-06 14:09:50 +00:00
|
|
|
if len(prm.StorageID) == 0 {
|
2022-07-06 12:39:35 +00:00
|
|
|
return b.deleteBig(prm)
|
|
|
|
}
|
|
|
|
return b.deleteSmall(prm)
|
|
|
|
}
|
|
|
|
|
|
|
|
// deleteBig removes an object from shallow dir of BLOB storage.
|
2020-11-24 14:32:21 +00:00
|
|
|
//
|
|
|
|
// Returns any error encountered that did not allow
|
|
|
|
// to completely remove the object.
|
|
|
|
//
|
2022-03-17 13:26:17 +00:00
|
|
|
// Returns an error of type apistatus.ObjectNotFound if there is no object to delete.
|
2022-07-06 12:39:35 +00:00
|
|
|
func (b *BlobStor) deleteBig(prm common.DeletePrm) (common.DeleteRes, error) {
|
2022-07-08 07:09:48 +00:00
|
|
|
res, err := b.fsTree.Delete(prm)
|
2021-09-06 14:28:07 +00:00
|
|
|
if err == nil {
|
2022-07-06 11:59:35 +00:00
|
|
|
storagelog.Write(b.log, storagelog.AddressField(prm.Address), storagelog.OpField("fstree DELETE"))
|
2021-09-06 14:28:07 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 07:09:48 +00:00
|
|
|
return res, err
|
2020-11-24 14:32:21 +00:00
|
|
|
}
|
2022-07-05 13:47:39 +00:00
|
|
|
|
2022-07-06 12:39:35 +00:00
|
|
|
// deleteSmall removes an object from blobovnicza of BLOB storage.
|
2022-07-05 13:47:39 +00:00
|
|
|
//
|
|
|
|
// If blobovnicza ID is not set or set to nil, BlobStor tries to
|
|
|
|
// find and remove object from any blobovnicza.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that did not allow
|
|
|
|
// to completely remove the object.
|
|
|
|
//
|
|
|
|
// Returns an error of type apistatus.ObjectNotFound if there is no object to delete.
|
2022-07-06 12:39:35 +00:00
|
|
|
func (b *BlobStor) deleteSmall(prm common.DeletePrm) (common.DeleteRes, error) {
|
2022-07-05 13:47:39 +00:00
|
|
|
return b.blobovniczas.Delete(prm)
|
|
|
|
}
|