2022-11-17 06:06:59 +00:00
|
|
|
package blobovnicza
|
|
|
|
|
|
|
|
import (
|
2023-06-20 08:24:14 +00:00
|
|
|
"context"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2022-11-17 06:06:59 +00:00
|
|
|
"go.etcd.io/bbolt"
|
2023-06-20 08:24:14 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
2022-11-17 06:06:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Exists check if object with the specified address is stored in b.
|
2023-06-20 08:24:14 +00:00
|
|
|
func (b *Blobovnicza) Exists(ctx context.Context, addr oid.Address) (bool, error) {
|
2023-10-31 11:56:55 +00:00
|
|
|
exists := false
|
2022-11-17 06:06:59 +00:00
|
|
|
|
2023-06-20 08:24:14 +00:00
|
|
|
_, span := tracing.StartSpanFromContext(ctx, "Blobovnicza.Exists",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("path", b.path),
|
|
|
|
attribute.String("address", addr.EncodeToString()),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
addrKey := addressKey(addr)
|
|
|
|
|
2022-11-17 06:06:59 +00:00
|
|
|
err := b.boltDB.View(func(tx *bbolt.Tx) error {
|
2023-09-27 13:25:15 +00:00
|
|
|
return tx.ForEach(func(bucketName []byte, buck *bbolt.Bucket) error {
|
2023-10-12 12:25:16 +00:00
|
|
|
if isNonDataBucket(bucketName) {
|
2023-09-27 13:25:15 +00:00
|
|
|
return nil
|
|
|
|
}
|
2022-11-17 06:06:59 +00:00
|
|
|
exists = buck.Get(addrKey) != nil
|
|
|
|
if exists {
|
|
|
|
return errInterruptForEach
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
if err == errInterruptForEach {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
return exists, err
|
|
|
|
}
|