Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: spans and debug lines for piece directory #1773

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion piecedirectory/piecedirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,39 @@ func (ps *PieceDirectory) Start(ctx context.Context) {
}

func (ps *PieceDirectory) FlaggedPiecesList(ctx context.Context, filter *bdtypes.FlaggedPiecesListFilter, cursor *time.Time, offset int, limit int) ([]model.FlaggedPiece, error) {
defer func(start time.Time) {
log.Debugw("piece directory ; FlaggedPiecesList span", "took", time.Since(start))
}(time.Now())

return ps.store.FlaggedPiecesList(ctx, filter, cursor, offset, limit)
}

func (ps *PieceDirectory) FlaggedPiecesCount(ctx context.Context, filter *bdtypes.FlaggedPiecesListFilter) (int, error) {
defer func(start time.Time) {
log.Debugw("piece directory ; FlaggedPiecesCount span", "took", time.Since(start))
}(time.Now())

return ps.store.FlaggedPiecesCount(ctx, filter)
}

func (ps *PieceDirectory) PiecesCount(ctx context.Context, maddr address.Address) (int, error) {
defer func(start time.Time) { log.Debugw("piece directory ; PiecesCount span", "took", time.Since(start)) }(time.Now())

return ps.store.PiecesCount(ctx, maddr)
}

func (ps *PieceDirectory) ScanProgress(ctx context.Context, maddr address.Address) (*bdtypes.ScanProgress, error) {
defer func(start time.Time) { log.Debugw("piece directory ; ScanProgress span", "took", time.Since(start)) }(time.Now())

return ps.store.ScanProgress(ctx, maddr)
}

// Get all metadata about a particular piece
func (ps *PieceDirectory) GetPieceMetadata(ctx context.Context, pieceCid cid.Cid) (types.PieceDirMetadata, error) {
defer func(start time.Time) {
log.Debugw("piece directory ; GetPieceMetadata span", "took", time.Since(start))
}(time.Now())

ctx, span := tracing.Tracer.Start(ctx, "pm.get_piece_metadata")
defer span.End()

Expand All @@ -133,6 +149,10 @@ func (ps *PieceDirectory) GetPieceMetadata(ctx context.Context, pieceCid cid.Cid

// Get the list of deals (and the sector the data is in) for a particular piece
func (ps *PieceDirectory) GetPieceDeals(ctx context.Context, pieceCid cid.Cid) ([]model.DealInfo, error) {
defer func(start time.Time) {
log.Debugw("piece directory ; GetPieceDeals span", "took", time.Since(start))
}(time.Now())

ctx, span := tracing.Tracer.Start(ctx, "pm.get_piece_deals")
defer span.End()

Expand All @@ -145,14 +165,20 @@ func (ps *PieceDirectory) GetPieceDeals(ctx context.Context, pieceCid cid.Cid) (
}

func (ps *PieceDirectory) GetOffsetSize(ctx context.Context, pieceCid cid.Cid, hash mh.Multihash) (*model.OffsetSize, error) {
defer func(start time.Time) {
log.Debugw("piece directory ; GetOffsetSize span", "took", time.Since(start))
}(time.Now())

ctx, span := tracing.Tracer.Start(ctx, "pm.get_offset")
defer span.End()

return ps.store.GetOffsetSize(ctx, pieceCid, hash)
}

func (ps *PieceDirectory) AddDealForPiece(ctx context.Context, pieceCid cid.Cid, dealInfo model.DealInfo) error {
log.Debugw("add deal for piece", "piececid", pieceCid, "uuid", dealInfo.DealUuid)
defer func(start time.Time) {
log.Debugw("piece directory ; AddDealForPiece span", "piececid", pieceCid, "uuid", dealInfo.DealUuid, "took", time.Since(start))
}(time.Now())

ctx, span := tracing.Tracer.Start(ctx, "pm.add_deal_for_piece")
defer span.End()
Expand Down Expand Up @@ -280,6 +306,10 @@ func (ps *PieceDirectory) addIndexForPiece(ctx context.Context, pieceCid cid.Cid
// corresponding to an unsealed sector for this method to work. It will try to build index
// using all available deals and will exit as soon as it succeeds for one of the deals
func (ps *PieceDirectory) BuildIndexForPiece(ctx context.Context, pieceCid cid.Cid) error {
defer func(start time.Time) {
log.Debugw("piece directory ; BuildIndexForPiece span", "took", time.Since(start))
}(time.Now())

ctx, span := tracing.Tracer.Start(ctx, "pm.build_index_for_piece")
defer span.End()

Expand Down Expand Up @@ -471,6 +501,10 @@ func (ps *PieceDirectory) GetSharedPieceReader(ctx context.Context, pieceCid cid

// Get all pieces that contain a multihash (used when retrieving by payload CID)
func (ps *PieceDirectory) PiecesContainingMultihash(ctx context.Context, m mh.Multihash) ([]cid.Cid, error) {
defer func(start time.Time) {
log.Debugw("piece directory ; PiecesContainingMultihash span", "took", time.Since(start))
}(time.Now())

ctx, span := tracing.Tracer.Start(ctx, "pm.pieces_containing_multihash")
defer span.End()

Expand Down