forked from TrueCloudLab/frostfs-node
[#216] blobovnicza: Implement main methods and logic
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
52b0c1f19a
commit
07e998d846
10 changed files with 627 additions and 0 deletions
46
pkg/local_object_storage/blobovnicza/iterate.go
Normal file
46
pkg/local_object_storage/blobovnicza/iterate.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package blobovnicza
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
func (b *Blobovnicza) iterateBuckets(tx *bbolt.Tx, f func(uint64, uint64, *bbolt.Bucket) (bool, error)) error {
|
||||
return b.iterateBucketKeys(func(lower uint64, upper uint64, key []byte) (bool, error) {
|
||||
buck := tx.Bucket(key)
|
||||
if buck == nil {
|
||||
// expected to happen:
|
||||
// - before initialization step (incorrect usage by design)
|
||||
// - if DB is corrupted (in future this case should be handled)
|
||||
return false, errors.Errorf("(%T) could not get bucket %s", b, stringifyBounds(lower, upper))
|
||||
}
|
||||
|
||||
return f(lower, upper, buck)
|
||||
})
|
||||
}
|
||||
|
||||
func (b *Blobovnicza) iterateBucketKeys(f func(uint64, uint64, []byte) (bool, error)) error {
|
||||
return b.iterateBounds(func(lower, upper uint64) (bool, error) {
|
||||
return f(lower, upper, bucketKeyFromBounds(upper))
|
||||
})
|
||||
}
|
||||
|
||||
func (b *Blobovnicza) iterateBounds(f func(uint64, uint64) (bool, error)) error {
|
||||
for upper := firstBucketBound; upper <= b.objSizeLimit; upper *= 2 {
|
||||
var lower uint64
|
||||
|
||||
if upper == firstBucketBound {
|
||||
lower = 0
|
||||
} else {
|
||||
lower = upper/2 + 1
|
||||
}
|
||||
|
||||
if stop, err := f(lower, upper); err != nil {
|
||||
return err
|
||||
} else if stop {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue