Dmitrii Stepanov
e0cb29cb6e
Blobovnicza initialization take a long time because of bucket Stat() call. So now blobovnicza stores counters in META bucket. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
45 lines
1 KiB
Go
45 lines
1 KiB
Go
package blobovnicza
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"go.etcd.io/bbolt"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// Exists check if object with the specified address is stored in b.
|
|
func (b *Blobovnicza) Exists(ctx context.Context, addr oid.Address) (bool, error) {
|
|
var (
|
|
exists = false
|
|
)
|
|
|
|
_, span := tracing.StartSpanFromContext(ctx, "Blobovnicza.Exists",
|
|
trace.WithAttributes(
|
|
attribute.String("path", b.path),
|
|
attribute.String("address", addr.EncodeToString()),
|
|
))
|
|
defer span.End()
|
|
|
|
addrKey := addressKey(addr)
|
|
|
|
err := b.boltDB.View(func(tx *bbolt.Tx) error {
|
|
return tx.ForEach(func(bucketName []byte, buck *bbolt.Bucket) error {
|
|
if isNonDataBucket(bucketName) {
|
|
return nil
|
|
}
|
|
exists = buck.Get(addrKey) != nil
|
|
if exists {
|
|
return errInterruptForEach
|
|
}
|
|
return nil
|
|
})
|
|
})
|
|
|
|
if err == errInterruptForEach {
|
|
err = nil
|
|
}
|
|
return exists, err
|
|
}
|