Skip to content
2 changes: 1 addition & 1 deletion cmd/neofs-lancet/internal/storage/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func getFunc(cmd *cobra.Command, _ []string) error {
}
defer storage.Close()

obj, err := storage.Get(addr)
obj, err := storage.Get(cmd.Context(), addr)
if err != nil {
return fmt.Errorf("could not fetch object: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-lancet/internal/storage/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func listFunc(cmd *cobra.Command, _ []string) error {
cursor *engine.Cursor
)
for {
addrs, cursor, err = storage.ListWithCursor(1024, cursor)
addrs, cursor, err = storage.ListWithCursor(cmd.Context(), 1024, cursor)
if err != nil {
if errors.Is(err, engine.ErrEndOfListing) {
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-lancet/internal/storage/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func statusObject(cmd *cobra.Command, _ []string) error {
return err
}
defer storage.Close()
status, err := storage.ObjectStatus(addr)
status, err := storage.ObjectStatus(cmd.Context(), addr)
if err != nil {
return fmt.Errorf("could not fetch object: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-node/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func reportHandler(c *cfg, logger *zap.Logger) timer.Tick {

l.Debug("sending container reports to contract...")

idList, err := st.ListContainers()
idList, err := st.ListContainers(context.TODO())
if err != nil {
l.Warn("engine's list containers failure", zap.Error(err))
return
Expand All @@ -238,7 +238,7 @@ func reportHandler(c *cfg, logger *zap.Logger) timer.Tick {

var successes int
for _, cnr := range idList {
size, objsNum, err := st.ContainerInfo(cnr)
size, objsNum, err := st.ContainerInfo(context.TODO(), cnr)
if err != nil {
l.Warn("container's stat fetching error", zap.Stringer("cid", cnr), zap.Error(err))
return
Expand Down
12 changes: 6 additions & 6 deletions cmd/neofs-node/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func (h *headerWriter) WriteHeader(o *object.Object) error {
return nil
}

func (h headerSource) Head(address oid.Address) (*object.Object, error) {
func (h headerSource) Head(ctx context.Context, address oid.Address) (*object.Object, error) {
l := h.l.With(zap.Stringer("address", address))
l.Debug("requesting header")

Expand All @@ -534,7 +534,7 @@ func (h headerSource) Head(address oid.Address) (*object.Object, error) {
prm.WithAddress(address)
prm.WithRawFlag(true)

err := h.getsvc.Head(context.Background(), prm)
err := h.getsvc.Head(ctx, prm)
if err != nil {
return nil, fmt.Errorf("reading header: %w", err)
}
Expand Down Expand Up @@ -656,12 +656,12 @@ type storageForObjectService struct {
}

// SearchObjects implements [objectService.Storage] interface.
func (x storageForObjectService) SearchObjects(cID cid.ID, fs []objectcore.SearchFilter, attrs []string, cursor *objectcore.SearchCursor, count uint16) ([]client.SearchResultItem, []byte, error) {
return x.local.Search(cID, fs, attrs, cursor, count)
func (x storageForObjectService) SearchObjects(ctx context.Context, cID cid.ID, fs []objectcore.SearchFilter, attrs []string, cursor *objectcore.SearchCursor, count uint16) ([]client.SearchResultItem, []byte, error) {
return x.local.Search(ctx, cID, fs, attrs, cursor, count)
}

func (x storageForObjectService) VerifyAndStoreObjectLocally(obj object.Object) error {
return x.putSvc.ValidateAndStoreObjectLocally(obj)
func (x storageForObjectService) VerifyAndStoreObjectLocally(ctx context.Context, obj object.Object) error {
return x.putSvc.ValidateAndStoreObjectLocally(ctx, obj)
}

func (x storageForObjectService) GetSessionPrivateKey(account user.ID) (ecdsa.PrivateKey, error) {
Expand Down
5 changes: 3 additions & 2 deletions cmd/neofs-node/storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"time"

"github.com/nspcc-dev/bbolt"
Expand Down Expand Up @@ -36,7 +37,7 @@ func initLocalStorage(c *cfg) {

subscribeToContainerRemoval(c, func(id cid.ID, owner user.ID) {
if owner.IsZero() {
err := ls.InhumeContainer(id)
err := ls.InhumeContainer(context.TODO(), id)
if err != nil {
c.log.Warn("inhuming container after a chain event",
zap.Stringer("cID", id), zap.Error(err))
Expand All @@ -46,7 +47,7 @@ func initLocalStorage(c *cfg) {
c.log.Info("caught container removal, marking its local objects for GC...",
zap.Stringer("container", id), zap.Stringer("owner", owner))

if err := ls.InhumeContainer(id); err != nil {
if err := ls.InhumeContainer(context.TODO(), id); err != nil {
c.log.Warn("failed to mark local objects from the removed container for GC",
zap.Stringer("container", id), zap.Error(err))
return
Expand Down
21 changes: 11 additions & 10 deletions pkg/core/object/ec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package objectcore

import (
"bytes"
"context"
"fmt"
"testing"

Expand Down Expand Up @@ -202,12 +203,12 @@ func TestFormatValidator_Validate_EC(t *testing.T) {
obj.SetParent(&parent)
tc.corruptPart(obj)
})
require.EqualError(t, v.Validate(&cp, false, true), tc.err)
require.EqualError(t, v.Validate(context.Background(), &cp, false, true), tc.err)
return
}

cp := corruptPart(t, tc.corruptPart)
require.EqualError(t, v.Validate(&cp, false, true), tc.err)
require.EqualError(t, v.Validate(context.Background(), &cp, false, true), tc.err)
})
}

Expand All @@ -218,17 +219,17 @@ func TestFormatValidator_Validate_EC(t *testing.T) {
obj.SetPayload(nil)
obj.AssociateDeleted(oidtest.ID())
})
require.EqualError(t, v.Validate(&cp, false, true), "mix of EC (__NEOFS__EC_RULE_IDX) and non-EC (__NEOFS__ASSOCIATE) attributes")
require.EqualError(t, v.Validate(context.Background(), &cp, false, true), "mix of EC (__NEOFS__EC_RULE_IDX) and non-EC (__NEOFS__ASSOCIATE) attributes")
})

t.Run("blank", func(t *testing.T) {
for i := range ecParts {
require.EqualError(t, v.Validate(&ecParts[i], true, true), "blank object with EC attributes")
require.EqualError(t, v.Validate(context.Background(), &ecParts[i], true, true), "blank object with EC attributes")
}

obj := blankValidObject(creator)
obj.SetContainerID(cnrID)
require.NoError(t, v.Validate(obj, true, true))
require.NoError(t, v.Validate(context.Background(), obj, true, true))
})

t.Run("non-EC container", func(t *testing.T) {
Expand All @@ -241,7 +242,7 @@ func TestFormatValidator_Validate_EC(t *testing.T) {
obj.SetContainerID(cnr)
})

require.EqualError(t, v.Validate(&cp, false, true), "object with EC attributes __NEOFS__EC_RULE_IDX in container without EC rules")
require.EqualError(t, v.Validate(context.Background(), &cp, false, true), "object with EC attributes __NEOFS__EC_RULE_IDX in container without EC rules")
})

t.Run("split", func(t *testing.T) {
Expand Down Expand Up @@ -312,7 +313,7 @@ func TestFormatValidator_Validate_EC(t *testing.T) {

require.NoError(t, linker.SetVerificationFields(creator))

require.NoError(t, v.Validate(&linker, false, true))
require.NoError(t, v.Validate(context.Background(), &linker, false, true))

for i := range splitParts {
parts, err := iec.Encode(irule, splitParts[i].Payload())
Expand All @@ -325,7 +326,7 @@ func TestFormatValidator_Validate_EC(t *testing.T) {
})
require.NoError(t, err)

require.NoError(t, v.Validate(&ecPart, false, true))
require.NoError(t, v.Validate(context.Background(), &ecPart, false, true))
}
}
})
Expand All @@ -339,11 +340,11 @@ func TestFormatValidator_Validate_EC(t *testing.T) {
})
require.NoError(t, err)

require.NoError(t, v.Validate(&obj, false, true))
require.NoError(t, v.Validate(context.Background(), &obj, false, true))
}
})

for i := range ecParts {
require.NoError(t, v.Validate(&ecParts[i], false, true))
require.NoError(t, v.Validate(context.Background(), &ecParts[i], false, true))
}
}
22 changes: 11 additions & 11 deletions pkg/core/object/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type DeleteHandler interface {
// LockSource is a source of lock relations between the objects.
type LockSource interface {
// IsLocked must clarify object's lock status.
IsLocked(address oid.Address) (bool, error)
IsLocked(ctx context.Context, address oid.Address) (bool, error)
}

// Locker is an object lock storage interface.
Expand Down Expand Up @@ -142,13 +142,13 @@ func NewFormatValidator(fsChain FSChain, netmapContract NetmapContract, containe
// allowAllVersions defines whether the object version is checked.
//
// Returns nil error if the object has valid structure.
func (v *FormatValidator) Validate(obj *object.Object, unprepared, allowAllVersions bool) error {
return v.validate(obj, unprepared, allowAllVersions, 0)
func (v *FormatValidator) Validate(ctx context.Context, obj *object.Object, unprepared, allowAllVersions bool) error {
return v.validate(ctx, obj, unprepared, allowAllVersions, 0)
}

const maxObjectNestingLevel = 2

func (v *FormatValidator) validate(obj *object.Object, unprepared, allowAllVersions bool, nestingLevel int) error {
func (v *FormatValidator) validate(ctx context.Context, obj *object.Object, unprepared, allowAllVersions bool, nestingLevel int) error {
if obj == nil {
return errNilObject
}
Expand Down Expand Up @@ -243,7 +243,7 @@ func (v *FormatValidator) validate(obj *object.Object, unprepared, allowAllVersi
if err := v.checkAttributes(obj); err != nil {
return fmt.Errorf("invalid attributes: %w", err)
}
if err := v.checkExpiration(*obj, expirationRequired); err != nil {
if err := v.checkExpiration(ctx, *obj, expirationRequired); err != nil {
return fmt.Errorf("expiration attribute: %w", err)
}

Expand All @@ -267,7 +267,7 @@ func (v *FormatValidator) validate(obj *object.Object, unprepared, allowAllVersi

// it is possible to have a split of a split
prepared := firstSet || splitID != nil || isEC
return v.validate(par, !prepared, allowAllVersions, nestingLevel+1)
return v.validate(ctx, par, !prepared, allowAllVersions, nestingLevel+1)
}

return nil
Expand All @@ -293,7 +293,7 @@ func (i ContentMeta) Objects() []oid.ID {
// ValidateContent validates payload content according to the object type.
// Since it operates on a finalized object it also checks for some attributes
// that can be omitted by [FormatValidator.Validate] for unprepared objects.
func (v *FormatValidator) ValidateContent(o *object.Object) error {
func (v *FormatValidator) ValidateContent(ctx context.Context, o *object.Object) error {
switch o.Type() {
case object.TypeRegular:
// ignore regular objects, they do not need payload formatting
Expand All @@ -319,7 +319,7 @@ func (v *FormatValidator) ValidateContent(o *object.Object) error {
return fmt.Errorf("reading link object's payload: %w", err)
}

err = v.sv.VerifySplit(context.Background(), cnr, firstObjID, testLink.Objects())
err = v.sv.VerifySplit(ctx, cnr, firstObjID, testLink.Objects())
if err != nil {
return fmt.Errorf("link object's split chain verification: %w", err)
}
Expand All @@ -333,7 +333,7 @@ func (v *FormatValidator) ValidateContent(o *object.Object) error {
}

if o.Type() == object.TypeTombstone {
return v.tv.VerifyTombStoneWithoutPayload(context.Background(), *o)
return v.tv.VerifyTombStoneWithoutPayload(ctx, *o)
}
default:
// ignore all other object types, they do not need payload formatting
Expand All @@ -343,7 +343,7 @@ func (v *FormatValidator) ValidateContent(o *object.Object) error {

var errExpired = errors.New("object has expired")

func (v *FormatValidator) checkExpiration(obj object.Object, expirationRequired bool) error {
func (v *FormatValidator) checkExpiration(ctx context.Context, obj object.Object, expirationRequired bool) error {
exp, err := Expiration(obj)
if err != nil {
if errors.Is(err, ErrNoExpiration) {
Expand All @@ -367,7 +367,7 @@ func (v *FormatValidator) checkExpiration(obj object.Object, expirationRequired
addr.SetContainer(cID)
addr.SetObject(oID)

locked, err := v.e.IsLocked(addr)
locked, err := v.e.IsLocked(ctx, addr)
if err != nil {
return fmt.Errorf("locking status check for an expired object: %w", err)
}
Expand Down
Loading
Loading