Skip to content

Commit

Permalink
engine: move metrics collection into entry methods
Browse files Browse the repository at this point in the history
I believe these should be counted irrespective of blocked/unblocked state,
doing this in internal functions is also error-prone since we can count for
some unrelated calls as well.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Nov 11, 2024
1 parent 88a3774 commit 8d91f82
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 46 deletions.
16 changes: 8 additions & 8 deletions pkg/local_object_storage/engine/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func (e *StorageEngine) ContainerSize(cnr cid.ID) (uint64, error) {
err error
size uint64
)
if e.metrics != nil {
defer elapsed(e.metrics.AddEstimateContainerSizeDuration)()
}

err = e.execIfNotBlocked(func() error {
size, err = e.containerSize(cnr)
return err
Expand All @@ -36,10 +40,6 @@ func ContainerSize(e *StorageEngine, id cid.ID) (uint64, error) {
func (e *StorageEngine) containerSize(cnr cid.ID) (uint64, error) {
var size uint64

if e.metrics != nil {
defer elapsed(e.metrics.AddEstimateContainerSizeDuration)()
}

e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
var csPrm shard.ContainerSizePrm
csPrm.SetContainerID(cnr)
Expand Down Expand Up @@ -67,6 +67,10 @@ func (e *StorageEngine) ListContainers() ([]cid.ID, error) {
res []cid.ID
err error
)
if e.metrics != nil {
defer elapsed(e.metrics.AddListContainersDuration)()
}

err = e.execIfNotBlocked(func() error {
res, err = e.listContainers()
return err
Expand All @@ -81,10 +85,6 @@ func ListContainers(e *StorageEngine) ([]cid.ID, error) {
}

func (e *StorageEngine) listContainers() ([]cid.ID, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddListContainersDuration)()
}

uniqueIDs := make(map[cid.ID]struct{})

e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
Expand Down
10 changes: 5 additions & 5 deletions pkg/local_object_storage/engine/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
// NOTE: This is a forced removal, marks any object to be deleted (despite
// any prohibitions on operations with that object).
func (e *StorageEngine) Delete(addr oid.Address) error {
if e.metrics != nil {
defer elapsed(e.metrics.AddDeleteDuration)()
}

return e.execIfNotBlocked(func() error {
return e.deleteObj(addr, true)
})
}

func (e *StorageEngine) deleteObj(addr oid.Address, force bool) error {
if e.metrics != nil {
defer elapsed(e.metrics.AddDeleteDuration)()
}

return e.inhumeInt([]oid.Address{addr}, force, nil, 0)
return e.inhume([]oid.Address{addr}, force, nil, 0)
}
9 changes: 5 additions & 4 deletions pkg/local_object_storage/engine/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func (e *StorageEngine) Get(addr oid.Address) (*objectSDK.Object, error) {
obj *objectSDK.Object
sp shard.GetPrm
)

if e.metrics != nil {
defer elapsed(e.metrics.AddGetDuration)()
}

sp.SetAddress(addr)
err = e.execIfNotBlocked(func() error {
return e.get(addr, func(s *shard.Shard, ignoreMetadata bool) (bool, error) {
Expand All @@ -44,10 +49,6 @@ func (e *StorageEngine) Get(addr oid.Address) (*objectSDK.Object, error) {
}

func (e *StorageEngine) get(addr oid.Address, shardFunc func(s *shard.Shard, ignoreMetadata bool) (hasMetadata bool, err error)) error {
if e.metrics != nil {
defer elapsed(e.metrics.AddGetDuration)()
}

var (
ok bool
siErr *objectSDK.SplitInfoError
Expand Down
8 changes: 4 additions & 4 deletions pkg/local_object_storage/engine/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func (e *StorageEngine) Head(addr oid.Address, raw bool) (*objectSDK.Object, err
err error
)

if e.metrics != nil {
defer elapsed(e.metrics.AddHeadDuration)()
}

err = e.execIfNotBlocked(func() error {
obj, err = e.head(addr, raw)
return err
Expand All @@ -36,10 +40,6 @@ func (e *StorageEngine) Head(addr oid.Address, raw bool) (*objectSDK.Object, err
}

func (e *StorageEngine) head(addr oid.Address, raw bool) (*objectSDK.Object, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddHeadDuration)()
}

var (
head *objectSDK.Object
siErr *objectSDK.SplitInfoError
Expand Down
14 changes: 5 additions & 9 deletions pkg/local_object_storage/engine/inhume.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ var errInhumeFailure = errors.New("inhume operation failed")
//
// Returns an error if executions are blocked (see BlockExecution).
func (e *StorageEngine) Inhume(tombstone oid.Address, tombExpiration uint64, addrs ...oid.Address) error {
return e.execIfNotBlocked(func() error {
return e.inhume(tombstone, tombExpiration, addrs)
})
}

func (e *StorageEngine) inhume(tombstone oid.Address, tombExpiration uint64, addrs []oid.Address) error {
if e.metrics != nil {
defer elapsed(e.metrics.AddInhumeDuration)()
}
return e.inhumeInt(addrs, false, &tombstone, tombExpiration)
return e.execIfNotBlocked(func() error {
return e.inhume(addrs, false, &tombstone, tombExpiration)
})
}

func (e *StorageEngine) inhumeInt(addrs []oid.Address, force bool, tombstone *oid.Address, tombExpiration uint64) error {
func (e *StorageEngine) inhume(addrs []oid.Address, force bool, tombstone *oid.Address, tombExpiration uint64) error {
var shPrm shard.InhumePrm
if force {
shPrm.ForceRemoval()
Expand Down Expand Up @@ -283,7 +279,7 @@ func (e *StorageEngine) isLocked(addr oid.Address) (bool, error) {
}

func (e *StorageEngine) processExpiredObjects(addrs []oid.Address) {
err := e.inhumeInt(addrs, false, nil, 0)
err := e.inhume(addrs, false, nil, 0)
if err != nil {
e.log.Warn("handling expired objects", zap.Error(err))
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/local_object_storage/engine/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ var errPutShard = errors.New("could not put object to any shard")
//
// Returns an error of type apistatus.ObjectAlreadyRemoved if the object has been marked as removed.
func (e *StorageEngine) Put(obj *objectSDK.Object, objBin []byte, hdrLen int) error {
if e.metrics != nil {
defer elapsed(e.metrics.AddPutDuration)()
}

return e.execIfNotBlocked(func() error {
return e.put(obj, objBin, hdrLen)
})
}

func (e *StorageEngine) put(obj *objectSDK.Object, objBin []byte, hdrLen int) error {
if e.metrics != nil {
defer elapsed(e.metrics.AddPutDuration)()
}

addr := object.AddressOf(obj)

// In #1146 this check was parallelized, however, it became
Expand Down
7 changes: 3 additions & 4 deletions pkg/local_object_storage/engine/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (e *StorageEngine) GetRange(addr oid.Address, offset uint64, length uint64)
err error
res []byte
)
if e.metrics != nil {
defer elapsed(e.metrics.AddRangeDuration)()
}
err = e.execIfNotBlocked(func() error {
res, err = e.getRange(addr, offset, length)
return err
Expand All @@ -49,10 +52,6 @@ func (e *StorageEngine) GetRange(addr oid.Address, offset uint64, length uint64)
}

func (e *StorageEngine) getRange(addr oid.Address, offset uint64, length uint64) ([]byte, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddRangeDuration)()
}

var (
out []byte
siErr *objectSDK.SplitInfoError
Expand Down
18 changes: 10 additions & 8 deletions pkg/local_object_storage/engine/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func (e *StorageEngine) Select(cnr cid.ID, filters object.SearchFilters) ([]oid.
err error
res []oid.Address
)

if e.metrics != nil {
defer elapsed(e.metrics.AddSearchDuration)()
}

err = e.execIfNotBlocked(func() error {
res, err = e._select(cnr, filters)
return err
Expand All @@ -29,10 +34,6 @@ func (e *StorageEngine) Select(cnr cid.ID, filters object.SearchFilters) ([]oid.
}

func (e *StorageEngine) _select(cnr cid.ID, filters object.SearchFilters) ([]oid.Address, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddSearchDuration)()
}

addrList := make([]oid.Address, 0)
uniqueMap := make(map[string]struct{})

Expand Down Expand Up @@ -75,6 +76,11 @@ func (e *StorageEngine) List(limit uint64) ([]oid.Address, error) {
err error
res []oid.Address
)

if e.metrics != nil {
defer elapsed(e.metrics.AddListObjectsDuration)()
}

err = e.execIfNotBlocked(func() error {
res, err = e.list(limit)
return err
Expand All @@ -84,10 +90,6 @@ func (e *StorageEngine) List(limit uint64) ([]oid.Address, error) {
}

func (e *StorageEngine) list(limit uint64) ([]oid.Address, error) {
if e.metrics != nil {
defer elapsed(e.metrics.AddListObjectsDuration)()
}

addrList := make([]oid.Address, 0, limit)
uniqueMap := make(map[string]struct{})
ln := uint64(0)
Expand Down

0 comments on commit 8d91f82

Please sign in to comment.