From 137e987a4e65ee253da0e16f4bcd602619b73c0d Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Wed, 15 Nov 2023 13:12:23 +0300 Subject: [PATCH] [#655] storage: Drop `LazyHandler` LazyHandler is implemented and used incorrectly. Signed-off-by: Dmitrii Stepanov --- .../blobstor/blobovniczatree/iterate.go | 4 +-- .../blobstor/common/iterate.go | 1 - .../blobstor/fstree/fstree.go | 35 ++++++++----------- .../blobstor/internal/blobstortest/iterate.go | 27 -------------- .../blobstor/memstore/memstore.go | 4 --- .../writecache/writecachebbolt/flush.go | 17 +++------ 6 files changed, 19 insertions(+), 69 deletions(-) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go b/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go index a2afbb8aa..7129e088a 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go @@ -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() diff --git a/pkg/local_object_storage/blobstor/common/iterate.go b/pkg/local_object_storage/blobstor/common/iterate.go index a6f0da26b..1fbb08d32 100644 --- a/pkg/local_object_storage/blobstor/common/iterate.go +++ b/pkg/local_object_storage/blobstor/common/iterate.go @@ -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 } diff --git a/pkg/local_object_storage/blobstor/fstree/fstree.go b/pkg/local_object_storage/blobstor/fstree/fstree.go index bf3400bcd..06309f53c 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree.go @@ -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 } diff --git a/pkg/local_object_storage/blobstor/internal/blobstortest/iterate.go b/pkg/local_object_storage/blobstor/internal/blobstortest/iterate.go index 72f107664..c73a663b6 100644 --- a/pkg/local_object_storage/blobstor/internal/blobstortest/iterate.go +++ b/pkg/local_object_storage/blobstor/internal/blobstortest/iterate.go @@ -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) diff --git a/pkg/local_object_storage/blobstor/memstore/memstore.go b/pkg/local_object_storage/blobstor/memstore/memstore.go index 9428f457f..63e1a3e99 100644 --- a/pkg/local_object_storage/blobstor/memstore/memstore.go +++ b/pkg/local_object_storage/blobstor/memstore/memstore.go @@ -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)) diff --git a/pkg/local_object_storage/writecache/writecachebbolt/flush.go b/pkg/local_object_storage/writecache/writecachebbolt/flush.go index 9e46226d1..9efee1dda 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/flush.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/flush.go @@ -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