-
Notifications
You must be signed in to change notification settings - Fork 402
/
main.go
84 lines (63 loc) · 2.21 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"time"
"github.com/spf13/cobra"
"github.com/zeebo/errs"
"go.uber.org/zap"
"storj.io/private/process"
"storj.io/storj/cmd/metabase-verify/verify"
"storj.io/storj/satellite/metabase"
)
// Error is the default error class for the package.
var Error = errs.Class("metabase-verify")
func main() {
log := zap.L()
root := &cobra.Command{
Use: "metainfo-loop-verify",
}
IncludeProfiling(root)
root.AddCommand(VerifyCommand(log))
process.Exec(root)
}
// VerifyCommand creates command for running verifications.
func VerifyCommand(log *zap.Logger) *cobra.Command {
var metabaseDB string
var ignoreVersionMismatch bool
var verifyConfig verify.Config
cmd := &cobra.Command{
Use: "run",
Short: "run metabase verification",
}
flag := cmd.Flags()
flag.StringVar(&metabaseDB, "metabasedb", "", "connection URL for MetabaseDB")
_ = cmd.MarkFlagRequired("metabasedb")
flag.BoolVar(&ignoreVersionMismatch, "ignore-version-mismatch", false, "ignore version mismatch")
flag.DurationVar(&verifyConfig.Loop.CoalesceDuration, "loop.coalesce-duration", 5*time.Second, "how long to wait for new observers before starting iteration")
flag.Float64Var(&verifyConfig.Loop.RateLimit, "loop.rate-limit", 0, "rate limit (default is 0 which is unlimited segments per second)")
flag.IntVar(&verifyConfig.Loop.ListLimit, "loop.list-limit", 2500, "how many items to query in a batch")
flag.Int64Var(&verifyConfig.ProgressPrintFrequency, "progress-frequency", 1000000, "how often should we print progress (every object)")
cmd.RunE = func(cmd *cobra.Command, args []string) error {
ctx, cancel := process.Ctx(cmd)
defer cancel()
mdb, err := metabase.Open(ctx, log.Named("mdb"), metabaseDB, metabase.Config{})
if err != nil {
return Error.Wrap(err)
}
defer func() { _ = mdb.Close() }()
versionErr := mdb.CheckVersion(ctx)
if versionErr != nil {
log.Error("versions skewed", zap.Error(versionErr))
if !ignoreVersionMismatch {
return Error.Wrap(versionErr)
}
}
verify := verify.New(log, mdb, verifyConfig)
if err := verify.RunOnce(ctx); err != nil {
return Error.Wrap(err)
}
return nil
}
return cmd
}