diff --git a/pkg/local_object_storage/metabase/delete.go b/pkg/local_object_storage/metabase/delete.go index cc54e58f5..2fc21a991 100644 --- a/pkg/local_object_storage/metabase/delete.go +++ b/pkg/local_object_storage/metabase/delete.go @@ -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 { diff --git a/pkg/local_object_storage/metabase/exists.go b/pkg/local_object_storage/metabase/exists.go index 399a1f899..4a27d875d 100644 --- a/pkg/local_object_storage/metabase/exists.go +++ b/pkg/local_object_storage/metabase/exists.go @@ -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) diff --git a/pkg/local_object_storage/metabase/get.go b/pkg/local_object_storage/metabase/get.go index 6f2997f2d..baff225c0 100644 --- a/pkg/local_object_storage/metabase/get.go +++ b/pkg/local_object_storage/metabase/get.go @@ -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) diff --git a/pkg/local_object_storage/metabase/inhume.go b/pkg/local_object_storage/metabase/inhume.go index 4fb304def..63632ee70 100644 --- a/pkg/local_object_storage/metabase/inhume.go +++ b/pkg/local_object_storage/metabase/inhume.go @@ -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) diff --git a/pkg/local_object_storage/metabase/list.go b/pkg/local_object_storage/metabase/list.go index e1c3ce4a6..becbaee9b 100644 --- a/pkg/local_object_storage/metabase/list.go +++ b/pkg/local_object_storage/metabase/list.go @@ -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 }) diff --git a/pkg/local_object_storage/metabase/movable.go b/pkg/local_object_storage/metabase/movable.go index f7d15473d..abf47171a 100644 --- a/pkg/local_object_storage/metabase/movable.go +++ b/pkg/local_object_storage/metabase/movable.go @@ -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 } diff --git a/pkg/local_object_storage/metabase/put.go b/pkg/local_object_storage/metabase/put.go index 9fd18a330..21c0b93a3 100644 --- a/pkg/local_object_storage/metabase/put.go +++ b/pkg/local_object_storage/metabase/put.go @@ -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) }) diff --git a/pkg/local_object_storage/metabase/select.go b/pkg/local_object_storage/metabase/select.go index 2eaf9dfee..f3ae6bafa 100644 --- a/pkg/local_object_storage/metabase/select.go +++ b/pkg/local_object_storage/metabase/select.go @@ -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 diff --git a/pkg/local_object_storage/metabase/small.go b/pkg/local_object_storage/metabase/small.go index d39594618..6c88a3474 100644 --- a/pkg/local_object_storage/metabase/small.go +++ b/pkg/local_object_storage/metabase/small.go @@ -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)