2019-03-15 20:21:52 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package irreparable
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-11-08 20:40:39 +00:00
|
|
|
"github.com/spacemonkeygo/monkit/v3"
|
2019-06-04 12:36:27 +01:00
|
|
|
|
2020-10-30 11:12:01 +00:00
|
|
|
"storj.io/storj/satellite/internalpb"
|
2019-03-15 20:21:52 +00:00
|
|
|
)
|
|
|
|
|
2019-06-04 12:36:27 +01:00
|
|
|
var (
|
|
|
|
mon = monkit.Package()
|
|
|
|
)
|
|
|
|
|
2020-12-05 16:01:42 +00:00
|
|
|
// Inspector is a RPC service for inspecting irreparable internals.
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Endpoint
|
2019-03-15 20:21:52 +00:00
|
|
|
type Inspector struct {
|
|
|
|
irrdb DB
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// NewInspector creates an Inspector.
|
2019-03-15 20:21:52 +00:00
|
|
|
func NewInspector(irrdb DB) *Inspector {
|
|
|
|
return &Inspector{irrdb: irrdb}
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// ListIrreparableSegments returns a number of irreparable segments by limit and offset.
|
2020-10-30 11:12:01 +00:00
|
|
|
func (srv *Inspector) ListIrreparableSegments(ctx context.Context, req *internalpb.ListIrreparableSegmentsRequest) (_ *internalpb.ListIrreparableSegmentsResponse, err error) {
|
2019-06-04 12:36:27 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-10-30 11:12:01 +00:00
|
|
|
return &internalpb.ListIrreparableSegmentsResponse{Segments: segments}, err
|
2019-03-15 20:21:52 +00:00
|
|
|
}
|