[#861] shard: Fix Delete object
Some checks failed
DCO action / DCO (pull_request) Successful in 3m26s
Vulncheck / Vulncheck (pull_request) Failing after 4m32s
Build / Build Components (1.21) (pull_request) Successful in 5m19s
Build / Build Components (1.20) (pull_request) Successful in 8m1s
Tests and linters / Staticcheck (pull_request) Successful in 10m0s
Tests and linters / Lint (pull_request) Successful in 10m29s
Tests and linters / Tests (1.21) (pull_request) Successful in 8m29s
Tests and linters / Tests (1.20) (pull_request) Successful in 3m51s
Tests and linters / Tests with -race (pull_request) Successful in 5m8s

It is possible that object doesn't exist in metabase.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-12-12 14:18:42 +03:00
parent 9436fcfc70
commit c8683554cd
2 changed files with 28 additions and 2 deletions

View file

@ -544,4 +544,5 @@ const (
BlobovniczaSavingCountersToMeta = "saving counters to blobovnicza's meta..."
BlobovniczaSavingCountersToMetaSuccess = "saving counters to blobovnicza's meta completed successfully"
BlobovniczaSavingCountersToMetaFailed = "saving counters to blobovnicza's meta failed"
ObjectRemovalFailureExistsInWritecache = "can't remove object: object must be flushed from writecache"
)

View file

@ -2,11 +2,13 @@ package shard
import (
"context"
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
@ -60,6 +62,13 @@ func (s *Shard) delete(ctx context.Context, prm DeletePrm, skipFailed bool) (Del
default:
}
if err := s.validateWritecacheDoesntContainObject(ctx, addr); err != nil {
if skipFailed {
continue
}
return result, err
}
if err := s.deleteFromBlobstor(ctx, addr); err != nil {
if skipFailed {
continue
@ -79,6 +88,21 @@ func (s *Shard) delete(ctx context.Context, prm DeletePrm, skipFailed bool) (Del
return result, nil
}
func (s *Shard) validateWritecacheDoesntContainObject(ctx context.Context, addr oid.Address) error {
if !s.hasWriteCache() {
return nil
}
_, err := s.writeCache.Head(ctx, addr)
if err == nil {
s.log.Warn(logs.ObjectRemovalFailureExistsInWritecache, zap.Stringer("object_address", addr))
return fmt.Errorf("object %s must be flushed from writecache", addr)
}
if client.IsErrObjectNotFound(err) {
return nil
}
return err
}
func (s *Shard) deleteFromBlobstor(ctx context.Context, addr oid.Address) error {
var sPrm meta.StorageIDPrm
sPrm.SetAddress(addr)
@ -97,12 +121,13 @@ func (s *Shard) deleteFromBlobstor(ctx context.Context, addr oid.Address) error
delPrm.StorageID = storageID
_, err = s.blobStor.Delete(ctx, delPrm)
if err != nil {
if err != nil && !client.IsErrObjectNotFound(err) {
s.log.Debug(logs.ObjectRemovalFailureBlobStor,
zap.Stringer("object_address", addr),
zap.String("error", err.Error()))
}
return err
}
return nil
}
func (s *Shard) deleteFromMetabase(ctx context.Context, addr oid.Address) error {