[#1460] meta: Do not use pointers as the results

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-05-31 14:43:08 +03:00 committed by Pavel Karpy
parent a580429996
commit 9b2932609b
9 changed files with 20 additions and 29 deletions

View file

@ -50,7 +50,7 @@ type referenceNumber struct {
type referenceCounter map[string]*referenceNumber
// Delete removed object records from metabase indexes.
func (db *DB) Delete(prm DeletePrm) (*DeleteRes, error) {
func (db *DB) Delete(prm DeletePrm) (DeleteRes, error) {
err := db.boltDB.Update(func(tx *bbolt.Tx) error {
return db.deleteGroup(tx, prm.addrs)
})
@ -61,7 +61,7 @@ func (db *DB) Delete(prm DeletePrm) (*DeleteRes, error) {
storagelog.OpField("metabase DELETE"))
}
}
return nil, err
return DeleteRes{}, err
}
func (db *DB) deleteGroup(tx *bbolt.Tx, addrs []oid.Address) error {

View file

@ -31,7 +31,7 @@ func (p *ExistsPrm) WithAddress(addr oid.Address) {
}
// Exists returns the fact that the object is in the metabase.
func (p *ExistsRes) Exists() bool {
func (p ExistsRes) Exists() bool {
return p.exists
}
@ -54,9 +54,7 @@ func Exists(db *DB, addr oid.Address) (bool, error) {
// returns true if addr is in primary index or false if it is not.
//
// Returns an error of type apistatus.ObjectAlreadyRemoved if object has been placed in graveyard.
func (db *DB) Exists(prm ExistsPrm) (res *ExistsRes, err error) {
res = new(ExistsRes)
func (db *DB) Exists(prm ExistsPrm) (res ExistsRes, err error) {
err = db.boltDB.View(func(tx *bbolt.Tx) error {
res.exists, err = db.exists(tx, prm.addr)

View file

@ -40,7 +40,7 @@ func (p *GetPrm) WithRaw(raw bool) {
}
// Header returns the requested object header.
func (r *GetRes) Header() *objectSDK.Object {
func (r GetRes) Header() *objectSDK.Object {
return r.hdr
}
@ -75,9 +75,7 @@ func GetRaw(db *DB, addr oid.Address, raw bool) (*objectSDK.Object, error) {
//
// Returns an error of type apistatus.ObjectNotFound if object is missing in DB.
// Returns an error of type apistatus.ObjectAlreadyRemoved if object has been placed in graveyard.
func (db *DB) Get(prm GetPrm) (res *GetRes, err error) {
res = new(GetRes)
func (db *DB) Get(prm GetPrm) (res GetRes, err error) {
err = db.boltDB.View(func(tx *bbolt.Tx) error {
res.hdr, err = db.get(tx, prm.addr, true, prm.raw)

View file

@ -66,7 +66,7 @@ var errBreakBucketForEach = errors.New("bucket ForEach break")
//
// Allows inhuming non-locked objects only. Returns apistatus.ObjectLocked
// if at least one object is locked.
func (db *DB) Inhume(prm InhumePrm) (res *InhumeRes, err error) {
func (db *DB) Inhume(prm InhumePrm) (res InhumeRes, err error) {
err = db.boltDB.Update(func(tx *bbolt.Tx) error {
garbageBKT := tx.Bucket(garbageBucketName)

View file

@ -79,9 +79,8 @@ func ListWithCursor(db *DB, count uint32, cursor *Cursor) ([]oid.Address, *Curso
//
// Returns ErrEndOfListing if there are no more objects to return or count
// parameter set to zero.
func (db *DB) ListWithCursor(prm ListPrm) (res *ListRes, err error) {
func (db *DB) ListWithCursor(prm ListPrm) (res ListRes, err error) {
err = db.boltDB.View(func(tx *bbolt.Tx) error {
res = new(ListRes)
res.addrList, res.cursor, err = db.listWithCursor(tx, prm.count, prm.cursor)
return err
})

View file

@ -61,7 +61,7 @@ func ToMoveIt(db *DB, addr oid.Address) error {
// ToMoveIt marks objects to move it into another shard. This useful for
// faster HRW fetching.
func (db *DB) ToMoveIt(prm ToMoveItPrm) (res *ToMoveItRes, err error) {
func (db *DB) ToMoveIt(prm ToMoveItPrm) (res ToMoveItRes, err error) {
err = db.boltDB.Update(func(tx *bbolt.Tx) error {
toMoveIt, err := tx.CreateBucketIfNotExists(toMoveItBucketName)
if err != nil {
@ -84,7 +84,7 @@ func DoNotMove(db *DB, addr oid.Address) error {
}
// DoNotMove removes `MoveIt` mark from the object.
func (db *DB) DoNotMove(prm DoNotMovePrm) (res *DoNotMoveRes, err error) {
func (db *DB) DoNotMove(prm DoNotMovePrm) (res DoNotMoveRes, err error) {
err = db.boltDB.Update(func(tx *bbolt.Tx) error {
toMoveIt := tx.Bucket(toMoveItBucketName)
if toMoveIt == nil {
@ -108,7 +108,7 @@ func Movable(db *DB) ([]oid.Address, error) {
}
// Movable returns list of marked objects to move into other shard.
func (db *DB) Movable(_ MovablePrm) (*MovableRes, error) {
func (db *DB) Movable(_ MovablePrm) (MovableRes, error) {
var strAddrs []string
err := db.boltDB.View(func(tx *bbolt.Tx) error {
@ -124,7 +124,7 @@ func (db *DB) Movable(_ MovablePrm) (*MovableRes, error) {
})
})
if err != nil {
return nil, err
return MovableRes{}, err
}
// we can parse strings to structures in-place, but probably it seems
@ -135,12 +135,12 @@ func (db *DB) Movable(_ MovablePrm) (*MovableRes, error) {
for i := range strAddrs {
err = decodeAddressFromKey(&addrs[i], []byte(strAddrs[i]))
if err != nil {
return nil, fmt.Errorf("can't parse object address %v: %w",
return MovableRes{}, fmt.Errorf("can't parse object address %v: %w",
strAddrs[i], err)
}
}
return &MovableRes{
return MovableRes{
addrList: addrs,
}, nil
}

View file

@ -70,7 +70,7 @@ func Put(db *DB, obj *objectSDK.Object, id *blobovnicza.ID) error {
// Big objects have nil blobovniczaID.
//
// Returns an error of type apistatus.ObjectAlreadyRemoved if object has been placed in graveyard.
func (db *DB) Put(prm PutPrm) (res *PutRes, err error) {
func (db *DB) Put(prm PutPrm) (res PutRes, err error) {
err = db.boltDB.Batch(func(tx *bbolt.Tx) error {
return db.put(tx, prm.obj, prm.id, nil)
})

View file

@ -73,9 +73,7 @@ func Select(db *DB, cnr cid.ID, fs object.SearchFilters) ([]oid.Address, error)
}
// Select returns list of addresses of objects that match search filters.
func (db *DB) Select(prm SelectPrm) (res *SelectRes, err error) {
res = new(SelectRes)
func (db *DB) Select(prm SelectPrm) (res SelectRes, err error) {
if blindlyProcess(prm.filters) {
return res, nil
}
@ -525,8 +523,8 @@ func (db *DB) matchSlowFilters(tx *bbolt.Tx, addr oid.Address, f object.SearchFi
// groupFilters divides filters in two groups: fast and slow. Fast filters
// processed by indexes and slow filters processed after by unmarshaling
// object headers.
func groupFilters(filters object.SearchFilters) (*filterGroup, error) {
res := &filterGroup{
func groupFilters(filters object.SearchFilters) (filterGroup, error) {
res := filterGroup{
fastFilters: make(object.SearchFilters, 0, len(filters)),
slowFilters: make(object.SearchFilters, 0, len(filters)),
}
@ -536,7 +534,7 @@ func groupFilters(filters object.SearchFilters) (*filterGroup, error) {
case v2object.FilterHeaderContainerID: // support deprecated field
err := res.cnr.DecodeString(filters[i].Value())
if err != nil {
return nil, fmt.Errorf("can't parse container id: %w", err)
return filterGroup{}, fmt.Errorf("can't parse container id: %w", err)
}
res.withCnrFilter = true

View file

@ -48,9 +48,7 @@ func IsSmall(db *DB, addr oid.Address) (*blobovnicza.ID, error) {
// 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.
func (db *DB) IsSmall(prm IsSmallPrm) (res *IsSmallRes, err error) {
res = new(IsSmallRes)
func (db *DB) IsSmall(prm IsSmallPrm) (res IsSmallRes, err error) {
err = db.boltDB.View(func(tx *bbolt.Tx) error {
res.id, err = db.isSmall(tx, prm.addr)