cmd/segment-reaper: skeleton command for zombie deletion (#3599)
This commit is contained in:
parent
36fead0093
commit
1e33995a89
61
cmd/segment-reaper/delete.go
Normal file
61
cmd/segment-reaper/delete.go
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2019 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/zeebo/errs"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"storj.io/storj/pkg/process"
|
||||
"storj.io/storj/satellite/metainfo"
|
||||
)
|
||||
|
||||
var (
|
||||
deleteCmd = &cobra.Command{
|
||||
Use: "delete input_file.csv [flags]",
|
||||
Short: "Deletes zombie segments from DB",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: cmdDelete,
|
||||
}
|
||||
|
||||
deleteCfg struct {
|
||||
DatabaseURL string `help:"the database connection string to use" default:"postgres://"`
|
||||
DryRun bool `help:"with this option no deletion will be done, only printing results" default:"false"`
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(deleteCmd)
|
||||
|
||||
process.Bind(deleteCmd, &deleteCfg)
|
||||
}
|
||||
|
||||
func cmdDelete(cmd *cobra.Command, args []string) (err error) {
|
||||
log := zap.L()
|
||||
db, err := metainfo.NewStore(log.Named("pointerdb"), detectCfg.DatabaseURL)
|
||||
if err != nil {
|
||||
return errs.New("error connecting database: %+v", err)
|
||||
}
|
||||
defer func() {
|
||||
err = errs.Combine(err, db.Close())
|
||||
}()
|
||||
|
||||
inputFile, err := os.Open(args[0])
|
||||
if err != nil {
|
||||
return errs.New("error opening input file: %+v", err)
|
||||
}
|
||||
defer func() {
|
||||
err = errs.Combine(err, inputFile.Close())
|
||||
}()
|
||||
|
||||
_ = csv.NewReader(inputFile)
|
||||
|
||||
// TODO logice will be added in next PR
|
||||
|
||||
return nil
|
||||
}
|
@ -35,7 +35,7 @@ var (
|
||||
DatabaseURL string `help:"the database connection string to use" default:"postgres://"`
|
||||
From string `help:"begin of date range for detecting zombie segments" default:""`
|
||||
To string `help:"end of date range for detecting zombie segments" default:""`
|
||||
File string `help:"location of file with report" default:"detect_result.csv"`
|
||||
File string `help:"location of file with report" default:"zombie-segments.csv"`
|
||||
}
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user