2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2022-10-28 10:55:21 +00:00
|
|
|
"errors"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
meta "github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
|
|
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-11-17 17:39:43 +00:00
|
|
|
"go.uber.org/zap"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DeletePrm groups the parameters of Delete operation.
|
|
|
|
type DeletePrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr []oid.Address
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DeleteRes groups the resulting values of Delete operation.
|
2020-11-17 12:23:15 +00:00
|
|
|
type DeleteRes struct{}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetAddresses is a Delete option to set the addresses of the objects to delete.
|
2020-11-17 12:23:15 +00:00
|
|
|
//
|
|
|
|
// Option is required.
|
2022-07-13 12:43:04 +00:00
|
|
|
func (p *DeletePrm) SetAddresses(addr ...oid.Address) {
|
|
|
|
p.addr = append(p.addr, addr...)
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 07:55:08 +00:00
|
|
|
// Delete removes data from the shard's writeCache, metaBase and
|
|
|
|
// blobStor.
|
2022-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) Delete(prm DeletePrm) (DeleteRes, error) {
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
|
|
|
return s.delete(prm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) delete(prm DeletePrm) (DeleteRes, error) {
|
|
|
|
if s.info.Mode.ReadOnly() {
|
2022-05-31 11:50:39 +00:00
|
|
|
return DeleteRes{}, ErrReadOnlyMode
|
2022-12-07 17:42:35 +00:00
|
|
|
} else if s.info.Mode.NoMetabase() {
|
2022-06-29 11:27:36 +00:00
|
|
|
return DeleteRes{}, ErrDegradedMode
|
2021-12-27 11:04:07 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 07:55:08 +00:00
|
|
|
ln := len(prm.addr)
|
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
smalls := make(map[oid.Address][]byte, ln)
|
2020-12-01 07:55:08 +00:00
|
|
|
|
|
|
|
for i := range prm.addr {
|
|
|
|
if s.hasWriteCache() {
|
2021-04-06 10:56:06 +00:00
|
|
|
err := s.writeCache.Delete(prm.addr[i])
|
2022-10-28 10:55:21 +00:00
|
|
|
if err != nil && !IsErrNotFound(err) && !errors.Is(err, writecache.ErrReadOnly) {
|
2022-10-25 07:40:56 +00:00
|
|
|
s.log.Warn("can't delete object from write cache", zap.String("error", err.Error()))
|
2020-12-01 07:55:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
var sPrm meta.StorageIDPrm
|
|
|
|
sPrm.SetAddress(prm.addr[i])
|
2022-07-12 14:42:55 +00:00
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
res, err := s.metaBase.StorageID(sPrm)
|
2020-12-01 07:55:08 +00:00
|
|
|
if err != nil {
|
2022-10-21 17:17:05 +00:00
|
|
|
s.log.Debug("can't get storage ID from metabase",
|
2020-12-01 07:55:08 +00:00
|
|
|
zap.Stringer("object", prm.addr[i]),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
if res.StorageID() != nil {
|
|
|
|
smalls[prm.addr[i]] = res.StorageID()
|
2020-12-01 07:55:08 +00:00
|
|
|
}
|
2020-11-17 17:39:43 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
var delPrm meta.DeletePrm
|
2022-07-12 14:59:37 +00:00
|
|
|
delPrm.SetAddresses(prm.addr...)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
2022-08-19 16:49:09 +00:00
|
|
|
res, err := s.metaBase.Delete(delPrm)
|
2020-12-01 07:55:08 +00:00
|
|
|
if err != nil {
|
2022-05-31 11:50:39 +00:00
|
|
|
return DeleteRes{}, err // stop on metabase error ?
|
2020-12-01 07:55:08 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 14:01:25 +00:00
|
|
|
var totalRemovedPayload uint64
|
|
|
|
|
2022-09-09 11:36:34 +00:00
|
|
|
s.decObjectCounterBy(physical, res.RawObjectsRemoved())
|
|
|
|
s.decObjectCounterBy(logical, res.AvailableObjectsRemoved())
|
2022-12-01 11:59:22 +00:00
|
|
|
for i := range prm.addr {
|
2023-02-02 20:28:42 +00:00
|
|
|
removedPayload := res.RemovedPhysicalObjectSizes()[i]
|
2023-01-25 14:01:25 +00:00
|
|
|
totalRemovedPayload += removedPayload
|
2023-02-02 20:28:42 +00:00
|
|
|
logicalRemovedPayload := res.RemovedLogicalObjectSizes()[i]
|
|
|
|
if logicalRemovedPayload > 0 {
|
|
|
|
s.addToContainerSize(prm.addr[i].Container().EncodeToString(), -int64(logicalRemovedPayload))
|
|
|
|
}
|
2022-12-01 11:59:22 +00:00
|
|
|
}
|
2023-02-07 11:28:28 +00:00
|
|
|
s.addToPayloadSize(-int64(totalRemovedPayload))
|
2022-08-19 16:49:09 +00:00
|
|
|
|
2022-10-21 17:17:05 +00:00
|
|
|
for i := range prm.addr {
|
2022-07-06 14:09:50 +00:00
|
|
|
var delPrm common.DeletePrm
|
|
|
|
delPrm.Address = prm.addr[i]
|
|
|
|
id := smalls[prm.addr[i]]
|
|
|
|
delPrm.StorageID = id
|
2020-12-01 07:55:08 +00:00
|
|
|
|
2022-07-06 14:09:50 +00:00
|
|
|
_, err = s.blobStor.Delete(delPrm)
|
2020-12-01 07:55:08 +00:00
|
|
|
if err != nil {
|
2022-10-21 17:17:05 +00:00
|
|
|
s.log.Debug("can't remove object from blobStor",
|
2020-12-01 07:55:08 +00:00
|
|
|
zap.Stringer("object_address", prm.addr[i]),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
2020-11-17 17:39:43 +00:00
|
|
|
}
|
2020-11-17 12:23:15 +00:00
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return DeleteRes{}, nil
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|