2020-11-23 13:30:56 +00:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
2021-12-06 15:24:53 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
2020-11-23 13:30:56 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2020-11-23 13:30:56 +00:00
|
|
|
"go.etcd.io/bbolt"
|
|
|
|
)
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
// IsSmallPrm groups the parameters of IsSmall operation.
|
|
|
|
type IsSmallPrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2020-12-08 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// IsSmallRes groups the resulting values of IsSmall operation.
|
2020-12-08 09:56:14 +00:00
|
|
|
type IsSmallRes struct {
|
|
|
|
id *blobovnicza.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithAddress is a IsSmall option to set the object address to check.
|
2022-05-20 16:48:14 +00:00
|
|
|
func (p *IsSmallPrm) WithAddress(addr oid.Address) {
|
2020-12-08 09:56:14 +00:00
|
|
|
if p != nil {
|
|
|
|
p.addr = addr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BlobovniczaID returns blobovnicza identifier.
|
2022-05-20 16:48:14 +00:00
|
|
|
func (r IsSmallRes) BlobovniczaID() *blobovnicza.ID {
|
2020-12-08 09:56:14 +00:00
|
|
|
return r.id
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsSmall wraps work with DB.IsSmall method with specified
|
|
|
|
// address and other parameters by default. Returns only
|
|
|
|
// the blobovnicza identifier.
|
2022-05-31 17:00:41 +00:00
|
|
|
func IsSmall(db *DB, addr oid.Address) (*blobovnicza.ID, error) {
|
2022-05-20 16:48:14 +00:00
|
|
|
var isSmallPrm IsSmallPrm
|
|
|
|
isSmallPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
r, err := db.IsSmall(isSmallPrm)
|
2020-12-08 09:56:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.BlobovniczaID(), nil
|
|
|
|
}
|
|
|
|
|
2020-11-23 13:30:56 +00:00
|
|
|
// IsSmall returns blobovniczaID for small objects and nil for big objects.
|
|
|
|
// Small objects stored in blobovnicza instances. Big objects stored in FS by
|
|
|
|
// shallow path which is calculated from address and therefore it is not
|
|
|
|
// indexed in metabase.
|
2022-05-20 16:48:14 +00:00
|
|
|
func (db *DB) IsSmall(prm IsSmallPrm) (res *IsSmallRes, err error) {
|
2020-12-08 09:56:14 +00:00
|
|
|
res = new(IsSmallRes)
|
|
|
|
|
2020-11-23 13:30:56 +00:00
|
|
|
err = db.boltDB.View(func(tx *bbolt.Tx) error {
|
2020-12-08 09:56:14 +00:00
|
|
|
res.id, err = db.isSmall(tx, prm.addr)
|
2020-11-23 13:30:56 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
return
|
2020-11-23 13:30:56 +00:00
|
|
|
}
|
2020-11-27 17:47:58 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (db *DB) isSmall(tx *bbolt.Tx, addr oid.Address) (*blobovnicza.ID, error) {
|
|
|
|
smallBucket := tx.Bucket(smallBucketName(addr.Container()))
|
2020-11-27 17:47:58 +00:00
|
|
|
if smallBucket == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
blobovniczaID := smallBucket.Get(objectKey(addr.Object()))
|
2020-12-01 13:33:59 +00:00
|
|
|
if len(blobovniczaID) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2020-11-27 17:47:58 +00:00
|
|
|
|
2021-12-06 15:24:53 +00:00
|
|
|
return blobovnicza.NewIDFromBytes(slice.Copy(blobovniczaID)), nil
|
2020-11-27 17:47:58 +00:00
|
|
|
}
|