2022-10-26 08:02:13 +01:00
|
|
|
// Copyright (C) 2022 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"net"
|
|
|
|
"runtime/pprof"
|
|
|
|
|
|
|
|
"github.com/spacemonkeygo/monkit/v3"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
|
|
|
|
"storj.io/private/debug"
|
|
|
|
"storj.io/storj/private/lifecycle"
|
2022-12-15 19:22:18 +00:00
|
|
|
"storj.io/storj/satellite/accounting/nodetally"
|
2022-12-15 00:37:37 +00:00
|
|
|
"storj.io/storj/satellite/audit"
|
2022-12-12 23:50:35 +00:00
|
|
|
"storj.io/storj/satellite/gc/bloomfilter"
|
2022-12-09 21:28:05 +00:00
|
|
|
"storj.io/storj/satellite/gracefulexit"
|
2023-01-19 16:17:01 +00:00
|
|
|
"storj.io/storj/satellite/mailservice"
|
2022-10-26 08:02:13 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
|
|
|
"storj.io/storj/satellite/metabase/rangedloop"
|
2022-12-09 21:34:32 +00:00
|
|
|
"storj.io/storj/satellite/metrics"
|
2023-01-19 16:17:01 +00:00
|
|
|
"storj.io/storj/satellite/overlay"
|
|
|
|
"storj.io/storj/satellite/repair/checker"
|
2022-10-26 08:02:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// RangedLoop is the satellite ranged loop process.
|
|
|
|
//
|
|
|
|
// architecture: Peer
|
|
|
|
type RangedLoop struct {
|
2023-01-03 14:36:26 +00:00
|
|
|
Log *zap.Logger
|
|
|
|
DB DB
|
2022-10-26 08:02:13 +01:00
|
|
|
|
|
|
|
Servers *lifecycle.Group
|
|
|
|
Services *lifecycle.Group
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
Audit struct {
|
|
|
|
Observer rangedloop.Observer
|
|
|
|
}
|
|
|
|
|
2022-10-26 08:02:13 +01:00
|
|
|
Debug struct {
|
|
|
|
Listener net.Listener
|
|
|
|
Server *debug.Server
|
|
|
|
}
|
|
|
|
|
2022-12-09 21:34:32 +00:00
|
|
|
Metrics struct {
|
|
|
|
Observer rangedloop.Observer
|
|
|
|
}
|
|
|
|
|
2023-01-19 16:17:01 +00:00
|
|
|
Mail struct {
|
|
|
|
Service *mailservice.Service
|
|
|
|
}
|
|
|
|
|
|
|
|
Overlay struct {
|
|
|
|
Service *overlay.Service
|
|
|
|
}
|
|
|
|
|
|
|
|
Repair struct {
|
|
|
|
Observer rangedloop.Observer
|
|
|
|
}
|
|
|
|
|
2022-12-09 21:28:05 +00:00
|
|
|
GracefulExit struct {
|
|
|
|
Observer rangedloop.Observer
|
|
|
|
}
|
|
|
|
|
2022-12-12 23:50:35 +00:00
|
|
|
GarbageCollectionBF struct {
|
|
|
|
Observer rangedloop.Observer
|
|
|
|
}
|
|
|
|
|
2022-12-15 19:22:18 +00:00
|
|
|
Accounting struct {
|
|
|
|
NodeTallyObserver *nodetally.RangedLoopObserver
|
|
|
|
}
|
|
|
|
|
2022-10-26 08:02:13 +01:00
|
|
|
RangedLoop struct {
|
|
|
|
Service *rangedloop.Service
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRangedLoop creates a new satellite ranged loop process.
|
2023-01-19 16:17:01 +00:00
|
|
|
func NewRangedLoop(log *zap.Logger, db DB, metabaseDB *metabase.DB, config *Config, atomicLogLevel *zap.AtomicLevel) (_ *RangedLoop, err error) {
|
2022-10-26 08:02:13 +01:00
|
|
|
peer := &RangedLoop{
|
2023-01-03 14:36:26 +00:00
|
|
|
Log: log,
|
|
|
|
DB: db,
|
2022-10-26 08:02:13 +01:00
|
|
|
|
|
|
|
Servers: lifecycle.NewGroup(log.Named("servers")),
|
|
|
|
Services: lifecycle.NewGroup(log.Named("services")),
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup debug
|
|
|
|
var err error
|
|
|
|
if config.Debug.Address != "" {
|
|
|
|
peer.Debug.Listener, err = net.Listen("tcp", config.Debug.Address)
|
|
|
|
if err != nil {
|
|
|
|
withoutStack := errors.New(err.Error())
|
|
|
|
peer.Log.Debug("failed to start debug endpoints", zap.Error(withoutStack))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debugConfig := config.Debug
|
|
|
|
debugConfig.ControlTitle = "RangedLoop"
|
|
|
|
peer.Debug.Server = debug.NewServerWithAtomicLevel(log.Named("debug"), peer.Debug.Listener, monkit.Default, debugConfig, atomicLogLevel)
|
|
|
|
peer.Servers.Add(lifecycle.Item{
|
|
|
|
Name: "debug",
|
|
|
|
Run: peer.Debug.Server.Run,
|
|
|
|
Close: peer.Debug.Server.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
{ // setup audit observer
|
|
|
|
peer.Audit.Observer = audit.NewObserver(log.Named("audit"), db.VerifyQueue(), config.Audit)
|
|
|
|
}
|
|
|
|
|
2022-12-09 21:34:32 +00:00
|
|
|
{ // setup metrics observer
|
|
|
|
peer.Metrics.Observer = metrics.NewObserver()
|
|
|
|
}
|
|
|
|
|
2022-12-09 21:28:05 +00:00
|
|
|
{ // setup gracefulexit
|
|
|
|
peer.GracefulExit.Observer = gracefulexit.NewObserver(
|
|
|
|
peer.Log.Named("gracefulexit:observer"),
|
|
|
|
peer.DB.GracefulExit(),
|
|
|
|
peer.DB.OverlayCache(),
|
|
|
|
config.GracefulExit,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-12-15 19:22:18 +00:00
|
|
|
{ // setup node tally observer
|
|
|
|
peer.Accounting.NodeTallyObserver = nodetally.NewRangedLoopObserver(
|
|
|
|
log.Named("accounting:nodetally"),
|
|
|
|
db.StoragenodeAccounting())
|
|
|
|
}
|
|
|
|
|
2023-01-19 16:17:01 +00:00
|
|
|
{ // setup mail service
|
|
|
|
peer.Mail.Service, 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.Service.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup overlay
|
|
|
|
peer.Overlay.Service, err = overlay.NewService(peer.Log.Named("overlay"), peer.DB.OverlayCache(), peer.DB.NodeEvents(), peer.Mail.Service, config.Console.ExternalAddress, config.Console.SatelliteName, config.Overlay)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "overlay",
|
|
|
|
Run: peer.Overlay.Service.Run,
|
|
|
|
Close: peer.Overlay.Service.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup repair
|
|
|
|
peer.Repair.Observer = checker.NewRangedLoopObserver(
|
|
|
|
peer.Log.Named("repair:checker"),
|
|
|
|
peer.DB.RepairQueue(),
|
|
|
|
peer.Overlay.Service,
|
|
|
|
config.Checker,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-12-12 23:50:35 +00:00
|
|
|
{ // setup garbage collection bloom filter observer
|
|
|
|
peer.GarbageCollectionBF.Observer = bloomfilter.NewObserver(log.Named("gc-bf"), config.GarbageCollectionBF, db.OverlayCache())
|
|
|
|
}
|
|
|
|
|
2022-10-26 08:02:13 +01:00
|
|
|
{ // setup ranged loop
|
2023-01-06 08:49:14 +00:00
|
|
|
observers := []rangedloop.Observer{
|
2023-03-06 09:30:53 +00:00
|
|
|
rangedloop.NewLiveCountObserver(metabaseDB, config.RangedLoop.SuspiciousProcessedRatio, config.RangedLoop.AsOfSystemInterval),
|
2023-01-06 08:49:14 +00:00
|
|
|
}
|
2022-12-09 21:34:32 +00:00
|
|
|
|
2022-12-15 00:37:37 +00:00
|
|
|
if config.Audit.UseRangedLoop {
|
|
|
|
observers = append(observers, peer.Audit.Observer)
|
|
|
|
}
|
|
|
|
|
2022-12-09 21:34:32 +00:00
|
|
|
if config.Metrics.UseRangedLoop {
|
|
|
|
observers = append(observers, peer.Metrics.Observer)
|
|
|
|
}
|
2023-01-19 16:17:01 +00:00
|
|
|
|
2022-12-15 19:22:18 +00:00
|
|
|
if config.Tally.UseRangedLoop {
|
|
|
|
observers = append(observers, peer.Accounting.NodeTallyObserver)
|
|
|
|
}
|
2022-12-09 21:34:32 +00:00
|
|
|
|
2022-12-09 21:28:05 +00:00
|
|
|
if config.GracefulExit.Enabled && config.GracefulExit.UseRangedLoop {
|
|
|
|
observers = append(observers, peer.GracefulExit.Observer)
|
|
|
|
}
|
|
|
|
|
2022-12-12 23:50:35 +00:00
|
|
|
if config.GarbageCollectionBF.Enabled && config.GarbageCollectionBF.UseRangedLoop {
|
|
|
|
observers = append(observers, peer.GarbageCollectionBF.Observer)
|
|
|
|
}
|
|
|
|
|
2023-01-19 16:17:01 +00:00
|
|
|
if config.Repairer.UseRangedLoop {
|
|
|
|
observers = append(observers, peer.Repair.Observer)
|
|
|
|
}
|
|
|
|
|
2023-01-06 08:37:32 +00:00
|
|
|
segments := rangedloop.NewMetabaseRangeSplitter(metabaseDB, config.RangedLoop.AsOfSystemInterval, config.RangedLoop.BatchSize)
|
2023-01-19 16:17:01 +00:00
|
|
|
peer.RangedLoop.Service = rangedloop.NewService(log.Named("rangedloop"), config.RangedLoop, segments, observers)
|
2022-10-26 08:02:13 +01:00
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "rangeloop",
|
|
|
|
Run: peer.RangedLoop.Service.Run,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return peer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run runs satellite ranged loop until it's either closed or it errors.
|
|
|
|
func (peer *RangedLoop) Run(ctx context.Context) (err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
group, ctx := errgroup.WithContext(ctx)
|
|
|
|
|
|
|
|
pprof.Do(ctx, pprof.Labels("subsystem", "rangedloop"), func(ctx context.Context) {
|
|
|
|
peer.Servers.Run(ctx, group)
|
|
|
|
peer.Services.Run(ctx, group)
|
|
|
|
|
|
|
|
pprof.Do(ctx, pprof.Labels("name", "subsystem-wait"), func(ctx context.Context) {
|
|
|
|
err = group.Wait()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes all the resources.
|
|
|
|
func (peer *RangedLoop) Close() error {
|
|
|
|
return errs.Combine(
|
|
|
|
peer.Servers.Close(),
|
|
|
|
peer.Services.Close(),
|
|
|
|
)
|
|
|
|
}
|