[#734] metabase: Include UpdateStorageID in metrics and traces

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-10-13 14:01:14 +03:00
parent 7e0c5a55de
commit f26233b47a
6 changed files with 23 additions and 7 deletions

View file

@ -3,6 +3,7 @@ package meta
import ( import (
"context" "context"
"errors" "errors"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
@ -94,7 +95,22 @@ func (p *UpdateStorageIDPrm) SetStorageID(id []byte) {
} }
// UpdateStorageID updates storage descriptor for objects from the blobstor. // UpdateStorageID updates storage descriptor for objects from the blobstor.
func (db *DB) UpdateStorageID(prm UpdateStorageIDPrm) (res UpdateStorageIDRes, err error) { func (db *DB) UpdateStorageID(ctx context.Context, prm UpdateStorageIDPrm) (res UpdateStorageIDRes, err error) {
var (
startedAt = time.Now()
success = false
)
defer func() {
db.metrics.AddMethodDuration("UpdateStorageID", time.Since(startedAt), success)
}()
_, span := tracing.StartSpanFromContext(ctx, "metabase.UpdateStorageID",
trace.WithAttributes(
attribute.String("address", prm.addr.EncodeToString()),
attribute.String("storage_id", string(prm.id)),
))
defer span.End()
db.modeMtx.RLock() db.modeMtx.RLock()
defer db.modeMtx.RUnlock() defer db.modeMtx.RUnlock()
@ -116,6 +132,6 @@ func (db *DB) UpdateStorageID(prm UpdateStorageIDPrm) (res UpdateStorageIDRes, e
return err return err
}) })
success = err == nil
return res, metaerr.Wrap(err) return res, metaerr.Wrap(err)
} }

View file

@ -79,7 +79,7 @@ func metaUpdateStorageID(db *meta.DB, addr oid.Address, id []byte) error {
sidPrm.SetAddress(addr) sidPrm.SetAddress(addr)
sidPrm.SetStorageID(id) sidPrm.SetStorageID(id)
_, err := db.UpdateStorageID(sidPrm) _, err := db.UpdateStorageID(context.Background(), sidPrm)
return err return err
} }

View file

@ -91,7 +91,7 @@ func benchmarkPutPrepare(b *testing.B, cache writecache.Cache) {
type testMetabase struct{} type testMetabase struct{}
func (testMetabase) UpdateStorageID(meta.UpdateStorageIDPrm) (meta.UpdateStorageIDRes, error) { func (testMetabase) UpdateStorageID(context.Context, meta.UpdateStorageIDPrm) (meta.UpdateStorageIDRes, error) {
return meta.UpdateStorageIDRes{}, nil return meta.UpdateStorageIDRes{}, nil
} }

View file

@ -51,7 +51,7 @@ type MainStorage interface {
// Metabase is the interface of the metabase used by Cache implementations. // Metabase is the interface of the metabase used by Cache implementations.
type Metabase interface { type Metabase interface {
UpdateStorageID(meta.UpdateStorageIDPrm) (meta.UpdateStorageIDRes, error) UpdateStorageID(context.Context, meta.UpdateStorageIDPrm) (meta.UpdateStorageIDRes, error)
} }
var ( var (

View file

@ -226,7 +226,7 @@ func (c *cache) flushObject(ctx context.Context, obj *objectSDK.Object, data []b
updPrm.SetAddress(addr) updPrm.SetAddress(addr)
updPrm.SetStorageID(res.StorageID) updPrm.SetStorageID(res.StorageID)
_, err = c.metabase.UpdateStorageID(updPrm) _, err = c.metabase.UpdateStorageID(ctx, updPrm)
if err != nil { if err != nil {
c.reportFlushError(logs.FrostFSNodeCantUpdateObjectStorageID, c.reportFlushError(logs.FrostFSNodeCantUpdateObjectStorageID,
addr.EncodeToString(), err) addr.EncodeToString(), err)

View file

@ -278,7 +278,7 @@ func (c *cache) flushObject(ctx context.Context, obj *objectSDK.Object, data []b
updPrm.SetAddress(addr) updPrm.SetAddress(addr)
updPrm.SetStorageID(res.StorageID) updPrm.SetStorageID(res.StorageID)
_, err = c.metabase.UpdateStorageID(updPrm) _, err = c.metabase.UpdateStorageID(ctx, updPrm)
if err != nil { if err != nil {
c.reportFlushError(logs.FSTreeCantUpdateID, c.reportFlushError(logs.FSTreeCantUpdateID,
addr.EncodeToString(), err) addr.EncodeToString(), err)