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"
|
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/pb"
|
|
|
|
"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"
|
2019-10-29 14:55:57 +00:00
|
|
|
"storj.io/storj/satellite/metainfo"
|
|
|
|
"storj.io/storj/satellite/orders"
|
|
|
|
"storj.io/storj/satellite/overlay"
|
2020-02-24 20:13:12 +00:00
|
|
|
"storj.io/storj/satellite/repair/irreparable"
|
2019-10-29 14:55:57 +00:00
|
|
|
"storj.io/storj/satellite/repair/queue"
|
|
|
|
"storj.io/storj/satellite/repair/repairer"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2020-01-10 18:53:42 +00:00
|
|
|
Metainfo *metainfo.Service
|
|
|
|
Overlay *overlay.Service
|
|
|
|
Orders struct {
|
|
|
|
DB orders.DB
|
|
|
|
Service *orders.Service
|
|
|
|
Chore *orders.Chore
|
|
|
|
}
|
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,
|
|
|
|
pointerDB metainfo.PointerDB,
|
|
|
|
revocationDB extensions.RevocationDB, repairQueue queue.RepairQueue,
|
2020-02-24 20:13:12 +00:00
|
|
|
bucketsDB metainfo.BucketsDB, overlayCache overlay.DB,
|
|
|
|
rollupsWriteCache *orders.RollupsWriteCache, irrDB irreparable.DB,
|
2020-05-12 20:10:32 +01:00
|
|
|
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))
|
|
|
|
err = nil
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup metainfo
|
|
|
|
peer.Metainfo = metainfo.NewService(log.Named("metainfo"), pointerDB, bucketsDB)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup overlay
|
2020-12-22 19:07:07 +00:00
|
|
|
var err error
|
|
|
|
peer.Overlay, err = overlay.NewService(log.Named("overlay"), overlayCache, config.Overlay)
|
|
|
|
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",
|
|
|
|
Close: peer.Overlay.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-06-25 15:47:44 +01:00
|
|
|
bucketsDB,
|
2020-08-27 15:30:04 +01:00
|
|
|
config.Orders,
|
2019-10-29 14:55:57 +00:00
|
|
|
&pb.NodeAddress{
|
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
|
|
|
Address: config.Contact.ExternalAddress,
|
|
|
|
},
|
|
|
|
)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup repairer
|
|
|
|
peer.SegmentRepairer = repairer.NewSegmentRepairer(
|
2020-01-06 12:34:54 +00:00
|
|
|
log.Named("segment-repair"),
|
2019-10-29 14:55:57 +00:00
|
|
|
peer.Metainfo,
|
2020-01-10 18:53:42 +00:00
|
|
|
peer.Orders.Service,
|
2019-10-29 14:55:57 +00:00
|
|
|
peer.Overlay,
|
|
|
|
peer.Dialer,
|
|
|
|
config.Repairer.Timeout,
|
|
|
|
config.Repairer.MaxExcessRateOptimalThreshold,
|
2020-10-27 18:26:46 +00:00
|
|
|
config.Checker.RepairOverrides,
|
2019-10-30 20:31:08 +00:00
|
|
|
config.Repairer.DownloadTimeout,
|
2020-03-18 23:55:09 +00:00
|
|
|
config.Repairer.InMemoryRepair,
|
2019-10-29 14:55:57 +00:00
|
|
|
signing.SigneeFromPeerIdentity(peer.Identity.PeerIdentity()),
|
|
|
|
)
|
2020-02-24 20:13:12 +00:00
|
|
|
peer.Repairer = repairer.NewService(log.Named("repairer"), repairQueue, &config.Repairer, peer.SegmentRepairer, irrDB)
|
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)
|
|
|
|
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Servers.Run(ctx, group)
|
|
|
|
peer.Services.Run(ctx, group)
|
2019-10-29 14:55:57 +00:00
|
|
|
|
|
|
|
return group.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 }
|