storj/pkg/datarepair/irreparable/inspector.go
Jess G 3af9250659
update irreparableDB.GetLimited query to use where instead of offset (#2585)
* update query to use where instead of offset, update tests

* update cmd/inspector irreparable

* add comment for offset
2019-07-18 09:21:21 -07:00

42 lines
1009 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package irreparable
import (
"context"
monkit "gopkg.in/spacemonkeygo/monkit.v2"
"storj.io/storj/pkg/pb"
)
var (
mon = monkit.Package()
)
// Inspector is a gRPC service for inspecting irreparable internals
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
}