forked from TrueCloudLab/frostfs-node
[#655] storage: Drop LazyHandler
LazyHandler is implemented and used incorrectly. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
4d5be5ccb5
commit
137e987a4e
6 changed files with 19 additions and 69 deletions
|
@ -53,9 +53,7 @@ func (b *Blobovniczas) Iterate(ctx context.Context, prm common.IteratePrm) (comm
|
||||||
StorageID: []byte(p),
|
StorageID: []byte(p),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return prm.LazyHandler(elem.Address(), func() ([]byte, error) {
|
return nil
|
||||||
return data, err
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
subPrm.DecodeAddresses()
|
subPrm.DecodeAddresses()
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ type IterationHandler func(IterationElement) error
|
||||||
// IteratePrm groups the parameters of Iterate operation.
|
// IteratePrm groups the parameters of Iterate operation.
|
||||||
type IteratePrm struct {
|
type IteratePrm struct {
|
||||||
Handler IterationHandler
|
Handler IterationHandler
|
||||||
LazyHandler func(oid.Address, func() ([]byte, error)) error
|
|
||||||
IgnoreErrors bool
|
IgnoreErrors bool
|
||||||
ErrorHandler func(oid.Address, error) error
|
ErrorHandler func(oid.Address, error) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,31 +188,24 @@ func (t *FSTree) iterate(ctx context.Context, depth uint64, curPath []string, pr
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if prm.LazyHandler != nil {
|
if err == nil {
|
||||||
err = prm.LazyHandler(addr, func() ([]byte, error) {
|
data, err = t.Decompress(data)
|
||||||
return data, err
|
}
|
||||||
})
|
if err != nil {
|
||||||
} else {
|
if prm.IgnoreErrors {
|
||||||
if err == nil {
|
if prm.ErrorHandler != nil {
|
||||||
data, err = t.Decompress(data)
|
return prm.ErrorHandler(addr, err)
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
if prm.IgnoreErrors {
|
|
||||||
if prm.ErrorHandler != nil {
|
|
||||||
return prm.ErrorHandler(addr, err)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
return err
|
continue
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
err = prm.Handler(common.IterationElement{
|
|
||||||
Address: addr,
|
|
||||||
ObjectData: data,
|
|
||||||
StorageID: []byte{},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = prm.Handler(common.IterationElement{
|
||||||
|
Address: addr,
|
||||||
|
ObjectData: data,
|
||||||
|
StorageID: []byte{},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
"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"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,8 +29,6 @@ func TestIterate(t *testing.T, cons Constructor, min, max uint64) {
|
||||||
|
|
||||||
runTestNormalHandler(t, s, objects)
|
runTestNormalHandler(t, s, objects)
|
||||||
|
|
||||||
runTestLazyHandler(t, s, objects)
|
|
||||||
|
|
||||||
runTestIgnoreLogicalErrors(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) {
|
func runTestIgnoreLogicalErrors(t *testing.T, s common.Storage, objects []objectDesc) {
|
||||||
t.Run("ignore errors doesn't work for logical errors", func(t *testing.T) {
|
t.Run("ignore errors doesn't work for logical errors", func(t *testing.T) {
|
||||||
seen := make(map[string]objectDesc)
|
seen := make(map[string]objectDesc)
|
||||||
|
|
|
@ -154,10 +154,6 @@ func (s *memstoreImpl) Iterate(_ context.Context, req common.IteratePrm) (common
|
||||||
if err := req.Handler(elem); err != nil {
|
if err := req.Handler(elem); err != nil {
|
||||||
return common.IterateRes{}, err
|
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:
|
default:
|
||||||
if !req.IgnoreErrors {
|
if !req.IgnoreErrors {
|
||||||
return common.IterateRes{}, logicerr.Wrap(fmt.Errorf("(%T) no Handler or LazyHandler set for IteratePrm", s))
|
return common.IterateRes{}, logicerr.Wrap(fmt.Errorf("(%T) no Handler or LazyHandler set for IteratePrm", s))
|
||||||
|
|
|
@ -180,20 +180,11 @@ func (c *cache) reportFlushError(msg string, addr string, err error) {
|
||||||
func (c *cache) flushFSTree(ctx context.Context, ignoreErrors bool) error {
|
func (c *cache) flushFSTree(ctx context.Context, ignoreErrors bool) error {
|
||||||
var prm common.IteratePrm
|
var prm common.IteratePrm
|
||||||
prm.IgnoreErrors = ignoreErrors
|
prm.IgnoreErrors = ignoreErrors
|
||||||
prm.LazyHandler = func(addr oid.Address, f func() ([]byte, error)) error {
|
prm.Handler = func(e common.IterationElement) error {
|
||||||
sAddr := addr.EncodeToString()
|
sAddr := e.Address.EncodeToString()
|
||||||
|
|
||||||
data, err := f()
|
|
||||||
if err != nil {
|
|
||||||
c.reportFlushError(logs.FSTreeCantReadFile, sAddr, metaerr.Wrap(err))
|
|
||||||
if ignoreErrors {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var obj objectSDK.Object
|
var obj objectSDK.Object
|
||||||
err = obj.Unmarshal(data)
|
err := obj.Unmarshal(e.ObjectData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.reportFlushError(logs.FSTreeCantUnmarshalObject, sAddr, metaerr.Wrap(err))
|
c.reportFlushError(logs.FSTreeCantUnmarshalObject, sAddr, metaerr.Wrap(err))
|
||||||
if ignoreErrors {
|
if ignoreErrors {
|
||||||
|
@ -202,7 +193,7 @@ func (c *cache) flushFSTree(ctx context.Context, ignoreErrors bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.flushObject(ctx, &obj, data, writecache.StorageTypeFSTree)
|
err = c.flushObject(ctx, &obj, e.ObjectData, writecache.StorageTypeFSTree)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ignoreErrors {
|
if ignoreErrors {
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue