storj/satellite/repair/irreparable/inspector.go

44 lines
1.0 KiB
Go
Raw Normal View History

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package irreparable
import (
"context"
"github.com/spacemonkeygo/monkit/v3"
"storj.io/common/pb"
)
var (
mon = monkit.Package()
)
// Inspector is a gRPC service for inspecting irreparable internals
2019-09-10 14:24:16 +01:00
//
// architecture: Endpoint
type Inspector struct {
irrdb DB
}
// NewInspector creates an Inspector
func NewInspector(irrdb DB) *Inspector {
return &Inspector{irrdb: irrdb}
}
// ListIrreparableSegments returns a number of irreparable segments by limit and offset
func (srv *Inspector) ListIrreparableSegments(ctx context.Context, req *pb.ListIrreparableSegmentsRequest) (_ *pb.ListIrreparableSegmentsResponse, err error) {
defer mon.Task()(&ctx)(&err)
last := req.GetLastSeenSegmentPath()
if len(req.GetLastSeenSegmentPath()) == 0 {
last = []byte{}
}
segments, err := srv.irrdb.GetLimited(ctx, int(req.GetLimit()), last)
if err != nil {
return nil, err
}
return &pb.ListIrreparableSegmentsResponse{Segments: segments}, err
}