[#1686] blobovnicza: Remove IterateObjects

It is used only once, makes sense to inline.

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-08-23 11:43:01 +03:00 committed by fyrchik
parent 5f95498364
commit b2d4cc556e
3 changed files with 9 additions and 72 deletions

View file

@ -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)
}

View file

@ -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

View file

@ -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
})
}