2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-21 17:31:27 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-04-16 17:17:54 +01:00
|
|
|
"encoding/base64"
|
2018-11-21 22:01:09 +00:00
|
|
|
"encoding/csv"
|
2019-03-15 20:21:52 +00:00
|
|
|
"encoding/json"
|
2018-11-21 17:31:27 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2018-11-21 22:01:09 +00:00
|
|
|
"os"
|
|
|
|
"strconv"
|
2019-03-15 20:21:52 +00:00
|
|
|
"strings"
|
2018-11-21 17:31:27 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/identity"
|
|
|
|
"storj.io/common/rpc"
|
|
|
|
"storj.io/common/storj"
|
2020-03-23 19:18:20 +00:00
|
|
|
"storj.io/private/process"
|
2020-02-25 11:00:31 +00:00
|
|
|
"storj.io/storj/private/prompt"
|
2020-04-01 08:12:26 +01:00
|
|
|
_ "storj.io/storj/private/version" // This attaches version information during release builds.
|
2020-10-30 11:12:01 +00:00
|
|
|
"storj.io/storj/satellite/internalpb"
|
2020-02-21 14:07:29 +00:00
|
|
|
"storj.io/uplink/private/eestream"
|
2018-11-21 17:31:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-08-11 15:50:01 +01:00
|
|
|
// Addr is the address of peer from command flags.
|
2019-03-07 18:19:37 +00:00
|
|
|
Addr = flag.String("address", "127.0.0.1:7778", "address of peer to inspect")
|
2018-11-21 17:31:27 +00:00
|
|
|
|
2020-08-11 15:50:01 +01:00
|
|
|
// IdentityPath is the path to the identity the inspector should use for network communication.
|
2019-01-18 15:02:35 +00:00
|
|
|
IdentityPath = flag.String("identity-path", "", "path to the identity certificate for use on the network")
|
|
|
|
|
2020-08-11 15:50:01 +01:00
|
|
|
// CSVPath is the csv path where command output is written.
|
2019-04-04 18:11:19 +01:00
|
|
|
CSVPath string
|
|
|
|
|
2020-08-11 15:50:01 +01:00
|
|
|
// ErrInspectorDial throws when there are errors dialing the inspector server.
|
2018-11-21 17:31:27 +00:00
|
|
|
ErrInspectorDial = errs.Class("error dialing inspector server:")
|
|
|
|
|
2020-08-11 15:50:01 +01:00
|
|
|
// ErrRequest is for request errors after dialing.
|
2018-11-21 17:31:27 +00:00
|
|
|
ErrRequest = errs.Class("error processing request:")
|
|
|
|
|
2020-08-11 15:50:01 +01:00
|
|
|
// ErrIdentity is for errors during identity creation for this CLI.
|
2018-11-21 17:31:27 +00:00
|
|
|
ErrIdentity = errs.Class("error creating identity:")
|
|
|
|
|
2020-08-11 15:50:01 +01:00
|
|
|
// ErrArgs throws when there are errors with CLI args.
|
2018-11-21 22:01:09 +00:00
|
|
|
ErrArgs = errs.Class("error with CLI args:")
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
irreparableLimit int32
|
|
|
|
|
2020-08-11 15:50:01 +01:00
|
|
|
// Commander CLI.
|
2018-11-21 17:31:27 +00:00
|
|
|
rootCmd = &cobra.Command{
|
|
|
|
Use: "inspector",
|
2019-09-19 20:56:34 +01:00
|
|
|
Short: "CLI for interacting with Storj network",
|
2018-11-21 22:01:09 +00:00
|
|
|
}
|
|
|
|
statsCmd = &cobra.Command{
|
|
|
|
Use: "statdb",
|
|
|
|
Short: "commands for statdb",
|
|
|
|
}
|
2019-04-02 15:55:58 +01:00
|
|
|
healthCmd = &cobra.Command{
|
|
|
|
Use: "health",
|
|
|
|
Short: "commands for querying health of a stored data",
|
|
|
|
}
|
2019-03-15 20:21:52 +00:00
|
|
|
irreparableCmd = &cobra.Command{
|
|
|
|
Use: "irreparable",
|
|
|
|
Short: "list segments in irreparable database",
|
|
|
|
RunE: getSegments,
|
|
|
|
}
|
2019-04-02 15:55:58 +01:00
|
|
|
objectHealthCmd = &cobra.Command{
|
|
|
|
Use: "object <project-id> <bucket> <encrypted-path>",
|
|
|
|
Short: "Get stats about an object's health",
|
|
|
|
Args: cobra.MinimumNArgs(3),
|
|
|
|
RunE: ObjectHealth,
|
|
|
|
}
|
|
|
|
segmentHealthCmd = &cobra.Command{
|
|
|
|
Use: "segment <project-id> <segment-index> <bucket> <encrypted-path>",
|
|
|
|
Short: "Get stats about a segment's health",
|
|
|
|
Args: cobra.MinimumNArgs(4),
|
|
|
|
RunE: SegmentHealth,
|
|
|
|
}
|
2018-11-21 17:31:27 +00:00
|
|
|
)
|
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
// Inspector gives access to overlay.
|
2018-11-21 17:31:27 +00:00
|
|
|
type Inspector struct {
|
2021-03-29 10:04:31 +01:00
|
|
|
conn *rpc.Conn
|
|
|
|
identity *identity.FullIdentity
|
|
|
|
irrdbclient internalpb.DRPCIrreparableInspectorClient
|
|
|
|
healthclient internalpb.DRPCHealthInspectorClient
|
2018-11-21 17:31:27 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 11:54:14 +01:00
|
|
|
// NewInspector creates a new inspector client for access to overlay.
|
2020-05-12 09:46:48 +01:00
|
|
|
func NewInspector(ctx context.Context, address, path string) (*Inspector, error) {
|
2019-01-25 17:46:09 +00:00
|
|
|
id, err := identity.Config{
|
2019-01-28 22:53:37 +00:00
|
|
|
CertPath: fmt.Sprintf("%s/identity.cert", path),
|
|
|
|
KeyPath: fmt.Sprintf("%s/identity.key", path),
|
2019-01-18 15:02:35 +00:00
|
|
|
}.Load()
|
2019-02-11 11:17:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, ErrIdentity.Wrap(err)
|
|
|
|
}
|
2019-01-18 15:02:35 +00:00
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
conn, err := rpc.NewDefaultDialer(nil).DialAddressUnencrypted(ctx, address)
|
2018-11-21 17:31:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return &Inspector{}, ErrInspectorDial.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Inspector{
|
2021-03-29 10:04:31 +01:00
|
|
|
conn: conn,
|
|
|
|
identity: id,
|
|
|
|
irrdbclient: internalpb.NewDRPCIrreparableInspectorClient(conn),
|
|
|
|
healthclient: internalpb.NewDRPCHealthInspectorClient(conn),
|
2018-11-21 17:31:27 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
// Close closes the inspector.
|
|
|
|
func (i *Inspector) Close() error { return i.conn.Close() }
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// ObjectHealth gets information about the health of an object on the network.
|
2019-04-02 15:55:58 +01:00
|
|
|
func ObjectHealth(cmd *cobra.Command, args []string) (err error) {
|
2020-05-12 09:46:48 +01:00
|
|
|
ctx, _ := process.Ctx(cmd)
|
|
|
|
i, err := NewInspector(ctx, *Addr, *IdentityPath)
|
2019-04-02 15:55:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return ErrArgs.Wrap(err)
|
|
|
|
}
|
2019-09-19 05:46:39 +01:00
|
|
|
defer func() { err = errs.Combine(err, i.Close()) }()
|
2019-04-02 15:55:58 +01:00
|
|
|
|
2019-04-04 18:11:19 +01:00
|
|
|
startAfterSegment := int64(0) // start from first segment
|
|
|
|
endBeforeSegment := int64(0) // No end, so we stop when we've hit limit or arrived at the last segment
|
|
|
|
limit := int64(0) // No limit, so we stop when we've arrived at the last segment
|
|
|
|
|
|
|
|
switch len(args) {
|
|
|
|
case 6:
|
|
|
|
limit, err = strconv.ParseInt(args[5], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return ErrRequest.Wrap(err)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case 5:
|
|
|
|
endBeforeSegment, err = strconv.ParseInt(args[4], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return ErrRequest.Wrap(err)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case 4:
|
|
|
|
startAfterSegment, err = strconv.ParseInt(args[3], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return ErrRequest.Wrap(err)
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
default:
|
|
|
|
}
|
2020-04-16 17:17:54 +01:00
|
|
|
decodedPath, err := base64.URLEncoding.DecodeString(args[2])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-30 11:12:01 +00:00
|
|
|
req := &internalpb.ObjectHealthRequest{
|
2019-04-02 15:55:58 +01:00
|
|
|
ProjectId: []byte(args[0]),
|
|
|
|
Bucket: []byte(args[1]),
|
2020-04-16 17:17:54 +01:00
|
|
|
EncryptedPath: decodedPath,
|
2019-04-04 18:11:19 +01:00
|
|
|
StartAfterSegment: startAfterSegment,
|
|
|
|
EndBeforeSegment: endBeforeSegment,
|
|
|
|
Limit: int32(limit),
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := i.healthclient.ObjectHealth(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return ErrRequest.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := csvOutput()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2019-04-02 15:55:58 +01:00
|
|
|
}
|
2019-04-04 18:11:19 +01:00
|
|
|
defer func() {
|
|
|
|
err := f.Close()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("error closing file: %+v\n", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
w := csv.NewWriter(f)
|
|
|
|
defer w.Flush()
|
2019-04-02 15:55:58 +01:00
|
|
|
|
2019-04-04 18:11:19 +01:00
|
|
|
redundancy, err := eestream.NewRedundancyStrategyFromProto(resp.GetRedundancy())
|
2019-04-02 15:55:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return ErrRequest.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2019-04-04 18:11:19 +01:00
|
|
|
if err := printRedundancyTable(w, redundancy); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-18 23:22:14 +01:00
|
|
|
if err := printSegmentHealthAndNodeTables(w, redundancy, resp.GetSegments()); err != nil {
|
2019-04-04 18:11:19 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-04-02 15:55:58 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// SegmentHealth gets information about the health of a segment on the network.
|
2019-04-02 15:55:58 +01:00
|
|
|
func SegmentHealth(cmd *cobra.Command, args []string) (err error) {
|
2020-05-12 09:46:48 +01:00
|
|
|
ctx, _ := process.Ctx(cmd)
|
|
|
|
i, err := NewInspector(ctx, *Addr, *IdentityPath)
|
2019-04-02 15:55:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return ErrArgs.Wrap(err)
|
|
|
|
}
|
2019-09-19 05:46:39 +01:00
|
|
|
defer func() { err = errs.Combine(err, i.Close()) }()
|
2019-04-02 15:55:58 +01:00
|
|
|
|
|
|
|
segmentIndex, err := strconv.ParseInt(args[1], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return ErrRequest.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2020-10-30 11:12:01 +00:00
|
|
|
req := &internalpb.SegmentHealthRequest{
|
2019-04-02 15:55:58 +01:00
|
|
|
ProjectId: []byte(args[0]),
|
|
|
|
SegmentIndex: segmentIndex,
|
|
|
|
Bucket: []byte(args[2]),
|
|
|
|
EncryptedPath: []byte(args[3]),
|
|
|
|
}
|
|
|
|
|
2019-04-04 18:11:19 +01:00
|
|
|
resp, err := i.healthclient.SegmentHealth(ctx, req)
|
2019-04-02 15:55:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return ErrRequest.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2019-04-04 18:11:19 +01:00
|
|
|
f, err := csvOutput()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err := f.Close()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("error closing file: %+v\n", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
w := csv.NewWriter(f)
|
|
|
|
defer w.Flush()
|
|
|
|
|
|
|
|
redundancy, err := eestream.NewRedundancyStrategyFromProto(resp.GetRedundancy())
|
|
|
|
if err != nil {
|
|
|
|
return ErrRequest.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := printRedundancyTable(w, redundancy); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-30 11:12:01 +00:00
|
|
|
if err := printSegmentHealthAndNodeTables(w, redundancy, []*internalpb.SegmentHealth{resp.GetHealth()}); err != nil {
|
2019-04-04 18:11:19 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func csvOutput() (*os.File, error) {
|
|
|
|
if CSVPath == "stdout" {
|
|
|
|
return os.Stdout, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return os.Create(CSVPath)
|
|
|
|
}
|
|
|
|
|
2020-10-30 11:12:01 +00:00
|
|
|
func printSegmentHealthAndNodeTables(w *csv.Writer, redundancy eestream.RedundancyStrategy, segments []*internalpb.SegmentHealth) error {
|
2019-04-04 18:11:19 +01:00
|
|
|
segmentTableHeader := []string{
|
2019-06-18 23:22:14 +01:00
|
|
|
"Segment Index", "Healthy Nodes", "Unhealthy Nodes", "Offline Nodes",
|
2019-04-04 18:11:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := w.Write(segmentTableHeader); err != nil {
|
|
|
|
return fmt.Errorf("error writing record to csv: %s", err)
|
|
|
|
}
|
|
|
|
|
2019-06-18 23:22:14 +01:00
|
|
|
currentNodeIndex := 1 // start at index 1 to leave first column empty
|
|
|
|
nodeIndices := make(map[storj.NodeID]int) // to keep track of node positions for node table
|
2019-04-04 18:11:19 +01:00
|
|
|
// Add each segment to the segmentTable
|
|
|
|
for _, segment := range segments {
|
2019-06-18 23:22:14 +01:00
|
|
|
healthyNodes := segment.HealthyIds // healthy nodes with pieces currently online
|
|
|
|
unhealthyNodes := segment.UnhealthyIds // unhealthy nodes with pieces currently online
|
|
|
|
offlineNodes := segment.OfflineIds // offline nodes
|
2019-04-04 18:11:19 +01:00
|
|
|
segmentIndexPath := string(segment.GetSegment()) // path formatted Segment Index
|
|
|
|
|
|
|
|
row := []string{
|
|
|
|
segmentIndexPath,
|
2019-06-18 23:22:14 +01:00
|
|
|
strconv.FormatInt(int64(len(healthyNodes)), 10),
|
|
|
|
strconv.FormatInt(int64(len(unhealthyNodes)), 10),
|
|
|
|
strconv.FormatInt(int64(len(offlineNodes)), 10),
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := w.Write(row); err != nil {
|
|
|
|
return fmt.Errorf("error writing record to csv: %s", err)
|
2019-04-04 18:11:19 +01:00
|
|
|
}
|
|
|
|
|
2019-06-18 23:22:14 +01:00
|
|
|
allNodes := append(healthyNodes, unhealthyNodes...)
|
|
|
|
allNodes = append(allNodes, offlineNodes...)
|
|
|
|
for _, id := range allNodes {
|
|
|
|
if nodeIndices[id] == 0 {
|
|
|
|
nodeIndices[id] = currentNodeIndex
|
|
|
|
currentNodeIndex++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := w.Write([]string{}); err != nil {
|
|
|
|
return fmt.Errorf("error writing record to csv: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
numNodes := len(nodeIndices)
|
|
|
|
nodeTableHeader := make([]string, numNodes+1)
|
|
|
|
for id, i := range nodeIndices {
|
|
|
|
nodeTableHeader[i] = id.String()
|
|
|
|
}
|
|
|
|
if err := w.Write(nodeTableHeader); err != nil {
|
|
|
|
return fmt.Errorf("error writing record to csv: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add online/offline info to the node table
|
|
|
|
for _, segment := range segments {
|
|
|
|
row := make([]string, numNodes+1)
|
|
|
|
for _, id := range segment.HealthyIds {
|
|
|
|
i := nodeIndices[id]
|
|
|
|
row[i] = "healthy"
|
|
|
|
}
|
|
|
|
for _, id := range segment.UnhealthyIds {
|
|
|
|
i := nodeIndices[id]
|
|
|
|
row[i] = "unhealthy"
|
|
|
|
}
|
|
|
|
for _, id := range segment.OfflineIds {
|
|
|
|
i := nodeIndices[id]
|
|
|
|
row[i] = "offline"
|
|
|
|
}
|
|
|
|
row[0] = string(segment.GetSegment())
|
2019-04-04 18:11:19 +01:00
|
|
|
if err := w.Write(row); err != nil {
|
|
|
|
return fmt.Errorf("error writing record to csv: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func printRedundancyTable(w *csv.Writer, redundancy eestream.RedundancyStrategy) error {
|
|
|
|
total := redundancy.TotalCount() // total amount of pieces we generated (n)
|
|
|
|
required := redundancy.RequiredCount() // minimum required stripes for reconstruction (k)
|
|
|
|
optimalThreshold := redundancy.OptimalThreshold() // amount of pieces we need to store to call it a success (o)
|
|
|
|
repairThreshold := redundancy.RepairThreshold() // amount of pieces we need to drop to before triggering repair (m)
|
|
|
|
|
|
|
|
redundancyTable := [][]string{
|
|
|
|
{"Total Pieces (n)", "Minimum Required (k)", "Optimal Threshold (o)", "Repair Threshold (m)"},
|
|
|
|
{strconv.Itoa(total), strconv.Itoa(required), strconv.Itoa(optimalThreshold), strconv.Itoa(repairThreshold)},
|
|
|
|
{},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, row := range redundancyTable {
|
|
|
|
if err := w.Write(row); err != nil {
|
|
|
|
return fmt.Errorf("error writing record to csv: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 15:55:58 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
func getSegments(cmd *cobra.Command, args []string) error {
|
|
|
|
if irreparableLimit <= int32(0) {
|
|
|
|
return ErrArgs.New("limit must be greater than 0")
|
|
|
|
}
|
|
|
|
|
2020-05-12 09:46:48 +01:00
|
|
|
ctx, _ := process.Ctx(cmd)
|
|
|
|
i, err := NewInspector(ctx, *Addr, *IdentityPath)
|
2019-03-15 20:21:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return ErrInspectorDial.Wrap(err)
|
|
|
|
}
|
2019-09-19 05:46:39 +01:00
|
|
|
defer func() { err = errs.Combine(err, i.Close()) }()
|
|
|
|
|
2019-07-18 17:21:21 +01:00
|
|
|
var lastSeenSegmentPath = []byte{}
|
2019-03-15 20:21:52 +00:00
|
|
|
|
|
|
|
// query DB and paginate results
|
2019-07-18 17:21:21 +01:00
|
|
|
for {
|
2020-10-30 11:12:01 +00:00
|
|
|
req := &internalpb.ListIrreparableSegmentsRequest{
|
2019-07-18 17:21:21 +01:00
|
|
|
Limit: irreparableLimit,
|
|
|
|
LastSeenSegmentPath: lastSeenSegmentPath,
|
|
|
|
}
|
2020-05-12 09:46:48 +01:00
|
|
|
res, err := i.irrdbclient.ListIrreparableSegments(ctx, req)
|
2019-03-15 20:21:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return ErrRequest.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:21:21 +01:00
|
|
|
if len(res.Segments) == 0 {
|
2019-03-15 20:21:52 +00:00
|
|
|
break
|
|
|
|
}
|
2019-07-18 17:21:21 +01:00
|
|
|
lastSeenSegmentPath = res.Segments[len(res.Segments)-1].Path
|
2019-03-15 20:21:52 +00:00
|
|
|
|
2019-07-18 17:21:21 +01:00
|
|
|
objects := sortSegments(res.Segments)
|
2019-03-15 20:21:52 +00:00
|
|
|
// format and print segments
|
|
|
|
enc := json.NewEncoder(os.Stdout)
|
|
|
|
enc.SetIndent("", " ")
|
|
|
|
err = enc.Encode(objects)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:21:21 +01:00
|
|
|
length := int32(len(res.Segments))
|
2019-03-15 20:21:52 +00:00
|
|
|
if length >= irreparableLimit {
|
2020-02-25 11:00:31 +00:00
|
|
|
confirmed, err := prompt.Confirm("\nNext page? [y/n]")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !confirmed {
|
2019-03-15 20:21:52 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// sortSegments by the object they belong to.
|
2020-10-30 11:12:01 +00:00
|
|
|
func sortSegments(segments []*internalpb.IrreparableSegment) map[string][]*internalpb.IrreparableSegment {
|
|
|
|
objects := make(map[string][]*internalpb.IrreparableSegment)
|
2019-03-15 20:21:52 +00:00
|
|
|
for _, seg := range segments {
|
|
|
|
pathElements := storj.SplitPath(string(seg.Path))
|
|
|
|
|
|
|
|
// by removing the segment index, we can easily sort segments into a map of objects
|
|
|
|
pathElements = append(pathElements[:1], pathElements[2:]...)
|
|
|
|
objPath := strings.Join(pathElements, "/")
|
|
|
|
objects[objPath] = append(objects[objPath], seg)
|
|
|
|
}
|
|
|
|
return objects
|
|
|
|
}
|
|
|
|
|
2018-11-21 17:31:27 +00:00
|
|
|
func init() {
|
2018-11-21 22:01:09 +00:00
|
|
|
rootCmd.AddCommand(statsCmd)
|
2019-03-15 20:21:52 +00:00
|
|
|
rootCmd.AddCommand(irreparableCmd)
|
2019-04-02 15:55:58 +01:00
|
|
|
rootCmd.AddCommand(healthCmd)
|
2018-11-21 22:01:09 +00:00
|
|
|
|
2019-04-02 15:55:58 +01:00
|
|
|
healthCmd.AddCommand(objectHealthCmd)
|
|
|
|
healthCmd.AddCommand(segmentHealthCmd)
|
|
|
|
|
2019-04-04 18:11:19 +01:00
|
|
|
objectHealthCmd.Flags().StringVar(&CSVPath, "csv-path", "stdout", "csv path where command output is written")
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
irreparableCmd.Flags().Int32Var(&irreparableLimit, "limit", 50, "max number of results per page")
|
|
|
|
|
2018-11-21 17:31:27 +00:00
|
|
|
flag.Parse()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
process.Exec(rootCmd)
|
|
|
|
}
|