2020-11-25 09:53:17 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2021-09-13 11:51:17 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
2022-06-21 07:52:03 +00:00
|
|
|
"go.uber.org/zap"
|
2020-11-25 09:53:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Iterate traverses the storage over the stored objects and calls the handler
|
|
|
|
// on each element.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that
|
|
|
|
// did not allow to completely iterate over the storage.
|
|
|
|
//
|
2021-09-13 11:51:17 +00:00
|
|
|
// If handler returns an error, method wraps and returns it immediately.
|
2022-07-07 12:03:45 +00:00
|
|
|
func (b *BlobStor) Iterate(prm common.IteratePrm) (common.IterateRes, error) {
|
2022-11-15 12:33:48 +00:00
|
|
|
b.modeMtx.RLock()
|
|
|
|
defer b.modeMtx.RUnlock()
|
|
|
|
|
2022-07-08 11:33:49 +00:00
|
|
|
for i := range b.storage {
|
|
|
|
_, err := b.storage[i].Storage.Iterate(prm)
|
|
|
|
if err != nil && !prm.IgnoreErrors {
|
2022-07-11 12:34:17 +00:00
|
|
|
return common.IterateRes{}, fmt.Errorf("blobstor iterator failure: %w", err)
|
2022-07-08 11:33:49 +00:00
|
|
|
}
|
2022-07-07 12:03:45 +00:00
|
|
|
}
|
|
|
|
return common.IterateRes{}, nil
|
2021-09-13 11:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IterateBinaryObjects is a helper function which iterates over BlobStor and passes binary objects to f.
|
2022-06-21 07:52:03 +00:00
|
|
|
// Errors related to object reading and unmarshaling are logged and skipped.
|
2022-07-06 14:09:50 +00:00
|
|
|
func IterateBinaryObjects(blz *BlobStor, f func(addr oid.Address, data []byte, descriptor []byte) error) error {
|
2022-07-07 12:03:45 +00:00
|
|
|
var prm common.IteratePrm
|
2021-09-13 11:51:17 +00:00
|
|
|
|
2022-07-07 12:03:45 +00:00
|
|
|
prm.Handler = func(elem common.IterationElement) error {
|
|
|
|
return f(elem.Address, elem.ObjectData, elem.StorageID)
|
|
|
|
}
|
|
|
|
prm.IgnoreErrors = true
|
|
|
|
prm.ErrorHandler = func(addr oid.Address, err error) error {
|
2022-06-21 07:52:03 +00:00
|
|
|
blz.log.Warn("error occurred during the iteration",
|
|
|
|
zap.Stringer("address", addr),
|
|
|
|
zap.String("err", err.Error()))
|
|
|
|
return nil
|
2022-07-07 12:03:45 +00:00
|
|
|
}
|
2021-09-13 11:51:17 +00:00
|
|
|
|
|
|
|
_, err := blz.Iterate(prm)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|