From 932e7b043fb6f16dee533e1f79e2f8488e583a58 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 19 Jun 2024 00:51:34 +0300 Subject: [PATCH] node/meta: do not stop deleting objects on errors, log them instead Relates #2822. Signed-off-by: Pavel Karpy --- CHANGELOG.md | 1 + pkg/local_object_storage/metabase/delete.go | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 749517baea..a19f0e29e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Changelog for NeoFS Node ### Added ### Fixed +- Control service's Drop call does not clean metabase (#2822) ### Changed diff --git a/pkg/local_object_storage/metabase/delete.go b/pkg/local_object_storage/metabase/delete.go index dac1948adc..24d350c7e4 100644 --- a/pkg/local_object_storage/metabase/delete.go +++ b/pkg/local_object_storage/metabase/delete.go @@ -11,6 +11,7 @@ import ( objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" + "go.uber.org/zap" ) // DeletePrm groups the parameters of Delete operation. @@ -54,6 +55,8 @@ func (p *DeletePrm) SetAddresses(addrs ...oid.Address) { } // Delete removed object records from metabase indexes. +// Does not stop on an error if there are more objects to handle requested; +// returns the first error appeared with a number of deleted objects wrapped. func (db *DB) Delete(prm DeletePrm) (DeleteRes, error) { db.modeMtx.RLock() defer db.modeMtx.RUnlock() @@ -99,11 +102,19 @@ func (db *DB) deleteGroup(tx *bbolt.Tx, addrs []oid.Address, sizes []uint64) (ui var rawDeleted uint64 var availableDeleted uint64 + var errorCount int + var firstErr error for i := range addrs { removed, available, size, err := db.delete(tx, addrs[i], currEpoch) if err != nil { - return 0, 0, err // maybe log and continue? + errorCount++ + db.log.Warn("failed to delete object", zap.Stringer("addr", addrs[i]), zap.Error(err)) + if firstErr == nil { + firstErr = fmt.Errorf("%s object delete fail: %w", addrs[i], err) + } + + continue } if removed { @@ -116,6 +127,12 @@ func (db *DB) deleteGroup(tx *bbolt.Tx, addrs []oid.Address, sizes []uint64) (ui } } + if firstErr != nil { + all := len(addrs) + success := all - errorCount + return 0, 0, fmt.Errorf("deleted %d out of %d objects, first error: %w", success, all, firstErr) + } + if rawDeleted > 0 { err := db.updateCounter(tx, phy, rawDeleted, false) if err != nil {