From b2d4cc556e66f5a118706e9c44964ca2dce8a14e Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 23 Aug 2022 11:43:01 +0300 Subject: [PATCH] [#1686] blobovnicza: Remove `IterateObjects` It is used only once, makes sense to inline. Signed-off-by: Evgenii Stratonikov --- .../blobovnicza/blobovnicza_test.go | 55 ------------------- .../blobovnicza/iterate.go | 13 ----- .../blobstor/blobovniczatree/iterate.go | 13 +++-- 3 files changed, 9 insertions(+), 72 deletions(-) diff --git a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go index 1c07700248..dd46a52996 100644 --- a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go +++ b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go @@ -1,7 +1,6 @@ package blobovnicza import ( - "encoding/binary" "errors" "math/rand" "os" @@ -106,57 +105,3 @@ func TestBlobovnicza(t *testing.T) { require.NoError(t, blz.Close()) } - -func TestIterateObjects(t *testing.T) { - p := t.Name() - - // create Blobovnicza instance - blz := New( - WithPath(p), - WithObjectSizeLimit(1<<10), - WithFullSizeLimit(100<<10), - ) - - defer os.Remove(p) - - // open Blobovnicza - require.NoError(t, blz.Open()) - - // initialize Blobovnicza - require.NoError(t, blz.Init()) - - const objNum = 5 - - mObjs := make(map[string][]byte) - - for i := uint64(0); i < objNum; i++ { - data := make([]byte, 8) // actual data doesn't really matter for test - - binary.BigEndian.PutUint64(data, i) - - mObjs[string(data)] = data - } - - var putPrm PutPrm - - for _, v := range mObjs { - putPrm.SetAddress(oidtest.Address()) - putPrm.SetMarshaledObject(v) - - _, err := blz.Put(putPrm) - require.NoError(t, err) - } - - err := IterateObjects(blz, func(_ oid.Address, data []byte) error { - v, ok := mObjs[string(data)] - require.True(t, ok) - - require.Equal(t, v, data) - - delete(mObjs, string(data)) - - return nil - }) - require.NoError(t, err) - require.Empty(t, mObjs) -} diff --git a/pkg/local_object_storage/blobovnicza/iterate.go b/pkg/local_object_storage/blobovnicza/iterate.go index 5a622f2f39..70f44f0368 100644 --- a/pkg/local_object_storage/blobovnicza/iterate.go +++ b/pkg/local_object_storage/blobovnicza/iterate.go @@ -146,19 +146,6 @@ func (b *Blobovnicza) Iterate(prm IteratePrm) (IterateRes, error) { return IterateRes{}, nil } -// IterateObjects is a helper function which iterates over Blobovnicza and passes binary objects to f. -func IterateObjects(blz *Blobovnicza, f func(addr oid.Address, data []byte) error) error { - var prm IteratePrm - - prm.SetHandler(func(elem IterationElement) error { - return f(elem.Address(), elem.ObjectData()) - }) - - _, err := blz.Iterate(prm) - - return err -} - // IterateAddresses is a helper function which iterates over Blobovnicza and passes addresses of the objects to f. func IterateAddresses(blz *Blobovnicza, f func(oid.Address) error) error { var prm IteratePrm diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go b/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go index 41ab2c9325..f1bc68d638 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/iterate.go @@ -13,12 +13,13 @@ import ( // Iterate iterates over all objects in b. func (b *Blobovniczas) Iterate(prm common.IteratePrm) (common.IterateRes, error) { return common.IterateRes{}, b.iterateBlobovniczas(prm.IgnoreErrors, func(p string, blz *blobovnicza.Blobovnicza) error { - return blobovnicza.IterateObjects(blz, func(addr oid.Address, data []byte) error { - data, err := b.compression.Decompress(data) + var subPrm blobovnicza.IteratePrm + subPrm.SetHandler(func(elem blobovnicza.IterationElement) error { + data, err := b.compression.Decompress(elem.ObjectData()) if err != nil { if prm.IgnoreErrors { if prm.ErrorHandler != nil { - return prm.ErrorHandler(addr, err) + return prm.ErrorHandler(elem.Address(), err) } return nil } @@ -26,11 +27,15 @@ func (b *Blobovniczas) Iterate(prm common.IteratePrm) (common.IterateRes, error) } return prm.Handler(common.IterationElement{ - Address: addr, + Address: elem.Address(), ObjectData: data, StorageID: []byte(p), }) }) + subPrm.DecodeAddresses() + + _, err := blz.Iterate(subPrm) + return err }) }