2019-06-21 14:39:43 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information
|
|
|
|
|
|
|
|
package testplanet
|
|
|
|
|
|
|
|
import (
|
2019-10-14 21:01:53 +01:00
|
|
|
"context"
|
|
|
|
"net"
|
2019-06-21 14:39:43 +01:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2020-10-29 11:58:36 +00:00
|
|
|
"runtime/pprof"
|
2019-06-21 14:39:43 +01:00
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
2019-08-19 23:10:38 +01:00
|
|
|
"github.com/zeebo/errs"
|
2019-10-14 21:01:53 +01:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"golang.org/x/sync/errgroup"
|
2019-08-19 23:10:38 +01:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/errs2"
|
|
|
|
"storj.io/common/identity"
|
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/peertls/extensions"
|
|
|
|
"storj.io/common/peertls/tlsopts"
|
|
|
|
"storj.io/common/rpc"
|
|
|
|
"storj.io/common/storj"
|
2020-05-19 11:21:56 +01:00
|
|
|
"storj.io/common/uuid"
|
2020-03-23 19:18:20 +00:00
|
|
|
"storj.io/private/debug"
|
2020-03-23 19:30:31 +00:00
|
|
|
"storj.io/private/version"
|
2019-08-19 23:10:38 +01:00
|
|
|
"storj.io/storj/pkg/revocation"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/pkg/server"
|
2019-11-14 19:46:15 +00:00
|
|
|
versionchecker "storj.io/storj/private/version/checker"
|
2020-04-08 20:40:49 +01:00
|
|
|
"storj.io/storj/private/web"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/satellite"
|
2019-10-14 21:01:53 +01:00
|
|
|
"storj.io/storj/satellite/accounting"
|
|
|
|
"storj.io/storj/satellite/accounting/live"
|
2020-07-07 15:48:09 +01:00
|
|
|
"storj.io/storj/satellite/accounting/projectbwcleanup"
|
2020-01-15 21:45:17 +00:00
|
|
|
"storj.io/storj/satellite/accounting/reportedrollup"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/accounting/rollup"
|
|
|
|
"storj.io/storj/satellite/accounting/tally"
|
2020-02-07 16:36:28 +00:00
|
|
|
"storj.io/storj/satellite/admin"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/audit"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/satellite/console"
|
2020-10-06 11:40:31 +01:00
|
|
|
"storj.io/storj/satellite/console/consoleauth"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/satellite/console/consoleweb"
|
2019-10-14 21:01:53 +01:00
|
|
|
"storj.io/storj/satellite/contact"
|
2019-08-27 18:12:38 +01:00
|
|
|
"storj.io/storj/satellite/dbcleanup"
|
2019-12-30 19:42:10 +00:00
|
|
|
"storj.io/storj/satellite/downtime"
|
2019-07-24 18:26:43 +01:00
|
|
|
"storj.io/storj/satellite/gc"
|
2019-10-07 21:38:05 +01:00
|
|
|
"storj.io/storj/satellite/gracefulexit"
|
2019-10-14 21:01:53 +01:00
|
|
|
"storj.io/storj/satellite/inspector"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/satellite/mailservice"
|
2019-06-24 21:51:54 +01:00
|
|
|
"storj.io/storj/satellite/marketingweb"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/satellite/metainfo"
|
2020-04-15 20:20:16 +01:00
|
|
|
"storj.io/storj/satellite/metainfo/expireddeletion"
|
2020-07-09 16:32:35 +01:00
|
|
|
"storj.io/storj/satellite/metainfo/objectdeletion"
|
2020-03-12 07:03:46 +00:00
|
|
|
"storj.io/storj/satellite/metainfo/piecedeletion"
|
2019-10-16 19:08:33 +01:00
|
|
|
"storj.io/storj/satellite/metrics"
|
2019-10-14 21:01:53 +01:00
|
|
|
"storj.io/storj/satellite/nodestats"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/satellite/orders"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
2020-05-18 10:17:05 +01:00
|
|
|
"storj.io/storj/satellite/payments/paymentsconfig"
|
|
|
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/repair/checker"
|
2019-10-14 21:01:53 +01:00
|
|
|
"storj.io/storj/satellite/repair/irreparable"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/repair/repairer"
|
2020-03-27 16:18:19 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
2019-10-31 17:27:38 +00:00
|
|
|
"storj.io/storj/storage/redis/redisserver"
|
2019-06-21 14:39:43 +01:00
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Satellite contains all the processes needed to run a full Satellite setup.
|
2020-03-27 14:46:40 +00:00
|
|
|
type Satellite struct {
|
2020-10-29 11:58:36 +00:00
|
|
|
Name string
|
2020-03-27 14:46:40 +00:00
|
|
|
Config satellite.Config
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
Core *satellite.Core
|
2019-10-29 14:55:57 +00:00
|
|
|
API *satellite.API
|
|
|
|
Repairer *satellite.Repairer
|
2020-02-07 15:56:59 +00:00
|
|
|
Admin *satellite.Admin
|
2020-03-12 15:40:22 +00:00
|
|
|
GC *satellite.GarbageCollection
|
2019-10-14 21:01:53 +01:00
|
|
|
|
|
|
|
Log *zap.Logger
|
|
|
|
Identity *identity.FullIdentity
|
|
|
|
DB satellite.DB
|
|
|
|
|
|
|
|
Dialer rpc.Dialer
|
|
|
|
|
|
|
|
Server *server.Server
|
|
|
|
|
2019-10-21 11:50:59 +01:00
|
|
|
Version *versionchecker.Service
|
2019-10-14 21:01:53 +01:00
|
|
|
|
|
|
|
Contact struct {
|
|
|
|
Service *contact.Service
|
|
|
|
Endpoint *contact.Endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
Overlay struct {
|
|
|
|
DB overlay.DB
|
|
|
|
Service *overlay.Service
|
|
|
|
Inspector *overlay.Inspector
|
|
|
|
}
|
|
|
|
|
|
|
|
Metainfo struct {
|
|
|
|
Database metainfo.PointerDB
|
|
|
|
Service *metainfo.Service
|
|
|
|
Endpoint2 *metainfo.Endpoint
|
|
|
|
Loop *metainfo.Loop
|
|
|
|
}
|
|
|
|
|
|
|
|
Inspector struct {
|
|
|
|
Endpoint *inspector.Endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
Orders struct {
|
2020-01-10 18:53:42 +00:00
|
|
|
DB orders.DB
|
2019-10-14 21:01:53 +01:00
|
|
|
Endpoint *orders.Endpoint
|
|
|
|
Service *orders.Service
|
2020-01-10 18:53:42 +00:00
|
|
|
Chore *orders.Chore
|
2019-10-14 21:01:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Repair struct {
|
|
|
|
Checker *checker.Checker
|
|
|
|
Repairer *repairer.Service
|
|
|
|
Inspector *irreparable.Inspector
|
|
|
|
}
|
|
|
|
Audit struct {
|
2020-08-20 14:29:02 +01:00
|
|
|
Queues *audit.Queues
|
2019-10-14 21:01:53 +01:00
|
|
|
Worker *audit.Worker
|
|
|
|
Chore *audit.Chore
|
|
|
|
Verifier *audit.Verifier
|
|
|
|
Reporter *audit.Reporter
|
|
|
|
}
|
|
|
|
|
|
|
|
GarbageCollection struct {
|
|
|
|
Service *gc.Service
|
|
|
|
}
|
|
|
|
|
2020-04-15 20:20:16 +01:00
|
|
|
ExpiredDeletion struct {
|
|
|
|
Chore *expireddeletion.Chore
|
|
|
|
}
|
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
DBCleanup struct {
|
|
|
|
Chore *dbcleanup.Chore
|
|
|
|
}
|
|
|
|
|
|
|
|
Accounting struct {
|
2020-07-07 15:48:09 +01:00
|
|
|
Tally *tally.Service
|
|
|
|
Rollup *rollup.Service
|
|
|
|
ProjectUsage *accounting.Service
|
|
|
|
ReportedRollup *reportedrollup.Chore
|
|
|
|
ProjectBWCleanup *projectbwcleanup.Chore
|
2019-10-14 21:01:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LiveAccounting struct {
|
2019-10-16 17:50:29 +01:00
|
|
|
Cache accounting.Cache
|
2019-10-14 21:01:53 +01:00
|
|
|
}
|
|
|
|
|
2020-09-09 20:20:44 +01:00
|
|
|
ProjectLimits struct {
|
|
|
|
Cache *accounting.ProjectLimitCache
|
|
|
|
}
|
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
Mail struct {
|
|
|
|
Service *mailservice.Service
|
|
|
|
}
|
|
|
|
|
|
|
|
Console struct {
|
|
|
|
Listener net.Listener
|
|
|
|
Service *console.Service
|
|
|
|
Endpoint *consoleweb.Server
|
|
|
|
}
|
|
|
|
|
|
|
|
Marketing struct {
|
|
|
|
Listener net.Listener
|
|
|
|
Endpoint *marketingweb.Server
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeStats struct {
|
|
|
|
Endpoint *nodestats.Endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
GracefulExit struct {
|
|
|
|
Chore *gracefulexit.Chore
|
|
|
|
Endpoint *gracefulexit.Endpoint
|
|
|
|
}
|
2019-10-16 19:08:33 +01:00
|
|
|
|
|
|
|
Metrics struct {
|
|
|
|
Chore *metrics.Chore
|
|
|
|
}
|
2019-12-30 19:42:10 +00:00
|
|
|
|
|
|
|
DowntimeTracking struct {
|
2020-01-07 21:34:48 +00:00
|
|
|
DetectionChore *downtime.DetectionChore
|
|
|
|
EstimationChore *downtime.EstimationChore
|
|
|
|
Service *downtime.Service
|
2019-12-30 19:42:10 +00:00
|
|
|
}
|
2019-10-14 21:01:53 +01:00
|
|
|
}
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
// Label returns name for debugger.
|
|
|
|
func (system *Satellite) Label() string { return system.Name }
|
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
// ID returns the ID of the Satellite system.
|
2020-03-27 14:46:40 +00:00
|
|
|
func (system *Satellite) ID() storj.NodeID { return system.API.Identity.ID }
|
2019-10-14 21:01:53 +01:00
|
|
|
|
|
|
|
// Addr returns the public address from the Satellite system API.
|
2020-03-27 14:46:40 +00:00
|
|
|
func (system *Satellite) Addr() string { return system.API.Server.Addr().String() }
|
2019-10-14 21:01:53 +01:00
|
|
|
|
2020-04-16 13:12:46 +01:00
|
|
|
// URL returns the node url from the Satellite system API.
|
|
|
|
func (system *Satellite) URL() string { return system.NodeURL().String() }
|
|
|
|
|
|
|
|
// NodeURL returns the storj.NodeURL from the Satellite system API.
|
|
|
|
func (system *Satellite) NodeURL() storj.NodeURL {
|
2019-10-14 21:01:53 +01:00
|
|
|
return storj.NodeURL{ID: system.API.ID(), Address: system.API.Addr()}
|
|
|
|
}
|
|
|
|
|
2020-07-24 10:40:17 +01:00
|
|
|
// AddUser adds user to a satellite. Password from newUser will be always overridden by FullName to have
|
|
|
|
// known password which can be used automatically.
|
|
|
|
func (system *Satellite) AddUser(ctx context.Context, newUser console.CreateUser, maxNumberOfProjects int) (*console.User, error) {
|
2020-05-19 11:21:56 +01:00
|
|
|
regToken, err := system.API.Console.Service.CreateRegToken(ctx, maxNumberOfProjects)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-07-24 10:40:17 +01:00
|
|
|
newUser.Password = newUser.FullName
|
|
|
|
user, err := system.API.Console.Service.CreateUser(ctx, newUser, regToken.Secret, "")
|
2020-05-19 11:21:56 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
activationToken, err := system.API.Console.Service.GenerateActivationToken(ctx, user.ID, user.Email)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = system.API.Console.Service.ActivateAccount(ctx, activationToken)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-07-24 10:40:17 +01:00
|
|
|
authCtx, err := system.AuthenticatedContext(ctx, user.ID)
|
2020-05-19 11:21:56 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = system.API.Console.Service.Payments().SetupAccount(authCtx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return user, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddProject adds project to a satellite and makes specified user an owner.
|
|
|
|
func (system *Satellite) AddProject(ctx context.Context, ownerID uuid.UUID, name string) (*console.Project, error) {
|
2020-07-24 10:40:17 +01:00
|
|
|
authCtx, err := system.AuthenticatedContext(ctx, ownerID)
|
2020-05-19 11:21:56 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
project, err := system.API.Console.Service.CreateProject(authCtx, console.ProjectInfo{
|
|
|
|
Name: name,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return project, nil
|
|
|
|
}
|
|
|
|
|
2020-07-24 10:40:17 +01:00
|
|
|
// AuthenticatedContext creates context with authentication date for given user.
|
|
|
|
func (system *Satellite) AuthenticatedContext(ctx context.Context, userID uuid.UUID) (context.Context, error) {
|
2020-05-19 11:21:56 +01:00
|
|
|
user, err := system.API.Console.Service.GetUser(ctx, userID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// we are using full name as a password
|
|
|
|
token, err := system.API.Console.Service.Token(ctx, user.Email, user.FullName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-10-06 11:40:31 +01:00
|
|
|
auth, err := system.API.Console.Service.Authorize(consoleauth.WithAPIKey(ctx, []byte(token)))
|
2020-05-19 11:21:56 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return console.WithAuth(ctx, auth), nil
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Close closes all the subsystems in the Satellite system.
|
2020-03-27 14:46:40 +00:00
|
|
|
func (system *Satellite) Close() error {
|
2020-02-07 16:36:28 +00:00
|
|
|
return errs.Combine(
|
|
|
|
system.API.Close(),
|
|
|
|
system.Core.Close(),
|
|
|
|
system.Repairer.Close(),
|
|
|
|
system.Admin.Close(),
|
2020-03-12 15:40:22 +00:00
|
|
|
system.GC.Close(),
|
2020-02-07 16:36:28 +00:00
|
|
|
)
|
2019-10-14 21:01:53 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Run runs all the subsystems in the Satellite system.
|
2020-03-27 14:46:40 +00:00
|
|
|
func (system *Satellite) Run(ctx context.Context) (err error) {
|
2019-10-14 21:01:53 +01:00
|
|
|
group, ctx := errgroup.WithContext(ctx)
|
|
|
|
|
|
|
|
group.Go(func() error {
|
2019-11-04 19:01:02 +00:00
|
|
|
return errs2.IgnoreCanceled(system.Core.Run(ctx))
|
2019-10-14 21:01:53 +01:00
|
|
|
})
|
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(system.API.Run(ctx))
|
|
|
|
})
|
2019-10-29 14:55:57 +00:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(system.Repairer.Run(ctx))
|
|
|
|
})
|
2020-02-07 16:36:28 +00:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(system.Admin.Run(ctx))
|
|
|
|
})
|
2020-03-12 15:40:22 +00:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(system.GC.Run(ctx))
|
|
|
|
})
|
2019-10-14 21:01:53 +01:00
|
|
|
return group.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrivateAddr returns the private address from the Satellite system API.
|
2020-03-27 14:46:40 +00:00
|
|
|
func (system *Satellite) PrivateAddr() string { return system.API.Server.PrivateAddr().String() }
|
2019-10-14 21:01:53 +01:00
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// newSatellites initializes satellites.
|
2020-10-29 11:58:36 +00:00
|
|
|
func (planet *Planet) newSatellites(ctx context.Context, count int, databases satellitedbtest.SatelliteDatabases) ([]*Satellite, error) {
|
|
|
|
var satellites []*Satellite
|
2019-06-21 14:39:43 +01:00
|
|
|
|
|
|
|
for i := 0; i < count; i++ {
|
2020-10-29 11:58:36 +00:00
|
|
|
index := i
|
|
|
|
prefix := "satellite" + strconv.Itoa(index)
|
2019-06-21 14:39:43 +01:00
|
|
|
log := planet.log.Named(prefix)
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
var system *Satellite
|
|
|
|
var err error
|
2019-06-21 14:39:43 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
pprof.Do(ctx, pprof.Labels("peer", prefix), func(ctx context.Context) {
|
|
|
|
system, err = planet.newSatellite(ctx, prefix, index, log, databases)
|
|
|
|
})
|
2019-06-21 14:39:43 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
log.Debug("id=" + system.ID().String() + " addr=" + system.Addr())
|
|
|
|
satellites = append(satellites, system)
|
|
|
|
planet.peers = append(planet.peers, newClosablePeer(system))
|
|
|
|
}
|
2019-06-21 14:39:43 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
return satellites, nil
|
|
|
|
}
|
2020-03-27 16:18:19 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
func (planet *Planet) newSatellite(ctx context.Context, prefix string, index int, log *zap.Logger, databases satellitedbtest.SatelliteDatabases) (*Satellite, error) {
|
|
|
|
storageDir := filepath.Join(planet.directory, prefix)
|
|
|
|
if err := os.MkdirAll(storageDir, 0700); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
identity, err := planet.NewIdentity()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
db, err := satellitedbtest.CreateMasterDB(ctx, log.Named("db"), planet.config.Name, "S", index, databases.MasterDB)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if planet.config.Reconfigure.SatelliteDB != nil {
|
|
|
|
var newdb satellite.DB
|
|
|
|
newdb, err = planet.config.Reconfigure.SatelliteDB(log.Named("db"), index, db)
|
2019-10-10 19:06:26 +01:00
|
|
|
if err != nil {
|
2020-10-29 11:58:36 +00:00
|
|
|
return nil, errs.Combine(err, db.Close())
|
2019-10-10 19:06:26 +01:00
|
|
|
}
|
2020-10-29 11:58:36 +00:00
|
|
|
db = newdb
|
|
|
|
}
|
|
|
|
planet.databases = append(planet.databases, db)
|
2020-03-27 16:18:19 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
pointerDB, err := satellitedbtest.CreatePointerDB(ctx, log.Named("pointerdb"), planet.config.Name, "P", index, databases.PointerDB)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-10-10 19:06:26 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
if planet.config.Reconfigure.SatellitePointerDB != nil {
|
|
|
|
var newPointerDB metainfo.PointerDB
|
|
|
|
newPointerDB, err = planet.config.Reconfigure.SatellitePointerDB(log.Named("pointerdb"), index, pointerDB)
|
2019-10-31 17:27:38 +00:00
|
|
|
if err != nil {
|
2020-10-29 11:58:36 +00:00
|
|
|
return nil, errs.Combine(err, pointerDB.Close())
|
2019-10-31 17:27:38 +00:00
|
|
|
}
|
2020-10-29 11:58:36 +00:00
|
|
|
pointerDB = newPointerDB
|
|
|
|
}
|
|
|
|
planet.databases = append(planet.databases, pointerDB)
|
2020-03-12 07:03:46 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
redis, err := redisserver.Mini(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
planet.databases = append(planet.databases, redis)
|
|
|
|
|
|
|
|
config := satellite.Config{
|
|
|
|
Server: server.Config{
|
|
|
|
Address: "127.0.0.1:0",
|
|
|
|
PrivateAddress: "127.0.0.1:0",
|
|
|
|
|
|
|
|
Config: tlsopts.Config{
|
|
|
|
RevocationDBURL: "bolt://" + filepath.Join(storageDir, "revocation.db"),
|
|
|
|
UsePeerCAWhitelist: true,
|
|
|
|
PeerCAWhitelistPath: planet.whitelistPath,
|
|
|
|
PeerIDVersions: "latest",
|
|
|
|
Extensions: extensions.Config{
|
|
|
|
Revocation: false,
|
|
|
|
WhitelistSignedLeaf: false,
|
2020-05-18 10:17:05 +01:00
|
|
|
},
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
},
|
|
|
|
Debug: debug.Config{
|
|
|
|
Address: "",
|
|
|
|
},
|
|
|
|
Admin: admin.Config{
|
|
|
|
Address: "127.0.0.1:0",
|
|
|
|
},
|
|
|
|
Contact: contact.Config{
|
|
|
|
Timeout: 1 * time.Minute,
|
|
|
|
},
|
|
|
|
Overlay: overlay.Config{
|
|
|
|
Node: overlay.NodeSelectionConfig{
|
|
|
|
UptimeCount: 0,
|
|
|
|
AuditCount: 0,
|
|
|
|
NewNodeFraction: 1,
|
|
|
|
OnlineWindow: time.Minute,
|
|
|
|
DistinctIP: false,
|
|
|
|
MinimumDiskSpace: 100 * memory.MB,
|
|
|
|
|
|
|
|
AuditReputationRepairWeight: 1,
|
|
|
|
AuditReputationUplinkWeight: 1,
|
|
|
|
AuditReputationLambda: 0.95,
|
|
|
|
AuditReputationWeight: 1,
|
|
|
|
AuditReputationDQ: 0.6,
|
|
|
|
SuspensionGracePeriod: time.Hour,
|
|
|
|
SuspensionDQEnabled: true,
|
2019-07-24 18:26:43 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
NodeSelectionCache: overlay.CacheConfig{
|
|
|
|
Staleness: 3 * time.Minute,
|
2020-04-15 20:20:16 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
UpdateStatsBatchSize: 100,
|
|
|
|
AuditHistory: overlay.AuditHistoryConfig{
|
|
|
|
WindowSize: 10 * time.Minute,
|
|
|
|
TrackingPeriod: time.Hour,
|
|
|
|
GracePeriod: time.Hour,
|
|
|
|
OfflineThreshold: 0.6,
|
2019-08-27 18:12:38 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
},
|
|
|
|
Metainfo: metainfo.Config{
|
|
|
|
DatabaseURL: "", // not used
|
|
|
|
MinRemoteSegmentSize: 0, // TODO: fix tests to work with 1024
|
|
|
|
MaxInlineSegmentSize: 4 * memory.KiB,
|
|
|
|
MaxSegmentSize: 64 * memory.MiB,
|
|
|
|
MaxMetadataSize: 2 * memory.KiB,
|
|
|
|
MaxCommitInterval: 1 * time.Hour,
|
|
|
|
Overlay: true,
|
|
|
|
RS: metainfo.RSConfig{
|
|
|
|
ErasureShareSize: memory.Size(256),
|
2020-10-27 17:34:59 +00:00
|
|
|
Min: atLeastOne(planet.config.StorageNodeCount * 1 / 5),
|
|
|
|
Repair: atLeastOne(planet.config.StorageNodeCount * 2 / 5),
|
|
|
|
Success: atLeastOne(planet.config.StorageNodeCount * 3 / 5),
|
|
|
|
Total: atLeastOne(planet.config.StorageNodeCount * 4 / 5),
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
Loop: metainfo.LoopConfig{
|
|
|
|
CoalesceDuration: 1 * time.Second,
|
|
|
|
ListLimit: 10000,
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
RateLimiter: metainfo.RateLimiterConfig{
|
|
|
|
Enabled: true,
|
|
|
|
Rate: 1000,
|
|
|
|
CacheCapacity: 100,
|
|
|
|
CacheExpiration: 10 * time.Second,
|
2020-01-15 21:45:17 +00:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
ProjectLimits: metainfo.ProjectLimitConfig{
|
|
|
|
MaxBuckets: 10,
|
|
|
|
DefaultMaxUsage: 25 * memory.GB,
|
|
|
|
DefaultMaxBandwidth: 25 * memory.GB,
|
2020-07-07 15:48:09 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
PieceDeletion: piecedeletion.Config{
|
|
|
|
MaxConcurrency: 100,
|
|
|
|
MaxConcurrentPieces: 1000,
|
|
|
|
|
|
|
|
MaxPiecesPerBatch: 4000,
|
|
|
|
MaxPiecesPerRequest: 2000,
|
|
|
|
|
|
|
|
DialTimeout: 2 * time.Second,
|
|
|
|
RequestTimeout: 2 * time.Second,
|
|
|
|
FailThreshold: 2 * time.Second,
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
ObjectDeletion: objectdeletion.Config{
|
|
|
|
MaxObjectsPerRequest: 100,
|
|
|
|
ZombieSegmentsPerRequest: 3,
|
|
|
|
MaxConcurrentRequests: 100,
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
},
|
|
|
|
Orders: orders.Config{
|
|
|
|
Expiration: 7 * 24 * time.Hour,
|
|
|
|
SettlementBatchSize: 10,
|
|
|
|
FlushBatchSize: 10,
|
|
|
|
FlushInterval: defaultInterval,
|
|
|
|
NodeStatusLogging: true,
|
|
|
|
WindowEndpointRolloutPhase: orders.WindowEndpointRolloutPhase3,
|
|
|
|
},
|
|
|
|
Checker: checker.Config{
|
|
|
|
Interval: defaultInterval,
|
|
|
|
IrreparableInterval: defaultInterval,
|
|
|
|
ReliabilityCacheStaleness: 1 * time.Minute,
|
|
|
|
},
|
|
|
|
Payments: paymentsconfig.Config{
|
|
|
|
StorageTBPrice: "10",
|
|
|
|
EgressTBPrice: "45",
|
|
|
|
ObjectPrice: "0.0000022",
|
|
|
|
StripeCoinPayments: stripecoinpayments.Config{
|
|
|
|
TransactionUpdateInterval: defaultInterval,
|
|
|
|
AccountBalanceUpdateInterval: defaultInterval,
|
|
|
|
ConversionRatesCycleInterval: defaultInterval,
|
|
|
|
ListingLimit: 100,
|
2019-10-07 21:38:05 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
CouponDuration: 2,
|
|
|
|
CouponValue: 275,
|
|
|
|
PaywallProportion: 1,
|
|
|
|
},
|
|
|
|
Repairer: repairer.Config{
|
|
|
|
MaxRepair: 10,
|
|
|
|
Interval: defaultInterval,
|
|
|
|
Timeout: 1 * time.Minute, // Repairs can take up to 10 seconds. Leaving room for outliers
|
|
|
|
DownloadTimeout: 1 * time.Minute,
|
|
|
|
TotalTimeout: 10 * time.Minute,
|
|
|
|
MaxBufferMem: 4 * memory.MiB,
|
|
|
|
MaxExcessRateOptimalThreshold: 0.05,
|
|
|
|
InMemoryRepair: false,
|
|
|
|
},
|
|
|
|
Audit: audit.Config{
|
|
|
|
MaxRetriesStatDB: 0,
|
|
|
|
MinBytesPerSecond: 1 * memory.KB,
|
|
|
|
MinDownloadTimeout: 5 * time.Second,
|
|
|
|
MaxReverifyCount: 3,
|
|
|
|
ChoreInterval: defaultInterval,
|
|
|
|
QueueInterval: defaultInterval,
|
|
|
|
Slots: 3,
|
|
|
|
WorkerConcurrency: 2,
|
|
|
|
},
|
|
|
|
GarbageCollection: gc.Config{
|
|
|
|
Interval: defaultInterval,
|
|
|
|
Enabled: true,
|
|
|
|
InitialPieces: 10,
|
|
|
|
FalsePositiveRate: 0.1,
|
|
|
|
ConcurrentSends: 1,
|
|
|
|
RunInCore: false,
|
|
|
|
},
|
|
|
|
ExpiredDeletion: expireddeletion.Config{
|
|
|
|
Interval: defaultInterval,
|
|
|
|
Enabled: true,
|
|
|
|
},
|
|
|
|
DBCleanup: dbcleanup.Config{
|
|
|
|
SerialsInterval: defaultInterval,
|
|
|
|
},
|
|
|
|
Tally: tally.Config{
|
|
|
|
Interval: defaultInterval,
|
|
|
|
},
|
|
|
|
Rollup: rollup.Config{
|
|
|
|
Interval: defaultInterval,
|
|
|
|
DeleteTallies: false,
|
|
|
|
},
|
|
|
|
ReportedRollup: reportedrollup.Config{
|
|
|
|
Interval: defaultInterval,
|
|
|
|
},
|
|
|
|
ProjectBWCleanup: projectbwcleanup.Config{
|
|
|
|
Interval: defaultInterval,
|
|
|
|
RetainMonths: 1,
|
|
|
|
},
|
|
|
|
LiveAccounting: live.Config{
|
|
|
|
StorageBackend: "redis://" + redis.Addr() + "?db=0",
|
|
|
|
BandwidthCacheTTL: 5 * time.Minute,
|
|
|
|
},
|
|
|
|
Mail: mailservice.Config{
|
|
|
|
SMTPServerAddress: "smtp.mail.test:587",
|
|
|
|
From: "Labs <storj@mail.test>",
|
|
|
|
AuthType: "simulate",
|
|
|
|
TemplatePath: filepath.Join(developmentRoot, "web/satellite/static/emails"),
|
|
|
|
},
|
|
|
|
Console: consoleweb.Config{
|
|
|
|
Address: "127.0.0.1:0",
|
|
|
|
StaticDir: filepath.Join(developmentRoot, "web/satellite"),
|
|
|
|
AuthToken: "very-secret-token",
|
|
|
|
AuthTokenSecret: "my-suppa-secret-key",
|
|
|
|
Config: console.Config{
|
|
|
|
PasswordCost: console.TestPasswordCost,
|
|
|
|
DefaultProjectLimit: 5,
|
2019-10-16 19:08:33 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
RateLimit: web.IPRateLimiterConfig{
|
|
|
|
Duration: 5 * time.Minute,
|
|
|
|
Burst: 3,
|
|
|
|
NumLimits: 10,
|
2020-01-02 20:41:18 +00:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
},
|
|
|
|
Marketing: marketingweb.Config{
|
|
|
|
Address: "127.0.0.1:0",
|
|
|
|
StaticDir: filepath.Join(developmentRoot, "web/marketing"),
|
|
|
|
},
|
|
|
|
Version: planet.NewVersionConfig(),
|
|
|
|
GracefulExit: gracefulexit.Config{
|
|
|
|
Enabled: true,
|
|
|
|
|
|
|
|
ChoreBatchSize: 10,
|
|
|
|
ChoreInterval: defaultInterval,
|
|
|
|
|
|
|
|
EndpointBatchSize: 100,
|
|
|
|
MaxFailuresPerPiece: 5,
|
|
|
|
MaxInactiveTimeFrame: time.Second * 10,
|
|
|
|
OverallMaxFailuresPercentage: 10,
|
|
|
|
RecvTimeout: time.Minute * 1,
|
|
|
|
MaxOrderLimitSendCount: 3,
|
|
|
|
NodeMinAgeInMonths: 0,
|
|
|
|
},
|
|
|
|
Metrics: metrics.Config{
|
|
|
|
ChoreInterval: defaultInterval,
|
|
|
|
},
|
|
|
|
Downtime: downtime.Config{
|
|
|
|
DetectionInterval: defaultInterval,
|
|
|
|
EstimationInterval: defaultInterval,
|
|
|
|
EstimationBatchSize: 5,
|
|
|
|
EstimationConcurrencyLimit: 5,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if planet.ReferralManager != nil {
|
|
|
|
config.Referrals.ReferralManagerURL = storj.NodeURL{
|
|
|
|
ID: planet.ReferralManager.Identity().ID,
|
|
|
|
Address: planet.ReferralManager.Addr().String(),
|
2019-06-21 14:39:43 +01:00
|
|
|
}
|
2020-10-29 11:58:36 +00:00
|
|
|
}
|
|
|
|
if planet.config.Reconfigure.Satellite != nil {
|
|
|
|
planet.config.Reconfigure.Satellite(log, index, &config)
|
|
|
|
}
|
2019-11-21 22:34:49 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
versionInfo := planet.NewVersionInfo()
|
2019-08-19 23:10:38 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
revocationDB, err := revocation.OpenDBFromCfg(ctx, config.Server.Config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Wrap(err)
|
|
|
|
}
|
2019-10-16 17:50:29 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
planet.databases = append(planet.databases, revocationDB)
|
2020-01-17 22:55:53 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
liveAccounting, err := live.NewCache(log.Named("live-accounting"), config.LiveAccounting)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Wrap(err)
|
|
|
|
}
|
|
|
|
planet.databases = append(planet.databases, liveAccounting)
|
2019-06-21 14:39:43 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
rollupsWriteCache := orders.NewRollupsWriteCache(log.Named("orders-write-cache"), db.Orders(), config.Orders.FlushBatchSize)
|
|
|
|
planet.databases = append(planet.databases, rollupsWriteCacheCloser{rollupsWriteCache})
|
2019-08-20 16:04:17 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
peer, err := satellite.New(log, identity, db, pointerDB, revocationDB, liveAccounting, rollupsWriteCache, versionInfo, &config, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-10-29 14:55:57 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
err = db.TestingMigrateToLatest(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-02-07 15:56:59 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
api, err := planet.newAPI(ctx, index, identity, db, pointerDB, config, versionInfo)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-10-29 14:55:57 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
adminPeer, err := planet.newAdmin(ctx, index, identity, db, config, versionInfo)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-03-12 15:40:22 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
repairerPeer, err := planet.newRepairer(ctx, index, identity, db, pointerDB, config, versionInfo)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-09-17 21:14:49 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
gcPeer, err := planet.newGarbageCollection(ctx, index, identity, db, pointerDB, config, versionInfo)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2019-06-21 14:39:43 +01:00
|
|
|
}
|
2020-10-29 11:58:36 +00:00
|
|
|
|
|
|
|
return createNewSystem(prefix, log, config, peer, api, repairerPeer, adminPeer, gcPeer), nil
|
2019-06-21 14:39:43 +01:00
|
|
|
}
|
2019-10-14 21:01:53 +01:00
|
|
|
|
|
|
|
// createNewSystem makes a new Satellite System and exposes the same interface from
|
|
|
|
// before we split out the API. In the short term this will help keep all the tests passing
|
|
|
|
// without much modification needed. However long term, we probably want to rework this
|
|
|
|
// so it represents how the satellite will run when it is made up of many prrocesses.
|
2020-10-29 11:58:36 +00:00
|
|
|
func createNewSystem(name string, log *zap.Logger, config satellite.Config, peer *satellite.Core, api *satellite.API, repairerPeer *satellite.Repairer, adminPeer *satellite.Admin, gcPeer *satellite.GarbageCollection) *Satellite {
|
2020-03-27 14:46:40 +00:00
|
|
|
system := &Satellite{
|
2020-10-29 11:58:36 +00:00
|
|
|
Name: name,
|
2020-03-27 14:46:40 +00:00
|
|
|
Config: config,
|
2019-11-04 19:01:02 +00:00
|
|
|
Core: peer,
|
2019-10-29 14:55:57 +00:00
|
|
|
API: api,
|
|
|
|
Repairer: repairerPeer,
|
2020-02-07 15:56:59 +00:00
|
|
|
Admin: adminPeer,
|
2020-03-12 15:40:22 +00:00
|
|
|
GC: gcPeer,
|
2019-10-14 21:01:53 +01:00
|
|
|
}
|
|
|
|
system.Log = log
|
|
|
|
system.Identity = peer.Identity
|
|
|
|
system.DB = api.DB
|
|
|
|
|
|
|
|
system.Dialer = api.Dialer
|
|
|
|
|
|
|
|
system.Contact.Service = api.Contact.Service
|
|
|
|
system.Contact.Endpoint = api.Contact.Endpoint
|
|
|
|
|
|
|
|
system.Overlay.DB = api.Overlay.DB
|
|
|
|
system.Overlay.Service = api.Overlay.Service
|
|
|
|
system.Overlay.Inspector = api.Overlay.Inspector
|
|
|
|
|
|
|
|
system.Metainfo.Database = api.Metainfo.Database
|
|
|
|
system.Metainfo.Service = peer.Metainfo.Service
|
|
|
|
system.Metainfo.Endpoint2 = api.Metainfo.Endpoint2
|
|
|
|
system.Metainfo.Loop = peer.Metainfo.Loop
|
|
|
|
|
|
|
|
system.Inspector.Endpoint = api.Inspector.Endpoint
|
|
|
|
|
2020-01-10 18:53:42 +00:00
|
|
|
system.Orders.DB = api.Orders.DB
|
2019-10-14 21:01:53 +01:00
|
|
|
system.Orders.Endpoint = api.Orders.Endpoint
|
|
|
|
system.Orders.Service = peer.Orders.Service
|
2020-01-10 18:53:42 +00:00
|
|
|
system.Orders.Chore = api.Orders.Chore
|
2019-10-14 21:01:53 +01:00
|
|
|
|
|
|
|
system.Repair.Checker = peer.Repair.Checker
|
2019-10-29 14:55:57 +00:00
|
|
|
system.Repair.Repairer = repairerPeer.Repairer
|
2019-10-14 21:01:53 +01:00
|
|
|
system.Repair.Inspector = api.Repair.Inspector
|
|
|
|
|
2020-08-20 14:29:02 +01:00
|
|
|
system.Audit.Queues = peer.Audit.Queues
|
2019-10-14 21:01:53 +01:00
|
|
|
system.Audit.Worker = peer.Audit.Worker
|
|
|
|
system.Audit.Chore = peer.Audit.Chore
|
|
|
|
system.Audit.Verifier = peer.Audit.Verifier
|
|
|
|
system.Audit.Reporter = peer.Audit.Reporter
|
|
|
|
|
2020-03-12 15:40:22 +00:00
|
|
|
system.GarbageCollection.Service = gcPeer.GarbageCollection.Service
|
2019-10-14 21:01:53 +01:00
|
|
|
|
2020-04-15 20:20:16 +01:00
|
|
|
system.ExpiredDeletion.Chore = peer.ExpiredDeletion.Chore
|
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
system.DBCleanup.Chore = peer.DBCleanup.Chore
|
|
|
|
|
|
|
|
system.Accounting.Tally = peer.Accounting.Tally
|
|
|
|
system.Accounting.Rollup = peer.Accounting.Rollup
|
2020-09-09 20:20:44 +01:00
|
|
|
system.Accounting.ProjectUsage = api.Accounting.ProjectUsage
|
2020-01-15 21:45:17 +00:00
|
|
|
system.Accounting.ReportedRollup = peer.Accounting.ReportedRollupChore
|
2020-07-07 15:48:09 +01:00
|
|
|
system.Accounting.ProjectBWCleanup = peer.Accounting.ProjectBWCleanupChore
|
2019-10-14 21:01:53 +01:00
|
|
|
|
2020-01-31 18:28:42 +00:00
|
|
|
system.LiveAccounting = peer.LiveAccounting
|
|
|
|
|
2020-09-09 20:20:44 +01:00
|
|
|
system.ProjectLimits.Cache = api.ProjectLimits.Cache
|
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
system.Marketing.Listener = api.Marketing.Listener
|
|
|
|
system.Marketing.Endpoint = api.Marketing.Endpoint
|
|
|
|
|
|
|
|
system.GracefulExit.Chore = peer.GracefulExit.Chore
|
|
|
|
system.GracefulExit.Endpoint = api.GracefulExit.Endpoint
|
2019-10-16 19:08:33 +01:00
|
|
|
|
|
|
|
system.Metrics.Chore = peer.Metrics.Chore
|
|
|
|
|
2020-01-02 20:41:18 +00:00
|
|
|
system.DowntimeTracking.DetectionChore = peer.DowntimeTracking.DetectionChore
|
2020-01-07 21:34:48 +00:00
|
|
|
system.DowntimeTracking.EstimationChore = peer.DowntimeTracking.EstimationChore
|
2019-12-30 19:42:10 +00:00
|
|
|
system.DowntimeTracking.Service = peer.DowntimeTracking.Service
|
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
return system
|
|
|
|
}
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
func (planet *Planet) newAPI(ctx context.Context, index int, identity *identity.FullIdentity, db satellite.DB, pointerDB metainfo.PointerDB, config satellite.Config, versionInfo version.Info) (*satellite.API, error) {
|
|
|
|
prefix := "satellite-api" + strconv.Itoa(index)
|
2019-10-14 21:01:53 +01:00
|
|
|
log := planet.log.Named(prefix)
|
|
|
|
var err error
|
|
|
|
|
2020-10-28 14:01:41 +00:00
|
|
|
revocationDB, err := revocation.OpenDBFromCfg(ctx, config.Server.Config)
|
2019-10-14 21:01:53 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Wrap(err)
|
|
|
|
}
|
|
|
|
planet.databases = append(planet.databases, revocationDB)
|
|
|
|
|
2019-10-16 17:50:29 +01:00
|
|
|
liveAccounting, err := live.NewCache(log.Named("live-accounting"), config.LiveAccounting)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Wrap(err)
|
|
|
|
}
|
|
|
|
planet.databases = append(planet.databases, liveAccounting)
|
|
|
|
|
2020-01-17 22:55:53 +00:00
|
|
|
rollupsWriteCache := orders.NewRollupsWriteCache(log.Named("orders-write-cache"), db.Orders(), config.Orders.FlushBatchSize)
|
|
|
|
planet.databases = append(planet.databases, rollupsWriteCacheCloser{rollupsWriteCache})
|
|
|
|
|
2020-05-12 20:10:32 +01:00
|
|
|
return satellite.NewAPI(log, identity, db, pointerDB, revocationDB, liveAccounting, rollupsWriteCache, &config, versionInfo, nil)
|
2019-10-14 21:01:53 +01:00
|
|
|
}
|
2019-10-29 14:55:57 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
func (planet *Planet) newAdmin(ctx context.Context, index int, identity *identity.FullIdentity, db satellite.DB, config satellite.Config, versionInfo version.Info) (*satellite.Admin, error) {
|
|
|
|
prefix := "satellite-admin" + strconv.Itoa(index)
|
2020-02-07 15:56:59 +00:00
|
|
|
log := planet.log.Named(prefix)
|
|
|
|
|
2020-07-06 22:33:27 +01:00
|
|
|
return satellite.NewAdmin(log, identity, db, versionInfo, &config, nil)
|
2020-02-07 15:56:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
func (planet *Planet) newRepairer(ctx context.Context, index int, identity *identity.FullIdentity, db satellite.DB, pointerDB metainfo.PointerDB, config satellite.Config, versionInfo version.Info) (*satellite.Repairer, error) {
|
|
|
|
prefix := "satellite-repairer" + strconv.Itoa(index)
|
2019-10-29 14:55:57 +00:00
|
|
|
log := planet.log.Named(prefix)
|
|
|
|
|
2020-10-28 14:01:41 +00:00
|
|
|
revocationDB, err := revocation.OpenDBFromCfg(ctx, config.Server.Config)
|
2019-10-29 14:55:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Wrap(err)
|
|
|
|
}
|
2020-01-23 22:17:23 +00:00
|
|
|
planet.databases = append(planet.databases, revocationDB)
|
2019-10-29 14:55:57 +00:00
|
|
|
|
2020-01-17 22:55:53 +00:00
|
|
|
rollupsWriteCache := orders.NewRollupsWriteCache(log.Named("orders-write-cache"), db.Orders(), config.Orders.FlushBatchSize)
|
|
|
|
planet.databases = append(planet.databases, rollupsWriteCacheCloser{rollupsWriteCache})
|
|
|
|
|
2020-05-12 20:10:32 +01:00
|
|
|
return satellite.NewRepairer(log, identity, pointerDB, revocationDB, db.RepairQueue(), db.Buckets(), db.OverlayCache(), rollupsWriteCache, db.Irreparable(), versionInfo, &config, nil)
|
2020-01-17 22:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type rollupsWriteCacheCloser struct {
|
|
|
|
*orders.RollupsWriteCache
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cache rollupsWriteCacheCloser) Close() error {
|
|
|
|
return cache.RollupsWriteCache.CloseAndFlush(context.TODO())
|
2019-10-29 14:55:57 +00:00
|
|
|
}
|
2020-03-12 15:40:22 +00:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
func (planet *Planet) newGarbageCollection(ctx context.Context, index int, identity *identity.FullIdentity, db satellite.DB, pointerDB metainfo.PointerDB, config satellite.Config, versionInfo version.Info) (*satellite.GarbageCollection, error) {
|
|
|
|
prefix := "satellite-gc" + strconv.Itoa(index)
|
2020-03-12 15:40:22 +00:00
|
|
|
log := planet.log.Named(prefix)
|
|
|
|
|
2020-10-28 14:01:41 +00:00
|
|
|
revocationDB, err := revocation.OpenDBFromCfg(ctx, config.Server.Config)
|
2020-03-12 15:40:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Wrap(err)
|
|
|
|
}
|
|
|
|
planet.databases = append(planet.databases, revocationDB)
|
2020-05-12 20:10:32 +01:00
|
|
|
return satellite.NewGarbageCollection(log, identity, db, pointerDB, revocationDB, versionInfo, &config, nil)
|
2020-03-12 15:40:22 +00:00
|
|
|
}
|
2020-05-26 09:05:43 +01:00
|
|
|
|
|
|
|
// atLeastOne returns 1 if value < 1, or value otherwise.
|
|
|
|
func atLeastOne(value int) int {
|
|
|
|
if value < 1 {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return value
|
|
|
|
}
|