2020-03-12 15:40:22 +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"
|
|
|
|
|
2020-03-23 19:18:20 +00:00
|
|
|
"storj.io/private/process"
|
2020-03-23 19:30:31 +00:00
|
|
|
"storj.io/private/version"
|
2020-03-12 15:40:22 +00:00
|
|
|
"storj.io/storj/pkg/revocation"
|
|
|
|
"storj.io/storj/satellite"
|
|
|
|
"storj.io/storj/satellite/metainfo"
|
|
|
|
"storj.io/storj/satellite/satellitedb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func cmdGCRun(cmd *cobra.Command, args []string) (err error) {
|
|
|
|
ctx, _ := process.Ctx(cmd)
|
|
|
|
log := zap.L()
|
|
|
|
|
|
|
|
runCfg.Debug.Address = *process.DebugAddrFlag
|
|
|
|
|
|
|
|
identity, err := runCfg.Identity.Load()
|
|
|
|
if err != nil {
|
2020-10-13 14:49:33 +01:00
|
|
|
log.Error("Failed to load identity.", zap.Error(err))
|
|
|
|
return errs.New("Failed to load identity: %+v", err)
|
2020-03-12 15:40:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-04 10:24:39 +00:00
|
|
|
db, err := satellitedb.Open(ctx, log.Named("db"), runCfg.Database, satellitedb.Options{ApplicationName: "satellite-gc"})
|
2020-03-12 15:40:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return errs.New("Error starting master database on satellite GC: %+v", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err = errs.Combine(err, db.Close())
|
|
|
|
}()
|
|
|
|
|
2020-12-09 08:50:04 +00:00
|
|
|
metabaseDB, err := metainfo.OpenMetabase(ctx, log.Named("metabase"), runCfg.Metainfo.DatabaseURL)
|
|
|
|
if err != nil {
|
|
|
|
return errs.New("Error creating metabase connection: %+v", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err = errs.Combine(err, metabaseDB.Close())
|
|
|
|
}()
|
|
|
|
|
2020-10-28 14:01:41 +00:00
|
|
|
revocationDB, err := revocation.OpenDBFromCfg(ctx, runCfg.Server.Config)
|
2020-03-12 15:40:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return errs.New("Error creating revocation database GC: %+v", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err = errs.Combine(err, revocationDB.Close())
|
|
|
|
}()
|
|
|
|
|
2020-12-22 10:38:32 +00:00
|
|
|
peer, err := satellite.NewGarbageCollection(log, identity, db, metabaseDB, revocationDB, version.Build, &runCfg.Config, process.AtomicLevel(cmd))
|
2020-03-12 15:40:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = peer.Version.Service.CheckVersion(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-19 03:54:58 +01:00
|
|
|
if err := process.InitMetricsWithHostname(ctx, log, nil); err != nil {
|
2020-04-13 10:31:17 +01:00
|
|
|
log.Warn("Failed to initialize telemetry batcher on satellite GC", zap.Error(err))
|
2020-03-12 15:40:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 10:38:32 +00:00
|
|
|
err = metabaseDB.CheckVersion(ctx)
|
2020-04-24 20:15:27 +01:00
|
|
|
if err != nil {
|
2020-12-22 10:38:32 +00:00
|
|
|
log.Error("Failed metabase database version check.", zap.Error(err))
|
|
|
|
return errs.New("failed metabase version check: %+v", err)
|
2020-04-24 20:15:27 +01:00
|
|
|
}
|
|
|
|
|
2020-03-12 15:40:22 +00:00
|
|
|
err = db.CheckVersion(ctx)
|
|
|
|
if err != nil {
|
2020-10-13 14:49:33 +01:00
|
|
|
log.Error("Failed satellite database version check.", zap.Error(err))
|
|
|
|
return errs.New("Error checking version for satellitedb: %+v", err)
|
2020-03-12 15:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
runError := peer.Run(ctx)
|
|
|
|
closeError := peer.Close()
|
|
|
|
return errs.Combine(runError, closeError)
|
|
|
|
}
|