2019-10-29 14:55:57 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/process"
|
|
|
|
"storj.io/storj/pkg/revocation"
|
2020-01-17 22:55:53 +00:00
|
|
|
"storj.io/storj/private/context2"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/version"
|
2019-10-29 14:55:57 +00:00
|
|
|
"storj.io/storj/satellite"
|
|
|
|
"storj.io/storj/satellite/metainfo"
|
2020-01-17 22:55:53 +00:00
|
|
|
"storj.io/storj/satellite/orders"
|
2019-10-29 14:55:57 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func cmdRepairerRun(cmd *cobra.Command, args []string) (err error) {
|
|
|
|
ctx, _ := process.Ctx(cmd)
|
|
|
|
log := zap.L()
|
|
|
|
|
2020-01-28 17:35:45 +00:00
|
|
|
runCfg.Debug.Address = *process.DebugAddrFlag
|
|
|
|
|
2019-10-29 14:55:57 +00:00
|
|
|
identity, err := runCfg.Identity.Load()
|
|
|
|
if err != nil {
|
|
|
|
zap.S().Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-01-10 01:12:27 +00:00
|
|
|
db, err := satellitedb.New(log.Named("db"), runCfg.Database, satellitedb.Options{})
|
2019-10-29 14:55:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return errs.New("Error starting master database: %+v", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err = errs.Combine(err, db.Close())
|
|
|
|
}()
|
|
|
|
|
|
|
|
pointerDB, err := metainfo.NewStore(log.Named("pointerdb"), runCfg.Metainfo.DatabaseURL)
|
|
|
|
if err != nil {
|
|
|
|
return errs.New("Error creating metainfo database: %+v", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
2020-01-27 19:08:37 +00:00
|
|
|
err = errs.Combine(err, pointerDB.Close())
|
2019-10-29 14:55:57 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
revocationDB, err := revocation.NewDBFromCfg(runCfg.Server.Config)
|
|
|
|
if err != nil {
|
|
|
|
return errs.New("Error creating revocation database: %+v", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err = errs.Combine(err, revocationDB.Close())
|
|
|
|
}()
|
|
|
|
|
2020-01-17 22:55:53 +00:00
|
|
|
rollupsWriteCache := orders.NewRollupsWriteCache(log.Named("orders-write-cache"), db.Orders(), runCfg.Orders.FlushBatchSize)
|
|
|
|
defer func() {
|
|
|
|
err = errs.Combine(err, rollupsWriteCache.CloseAndFlush(context2.WithoutCancellation(ctx)))
|
|
|
|
}()
|
|
|
|
|
2019-10-29 14:55:57 +00:00
|
|
|
peer, err := satellite.NewRepairer(
|
|
|
|
log,
|
|
|
|
identity,
|
|
|
|
pointerDB,
|
|
|
|
revocationDB,
|
|
|
|
db.RepairQueue(),
|
|
|
|
db.Buckets(),
|
|
|
|
db.OverlayCache(),
|
2020-01-17 22:55:53 +00:00
|
|
|
rollupsWriteCache,
|
2020-02-24 20:13:12 +00:00
|
|
|
db.Irreparable(),
|
2019-10-29 14:55:57 +00:00
|
|
|
version.Build,
|
|
|
|
&runCfg.Config,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-21 17:41:54 +00:00
|
|
|
_, err = peer.Version.Service.CheckVersion(ctx)
|
2019-10-29 14:55:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-18 16:16:51 +00:00
|
|
|
if err := process.InitMetricsWithHostname(ctx, log, nil); err != nil {
|
2019-10-29 14:55:57 +00:00
|
|
|
zap.S().Warn("Failed to initialize telemetry batcher on repairer: ", err)
|
|
|
|
}
|
|
|
|
|
2020-01-13 13:44:55 +00:00
|
|
|
err = db.CheckVersion(ctx)
|
2019-11-02 20:09:07 +00:00
|
|
|
if err != nil {
|
|
|
|
zap.S().Fatal("failed satellite database version check: ", err)
|
|
|
|
return errs.New("Error checking version for satellitedb: %+v", err)
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:55:57 +00:00
|
|
|
runError := peer.Run(ctx)
|
|
|
|
closeError := peer.Close()
|
|
|
|
return errs.Combine(runError, closeError)
|
|
|
|
}
|