[#655] storage: Drop LazyHandler

LazyHandler is implemented and used incorrectly.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-11-15 13:12:23 +03:00
parent 4d5be5ccb5
commit 137e987a4e
6 changed files with 19 additions and 69 deletions

View file

@ -53,9 +53,7 @@ func (b *Blobovniczas) Iterate(ctx context.Context, prm common.IteratePrm) (comm
StorageID: []byte(p),
})
}
return prm.LazyHandler(elem.Address(), func() ([]byte, error) {
return data, err
})
return nil
})
subPrm.DecodeAddresses()

View file

@ -15,7 +15,6 @@ type IterationHandler func(IterationElement) error
// IteratePrm groups the parameters of Iterate operation.
type IteratePrm struct {
Handler IterationHandler
LazyHandler func(oid.Address, func() ([]byte, error)) error
IgnoreErrors bool
ErrorHandler func(oid.Address, error) error
}

View file

@ -188,31 +188,24 @@ func (t *FSTree) iterate(ctx context.Context, depth uint64, curPath []string, pr
continue
}
if prm.LazyHandler != nil {
err = prm.LazyHandler(addr, func() ([]byte, error) {
return data, err
})
} else {
if err == nil {
data, err = t.Decompress(data)
}
if err != nil {
if prm.IgnoreErrors {
if prm.ErrorHandler != nil {
return prm.ErrorHandler(addr, err)
}
continue
if err == nil {
data, err = t.Decompress(data)
}
if err != nil {
if prm.IgnoreErrors {
if prm.ErrorHandler != nil {
return prm.ErrorHandler(addr, err)
}
return err
continue
}
err = prm.Handler(common.IterationElement{
Address: addr,
ObjectData: data,
StorageID: []byte{},
})
return err
}
err = prm.Handler(common.IterationElement{
Address: addr,
ObjectData: data,
StorageID: []byte{},
})
if err != nil {
return err
}

View file

@ -6,7 +6,6 @@ import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"github.com/stretchr/testify/require"
)
@ -30,8 +29,6 @@ func TestIterate(t *testing.T, cons Constructor, min, max uint64) {
runTestNormalHandler(t, s, objects)
runTestLazyHandler(t, s, objects)
runTestIgnoreLogicalErrors(t, s, objects)
}
@ -62,30 +59,6 @@ func runTestNormalHandler(t *testing.T, s common.Storage, objects []objectDesc)
})
}
func runTestLazyHandler(t *testing.T, s common.Storage, objects []objectDesc) {
t.Run("lazy handler", func(t *testing.T) {
seen := make(map[string]func() ([]byte, error))
var iterPrm common.IteratePrm
iterPrm.LazyHandler = func(addr oid.Address, f func() ([]byte, error)) error {
seen[addr.String()] = f
return nil
}
_, err := s.Iterate(context.Background(), iterPrm)
require.NoError(t, err)
require.Equal(t, len(objects), len(seen))
for i := range objects {
f, ok := seen[objects[i].addr.String()]
require.True(t, ok)
data, err := f()
require.NoError(t, err)
require.Equal(t, objects[i].raw, data)
}
})
}
func runTestIgnoreLogicalErrors(t *testing.T, s common.Storage, objects []objectDesc) {
t.Run("ignore errors doesn't work for logical errors", func(t *testing.T) {
seen := make(map[string]objectDesc)

View file

@ -154,10 +154,6 @@ func (s *memstoreImpl) Iterate(_ context.Context, req common.IteratePrm) (common
if err := req.Handler(elem); err != nil {
return common.IterateRes{}, err
}
case req.LazyHandler != nil:
if err := req.LazyHandler(elem.Address, func() ([]byte, error) { return elem.ObjectData, nil }); err != nil {
return common.IterateRes{}, err
}
default:
if !req.IgnoreErrors {
return common.IterateRes{}, logicerr.Wrap(fmt.Errorf("(%T) no Handler or LazyHandler set for IteratePrm", s))

View file

@ -180,20 +180,11 @@ func (c *cache) reportFlushError(msg string, addr string, err error) {
func (c *cache) flushFSTree(ctx context.Context, ignoreErrors bool) error {
var prm common.IteratePrm
prm.IgnoreErrors = ignoreErrors
prm.LazyHandler = func(addr oid.Address, f func() ([]byte, error)) error {
sAddr := addr.EncodeToString()
data, err := f()
if err != nil {
c.reportFlushError(logs.FSTreeCantReadFile, sAddr, metaerr.Wrap(err))
if ignoreErrors {
return nil
}
return err
}
prm.Handler = func(e common.IterationElement) error {
sAddr := e.Address.EncodeToString()
var obj objectSDK.Object
err = obj.Unmarshal(data)
err := obj.Unmarshal(e.ObjectData)
if err != nil {
c.reportFlushError(logs.FSTreeCantUnmarshalObject, sAddr, metaerr.Wrap(err))
if ignoreErrors {
@ -202,7 +193,7 @@ func (c *cache) flushFSTree(ctx context.Context, ignoreErrors bool) error {
return err
}
err = c.flushObject(ctx, &obj, data, writecache.StorageTypeFSTree)
err = c.flushObject(ctx, &obj, e.ObjectData, writecache.StorageTypeFSTree)
if err != nil {
if ignoreErrors {
return nil