2019-03-15 20:21:52 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package irreparable
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-06-04 12:36:27 +01:00
|
|
|
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
|
|
|
)
|
|
|
|
|
2019-06-04 12:36:27 +01:00
|
|
|
var (
|
|
|
|
mon = monkit.Package()
|
|
|
|
)
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
// 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}
|
|
|
|
}
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
// ListIrreparableSegments returns a number of irreparable segments by limit and offset
|
2019-06-04 12:36:27 +01:00
|
|
|
func (srv *Inspector) ListIrreparableSegments(ctx context.Context, req *pb.ListIrreparableSegmentsRequest) (_ *pb.ListIrreparableSegmentsResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
2019-07-18 17:21:21 +01:00
|
|
|
last := req.GetLastSeenSegmentPath()
|
|
|
|
if len(req.GetLastSeenSegmentPath()) == 0 {
|
|
|
|
last = []byte{}
|
|
|
|
}
|
|
|
|
segments, err := srv.irrdb.GetLimited(ctx, int(req.GetLimit()), last)
|
2019-03-15 20:21:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
return &pb.ListIrreparableSegmentsResponse{Segments: segments}, err
|
2019-03-15 20:21:52 +00:00
|
|
|
}
|