2019-10-29 14:55:57 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-01-29 23:04:30 +00:00
|
|
|
"errors"
|
2020-01-28 17:35:45 +00:00
|
|
|
"net"
|
2022-05-06 22:04:07 +01:00
|
|
|
"runtime/pprof"
|
2019-10-29 14:55:57 +00:00
|
|
|
|
2019-11-08 20:40:39 +00:00
|
|
|
"github.com/spacemonkeygo/monkit/v3"
|
2019-10-29 14:55:57 +00:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/identity"
|
|
|
|
"storj.io/common/peertls/extensions"
|
|
|
|
"storj.io/common/peertls/tlsopts"
|
|
|
|
"storj.io/common/rpc"
|
|
|
|
"storj.io/common/signing"
|
|
|
|
"storj.io/common/storj"
|
2020-03-23 19:18:20 +00:00
|
|
|
"storj.io/private/debug"
|
2020-03-23 19:30:31 +00:00
|
|
|
"storj.io/private/version"
|
2020-01-28 23:13:59 +00:00
|
|
|
"storj.io/storj/private/lifecycle"
|
2019-11-14 19:46:15 +00:00
|
|
|
version_checker "storj.io/storj/private/version/checker"
|
2021-08-03 14:21:27 +01:00
|
|
|
"storj.io/storj/satellite/audit"
|
2021-11-12 20:47:41 +00:00
|
|
|
"storj.io/storj/satellite/buckets"
|
2022-09-28 20:53:48 +01:00
|
|
|
"storj.io/storj/satellite/mailservice"
|
2021-05-13 09:14:18 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2019-10-29 14:55:57 +00:00
|
|
|
"storj.io/storj/satellite/orders"
|
|
|
|
"storj.io/storj/satellite/overlay"
|
|
|
|
"storj.io/storj/satellite/repair/queue"
|
|
|
|
"storj.io/storj/satellite/repair/repairer"
|
2021-07-15 15:14:13 +01:00
|
|
|
"storj.io/storj/satellite/reputation"
|
2019-10-29 14:55:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Repairer is the repairer process.
|
|
|
|
//
|
|
|
|
// architecture: Peer
|
|
|
|
type Repairer struct {
|
|
|
|
Log *zap.Logger
|
|
|
|
Identity *identity.FullIdentity
|
|
|
|
|
2020-01-28 23:13:59 +00:00
|
|
|
Servers *lifecycle.Group
|
|
|
|
Services *lifecycle.Group
|
|
|
|
|
2020-02-21 17:41:54 +00:00
|
|
|
Dialer rpc.Dialer
|
|
|
|
|
|
|
|
Version struct {
|
|
|
|
Chore *version_checker.Chore
|
|
|
|
Service *version_checker.Service
|
|
|
|
}
|
2019-10-29 14:55:57 +00:00
|
|
|
|
2020-01-28 17:35:45 +00:00
|
|
|
Debug struct {
|
|
|
|
Listener net.Listener
|
|
|
|
Server *debug.Server
|
|
|
|
}
|
|
|
|
|
2022-09-28 20:53:48 +01:00
|
|
|
Mail *mailservice.Service
|
2021-07-15 15:14:13 +01:00
|
|
|
Overlay *overlay.Service
|
|
|
|
Reputation *reputation.Service
|
|
|
|
Orders struct {
|
2020-01-10 18:53:42 +00:00
|
|
|
DB orders.DB
|
|
|
|
Service *orders.Service
|
|
|
|
Chore *orders.Chore
|
|
|
|
}
|
2021-08-03 14:21:27 +01:00
|
|
|
|
|
|
|
Audit struct {
|
2022-04-11 17:47:14 +01:00
|
|
|
Reporter audit.Reporter
|
2021-08-03 14:21:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EcRepairer *repairer.ECRepairer
|
2019-10-29 14:55:57 +00:00
|
|
|
SegmentRepairer *repairer.SegmentRepairer
|
|
|
|
Repairer *repairer.Service
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRepairer creates a new repairer peer.
|
2020-01-17 22:55:53 +00:00
|
|
|
func NewRepairer(log *zap.Logger, full *identity.FullIdentity,
|
2021-05-13 09:14:18 +01:00
|
|
|
metabaseDB *metabase.DB,
|
2021-08-03 14:21:27 +01:00
|
|
|
revocationDB extensions.RevocationDB,
|
|
|
|
repairQueue queue.RepairQueue,
|
2021-11-12 20:47:41 +00:00
|
|
|
bucketsDB buckets.DB,
|
2021-08-03 14:21:27 +01:00
|
|
|
overlayCache overlay.DB,
|
|
|
|
reputationdb reputation.DB,
|
|
|
|
containmentDB audit.Containment,
|
|
|
|
rollupsWriteCache *orders.RollupsWriteCache,
|
|
|
|
versionInfo version.Info, config *Config, atomicLogLevel *zap.AtomicLevel,
|
|
|
|
) (*Repairer, error) {
|
2019-10-29 14:55:57 +00:00
|
|
|
peer := &Repairer{
|
|
|
|
Log: log,
|
|
|
|
Identity: full,
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
Servers: lifecycle.NewGroup(log.Named("servers")),
|
|
|
|
Services: lifecycle.NewGroup(log.Named("services")),
|
2019-10-29 14:55:57 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 17:35:45 +00:00
|
|
|
{ // setup debug
|
|
|
|
var err error
|
|
|
|
if config.Debug.Address != "" {
|
|
|
|
peer.Debug.Listener, err = net.Listen("tcp", config.Debug.Address)
|
|
|
|
if err != nil {
|
2020-01-29 23:04:30 +00:00
|
|
|
withoutStack := errors.New(err.Error())
|
|
|
|
peer.Log.Debug("failed to start debug endpoints", zap.Error(withoutStack))
|
2020-01-28 17:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-30 12:49:40 +00:00
|
|
|
debugConfig := config.Debug
|
|
|
|
debugConfig.ControlTitle = "Repair"
|
2020-05-12 20:10:32 +01:00
|
|
|
peer.Debug.Server = debug.NewServerWithAtomicLevel(log.Named("debug"), peer.Debug.Listener, monkit.Default, debugConfig, atomicLogLevel)
|
2020-01-28 17:35:45 +00:00
|
|
|
peer.Servers.Add(lifecycle.Item{
|
|
|
|
Name: "debug",
|
|
|
|
Run: peer.Debug.Server.Run,
|
|
|
|
Close: peer.Debug.Server.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:55:57 +00:00
|
|
|
{
|
2020-04-15 20:32:22 +01:00
|
|
|
peer.Log.Info("Version info",
|
|
|
|
zap.Stringer("Version", versionInfo.Version.Version),
|
|
|
|
zap.String("Commit Hash", versionInfo.CommitHash),
|
|
|
|
zap.Stringer("Build Timestamp", versionInfo.Timestamp),
|
|
|
|
zap.Bool("Release Build", versionInfo.Release),
|
|
|
|
)
|
2020-02-21 17:41:54 +00:00
|
|
|
peer.Version.Service = version_checker.NewService(log.Named("version"), config.Version, versionInfo, "Satellite")
|
|
|
|
peer.Version.Chore = version_checker.NewChore(peer.Version.Service, config.Version.CheckInterval)
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "version",
|
2020-02-21 17:41:54 +00:00
|
|
|
Run: peer.Version.Chore.Run,
|
2020-01-28 23:13:59 +00:00
|
|
|
})
|
2019-10-29 14:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup dialer
|
|
|
|
sc := config.Server
|
|
|
|
|
|
|
|
tlsOptions, err := tlsopts.NewOptions(peer.Identity, sc.Config, revocationDB)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
peer.Dialer = rpc.NewDefaultDialer(tlsOptions)
|
|
|
|
}
|
|
|
|
|
2022-09-28 20:53:48 +01:00
|
|
|
{ // setup mail
|
|
|
|
var err error
|
|
|
|
peer.Mail, err = setupMailService(peer.Log, *config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "mail:service",
|
|
|
|
Close: peer.Mail.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:55:57 +00:00
|
|
|
{ // setup overlay
|
2020-12-22 19:07:07 +00:00
|
|
|
var err error
|
2022-09-28 20:53:48 +01:00
|
|
|
peer.Overlay, err = overlay.NewService(log.Named("overlay"), overlayCache, peer.Mail, config.Console.ExternalAddress, config.Console.SatelliteName, config.Overlay)
|
2020-12-22 19:07:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "overlay",
|
2022-06-28 12:53:39 +01:00
|
|
|
Run: peer.Overlay.Run,
|
2020-01-28 23:13:59 +00:00
|
|
|
Close: peer.Overlay.Close,
|
|
|
|
})
|
2019-10-29 14:55:57 +00:00
|
|
|
}
|
|
|
|
|
2021-07-15 15:14:13 +01:00
|
|
|
{ // setup reputation
|
2022-05-07 20:04:12 +01:00
|
|
|
if config.Reputation.FlushInterval > 0 {
|
2022-07-28 00:43:02 +01:00
|
|
|
cachingDB := reputation.NewCachingDB(log.Named("reputation:writecache"), reputationdb, config.Reputation)
|
2022-05-07 20:04:12 +01:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "reputation:writecache",
|
|
|
|
Run: cachingDB.Manage,
|
|
|
|
})
|
|
|
|
reputationdb = cachingDB
|
|
|
|
}
|
2021-07-15 15:14:13 +01:00
|
|
|
peer.Reputation = reputation.NewService(log.Named("reputation:service"),
|
2022-09-29 15:03:01 +01:00
|
|
|
peer.Overlay,
|
2021-07-15 15:14:13 +01:00
|
|
|
reputationdb,
|
|
|
|
config.Reputation,
|
|
|
|
)
|
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "reputation",
|
|
|
|
Close: peer.Reputation.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:55:57 +00:00
|
|
|
{ // setup orders
|
2020-01-17 22:55:53 +00:00
|
|
|
peer.Orders.DB = rollupsWriteCache
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Orders.Chore = orders.NewChore(log.Named("orders:chore"), rollupsWriteCache, config.Orders)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "orders:chore",
|
|
|
|
Run: peer.Orders.Chore.Run,
|
|
|
|
Close: peer.Orders.Chore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Orders Chore", peer.Orders.Chore.Loop))
|
|
|
|
|
2020-07-24 18:13:15 +01:00
|
|
|
var err error
|
|
|
|
peer.Orders.Service, err = orders.NewService(
|
2019-10-29 14:55:57 +00:00
|
|
|
log.Named("orders"),
|
|
|
|
signing.SignerFromFullIdentity(peer.Identity),
|
|
|
|
peer.Overlay,
|
2020-01-10 18:53:42 +00:00
|
|
|
peer.Orders.DB,
|
2020-08-27 15:30:04 +01:00
|
|
|
config.Orders,
|
2019-10-29 14:55:57 +00:00
|
|
|
)
|
2020-07-24 18:13:15 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2019-10-29 14:55:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-03 14:21:27 +01:00
|
|
|
{ // setup audit
|
|
|
|
peer.Audit.Reporter = audit.NewReporter(
|
|
|
|
log.Named("reporter"),
|
|
|
|
peer.Reputation,
|
|
|
|
containmentDB,
|
|
|
|
config.Audit.MaxRetriesStatDB,
|
|
|
|
int32(config.Audit.MaxReverifyCount))
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:55:57 +00:00
|
|
|
{ // setup repairer
|
2021-08-03 14:21:27 +01:00
|
|
|
peer.EcRepairer = repairer.NewECRepairer(
|
|
|
|
log.Named("ec-repair"),
|
|
|
|
peer.Dialer,
|
|
|
|
signing.SigneeFromPeerIdentity(peer.Identity.PeerIdentity()),
|
|
|
|
config.Repairer.DownloadTimeout,
|
|
|
|
config.Repairer.InMemoryRepair)
|
|
|
|
|
2019-10-29 14:55:57 +00:00
|
|
|
peer.SegmentRepairer = repairer.NewSegmentRepairer(
|
2020-01-06 12:34:54 +00:00
|
|
|
log.Named("segment-repair"),
|
2020-12-14 14:29:48 +00:00
|
|
|
metabaseDB,
|
2020-01-10 18:53:42 +00:00
|
|
|
peer.Orders.Service,
|
2019-10-29 14:55:57 +00:00
|
|
|
peer.Overlay,
|
2021-08-03 14:21:27 +01:00
|
|
|
peer.Audit.Reporter,
|
|
|
|
peer.EcRepairer,
|
|
|
|
config.Checker.RepairOverrides,
|
2019-10-29 14:55:57 +00:00
|
|
|
config.Repairer.Timeout,
|
|
|
|
config.Repairer.MaxExcessRateOptimalThreshold,
|
|
|
|
)
|
2021-06-15 22:45:31 +01:00
|
|
|
peer.Repairer = repairer.NewService(log.Named("repairer"), repairQueue, &config.Repairer, peer.SegmentRepairer)
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "repair",
|
|
|
|
Run: peer.Repairer.Run,
|
|
|
|
Close: peer.Repairer.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Repair Worker", peer.Repairer.Loop))
|
2019-10-29 14:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return peer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run runs the repair process until it's either closed or it errors.
|
|
|
|
func (peer *Repairer) Run(ctx context.Context) (err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
group, ctx := errgroup.WithContext(ctx)
|
|
|
|
|
2022-05-06 22:04:07 +01:00
|
|
|
pprof.Do(ctx, pprof.Labels("subsystem", "repairer"), func(ctx context.Context) {
|
|
|
|
peer.Servers.Run(ctx, group)
|
|
|
|
peer.Services.Run(ctx, group)
|
2019-10-29 14:55:57 +00:00
|
|
|
|
2022-05-06 22:04:07 +01:00
|
|
|
pprof.Do(ctx, pprof.Labels("name", "subsystem-wait"), func(ctx context.Context) {
|
|
|
|
err = group.Wait()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return err
|
2019-10-29 14:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes all the resources.
|
|
|
|
func (peer *Repairer) Close() error {
|
2020-01-28 23:13:59 +00:00
|
|
|
return errs.Combine(
|
|
|
|
peer.Servers.Close(),
|
|
|
|
peer.Services.Close(),
|
|
|
|
)
|
2019-10-29 14:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ID returns the peer ID.
|
|
|
|
func (peer *Repairer) ID() storj.NodeID { return peer.Identity.ID }
|