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"
|
2021-07-13 18:21:16 +01:00
|
|
|
"time"
|
2019-06-21 14:39:43 +01:00
|
|
|
|
2021-07-13 18:21:16 +01:00
|
|
|
"github.com/pquerna/otp/totp"
|
testplanet/satellite: reduce the number of places default values need to be configured
Satellites set their configuration values to default values using
cfgstruct, however, it turns out our tests don't test these values
at all! Instead, they have a completely separate definition system
that is easy to forget about.
As is to be expected, these values have drifted, and it appears
in a few cases test planet is testing unreasonable values that we
won't see in production, or perhaps worse, features enabled in
production were missed and weren't enabled in testplanet.
This change makes it so all values are configured the same,
systematic way, so it's easy to see when test values are different
than dev values or release values, and it's less hard to forget
to enable features in testplanet.
In terms of reviewing, this change should be actually fairly
easy to review, considering private/testplanet/satellite.go keeps
the current config system and the new one and confirms that they
result in identical configurations, so you can be certain that
nothing was missed and the config is all correct.
You can also check the config lock to see what actual config
values changed.
Change-Id: I6715d0794887f577e21742afcf56fd2b9d12170e
2021-05-31 22:15:00 +01:00
|
|
|
"github.com/spf13/pflag"
|
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/rpc"
|
|
|
|
"storj.io/common/storj"
|
2020-05-19 11:21:56 +01:00
|
|
|
"storj.io/common/uuid"
|
testplanet/satellite: reduce the number of places default values need to be configured
Satellites set their configuration values to default values using
cfgstruct, however, it turns out our tests don't test these values
at all! Instead, they have a completely separate definition system
that is easy to forget about.
As is to be expected, these values have drifted, and it appears
in a few cases test planet is testing unreasonable values that we
won't see in production, or perhaps worse, features enabled in
production were missed and weren't enabled in testplanet.
This change makes it so all values are configured the same,
systematic way, so it's easy to see when test values are different
than dev values or release values, and it's less hard to forget
to enable features in testplanet.
In terms of reviewing, this change should be actually fairly
easy to review, considering private/testplanet/satellite.go keeps
the current config system and the new one and confirms that they
result in identical configurations, so you can be certain that
nothing was missed and the config is all correct.
You can also check the config lock to see what actual config
values changed.
Change-Id: I6715d0794887f577e21742afcf56fd2b9d12170e
2021-05-31 22:15:00 +01:00
|
|
|
"storj.io/private/cfgstruct"
|
2020-03-23 19:30:31 +00:00
|
|
|
"storj.io/private/version"
|
2021-04-23 14:13:51 +01:00
|
|
|
"storj.io/storj/private/revocation"
|
|
|
|
"storj.io/storj/private/server"
|
2021-03-09 17:42:10 +00:00
|
|
|
"storj.io/storj/private/testredis"
|
2019-11-14 19:46:15 +00:00
|
|
|
versionchecker "storj.io/storj/private/version/checker"
|
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"
|
2021-06-01 17:44:09 +01:00
|
|
|
"storj.io/storj/satellite/accounting/nodetally"
|
2020-07-07 15:48:09 +01:00
|
|
|
"storj.io/storj/satellite/accounting/projectbwcleanup"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/accounting/rollup"
|
2020-11-30 19:34:42 +00:00
|
|
|
"storj.io/storj/satellite/accounting/rolluparchive"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/accounting/tally"
|
|
|
|
"storj.io/storj/satellite/audit"
|
testplanet/satellite: reduce the number of places default values need to be configured
Satellites set their configuration values to default values using
cfgstruct, however, it turns out our tests don't test these values
at all! Instead, they have a completely separate definition system
that is easy to forget about.
As is to be expected, these values have drifted, and it appears
in a few cases test planet is testing unreasonable values that we
won't see in production, or perhaps worse, features enabled in
production were missed and weren't enabled in testplanet.
This change makes it so all values are configured the same,
systematic way, so it's easy to see when test values are different
than dev values or release values, and it's less hard to forget
to enable features in testplanet.
In terms of reviewing, this change should be actually fairly
easy to review, considering private/testplanet/satellite.go keeps
the current config system and the new one and confirms that they
result in identical configurations, so you can be certain that
nothing was missed and the config is all correct.
You can also check the config lock to see what actual config
values changed.
Change-Id: I6715d0794887f577e21742afcf56fd2b9d12170e
2021-05-31 22:15:00 +01:00
|
|
|
"storj.io/storj/satellite/compensation"
|
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-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"
|
2021-05-13 09:14:18 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2021-05-28 10:42:55 +01:00
|
|
|
"storj.io/storj/satellite/metabase/segmentloop"
|
2021-05-06 12:54:10 +01:00
|
|
|
"storj.io/storj/satellite/metabase/zombiedeletion"
|
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"
|
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-12-31 18:43:13 +00:00
|
|
|
"storj.io/storj/satellite/overlay/straynodes"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/repair/checker"
|
|
|
|
"storj.io/storj/satellite/repair/repairer"
|
2021-06-23 00:09:39 +01:00
|
|
|
"storj.io/storj/satellite/reputation"
|
2020-03-27 16:18:19 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
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 {
|
2020-12-31 18:43:13 +00:00
|
|
|
DB overlay.DB
|
|
|
|
Service *overlay.Service
|
|
|
|
DQStrayNodes *straynodes.Chore
|
2019-10-14 21:01:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Metainfo struct {
|
2021-09-07 09:15:47 +01:00
|
|
|
// TODO remove when uplink will be adjusted to use Metabase.DB
|
|
|
|
Metabase *metabase.DB
|
|
|
|
Endpoint *metainfo.Endpoint
|
|
|
|
// TODO remove when uplink will be adjusted to use Metabase.SegmentLoop
|
|
|
|
SegmentLoop *segmentloop.Service
|
|
|
|
}
|
|
|
|
|
|
|
|
Metabase struct {
|
|
|
|
DB *metabase.DB
|
2021-05-28 10:42:55 +01:00
|
|
|
SegmentLoop *segmentloop.Service
|
2019-10-14 21:01:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2021-06-15 22:45:31 +01:00
|
|
|
Checker *checker.Checker
|
|
|
|
Repairer *repairer.Service
|
2019-10-14 21:01:53 +01:00
|
|
|
}
|
2020-12-31 18:43:13 +00:00
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
Reputation struct {
|
|
|
|
Service *reputation.Service
|
|
|
|
}
|
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
GarbageCollection struct {
|
|
|
|
Service *gc.Service
|
|
|
|
}
|
|
|
|
|
2020-04-15 20:20:16 +01:00
|
|
|
ExpiredDeletion struct {
|
|
|
|
Chore *expireddeletion.Chore
|
|
|
|
}
|
|
|
|
|
2021-05-06 12:54:10 +01:00
|
|
|
ZombieDeletion struct {
|
|
|
|
Chore *zombiedeletion.Chore
|
|
|
|
}
|
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
Accounting struct {
|
2020-07-07 15:48:09 +01:00
|
|
|
Tally *tally.Service
|
2021-06-01 17:44:09 +01:00
|
|
|
NodeTally *nodetally.Service
|
2020-07-07 15:48:09 +01:00
|
|
|
Rollup *rollup.Service
|
|
|
|
ProjectUsage *accounting.Service
|
|
|
|
ProjectBWCleanup *projectbwcleanup.Chore
|
2020-11-30 19:34:42 +00:00
|
|
|
RollupArchive *rolluparchive.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
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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() }
|
|
|
|
|
2021-06-09 12:39:38 +01:00
|
|
|
// ConsoleURL returns the console URL.
|
|
|
|
func (system *Satellite) ConsoleURL() string {
|
|
|
|
return "http://" + system.API.Console.Listener.Addr().String()
|
|
|
|
}
|
|
|
|
|
2020-04-16 13:12:46 +01:00
|
|
|
// 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
|
2021-02-04 18:16:49 +00:00
|
|
|
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
|
2021-07-13 18:21:16 +01:00
|
|
|
request := console.AuthUser{Email: user.Email, Password: user.FullName}
|
|
|
|
if user.MFAEnabled {
|
|
|
|
code, err := totp.GenerateCode(user.MFASecretKey, time.Now())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
request.MFAPasscode = code
|
|
|
|
}
|
|
|
|
token, err := system.API.Console.Service.Token(ctx, request)
|
2020-05-19 11:21:56 +01:00
|
|
|
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 16:54:35 +00:00
|
|
|
metabaseDB, err := satellitedbtest.CreateMetabaseDB(context.TODO(), log.Named("metabase"), planet.config.Name, "M", index, databases.MetabaseDB)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if planet.config.Reconfigure.SatelliteMetabaseDB != nil {
|
2021-05-13 09:14:18 +01:00
|
|
|
var newMetabaseDB *metabase.DB
|
2020-10-29 16:54:35 +00:00
|
|
|
newMetabaseDB, err = planet.config.Reconfigure.SatelliteMetabaseDB(log.Named("metabase"), index, metabaseDB)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, metabaseDB.Close())
|
|
|
|
}
|
|
|
|
metabaseDB = newMetabaseDB
|
|
|
|
}
|
|
|
|
planet.databases = append(planet.databases, metabaseDB)
|
|
|
|
|
2021-03-09 17:42:10 +00:00
|
|
|
redis, err := testredis.Mini(ctx)
|
2020-10-29 11:58:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-11-18 21:39:13 +00:00
|
|
|
encryptionKeys, err := orders.NewEncryptionKeys(orders.EncryptionKey{
|
|
|
|
ID: orders.EncryptionKeyID{1},
|
|
|
|
Key: storj.Key{1},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-10-29 11:58:36 +00:00
|
|
|
|
testplanet/satellite: reduce the number of places default values need to be configured
Satellites set their configuration values to default values using
cfgstruct, however, it turns out our tests don't test these values
at all! Instead, they have a completely separate definition system
that is easy to forget about.
As is to be expected, these values have drifted, and it appears
in a few cases test planet is testing unreasonable values that we
won't see in production, or perhaps worse, features enabled in
production were missed and weren't enabled in testplanet.
This change makes it so all values are configured the same,
systematic way, so it's easy to see when test values are different
than dev values or release values, and it's less hard to forget
to enable features in testplanet.
In terms of reviewing, this change should be actually fairly
easy to review, considering private/testplanet/satellite.go keeps
the current config system and the new one and confirms that they
result in identical configurations, so you can be certain that
nothing was missed and the config is all correct.
You can also check the config lock to see what actual config
values changed.
Change-Id: I6715d0794887f577e21742afcf56fd2b9d12170e
2021-05-31 22:15:00 +01:00
|
|
|
var config satellite.Config
|
|
|
|
cfgstruct.Bind(pflag.NewFlagSet("", pflag.PanicOnError), &config,
|
|
|
|
cfgstruct.UseTestDefaults(),
|
|
|
|
cfgstruct.ConfDir(storageDir),
|
|
|
|
cfgstruct.IdentityDir(storageDir),
|
|
|
|
cfgstruct.ConfigVar("TESTINTERVAL", defaultInterval.String()))
|
|
|
|
|
|
|
|
// TODO: these are almost certainly mistakenly set to the zero value
|
|
|
|
// in tests due to a prior mismatch between testplanet config and
|
|
|
|
// cfgstruct devDefaults. we need to make sure it's safe to remove
|
|
|
|
// these lines and then remove them.
|
|
|
|
config.Debug.Control = false
|
2021-07-14 00:30:06 +01:00
|
|
|
config.Reputation.AuditHistory.OfflineDQEnabled = false
|
testplanet/satellite: reduce the number of places default values need to be configured
Satellites set their configuration values to default values using
cfgstruct, however, it turns out our tests don't test these values
at all! Instead, they have a completely separate definition system
that is easy to forget about.
As is to be expected, these values have drifted, and it appears
in a few cases test planet is testing unreasonable values that we
won't see in production, or perhaps worse, features enabled in
production were missed and weren't enabled in testplanet.
This change makes it so all values are configured the same,
systematic way, so it's easy to see when test values are different
than dev values or release values, and it's less hard to forget
to enable features in testplanet.
In terms of reviewing, this change should be actually fairly
easy to review, considering private/testplanet/satellite.go keeps
the current config system and the new one and confirms that they
result in identical configurations, so you can be certain that
nothing was missed and the config is all correct.
You can also check the config lock to see what actual config
values changed.
Change-Id: I6715d0794887f577e21742afcf56fd2b9d12170e
2021-05-31 22:15:00 +01:00
|
|
|
config.Server.Config.Extensions.Revocation = false
|
|
|
|
config.Orders.OrdersSemaphoreSize = 0
|
|
|
|
config.Checker.NodeFailureRate = 0
|
|
|
|
config.Audit.MaxRetriesStatDB = 0
|
|
|
|
config.GarbageCollection.RetainSendTimeout = 0
|
|
|
|
config.ExpiredDeletion.ListLimit = 0
|
|
|
|
config.Tally.SaveRollupBatchSize = 0
|
|
|
|
config.Tally.ReadRollupBatchSize = 0
|
|
|
|
config.Rollup.DeleteTallies = false
|
|
|
|
config.Payments.BonusRate = 0
|
|
|
|
config.Payments.MinCoinPayment = 0
|
|
|
|
config.Payments.NodeEgressBandwidthPrice = 0
|
|
|
|
config.Payments.NodeRepairBandwidthPrice = 0
|
|
|
|
config.Payments.NodeAuditBandwidthPrice = 0
|
|
|
|
config.Payments.NodeDiskSpacePrice = 0
|
|
|
|
config.Identity.CertPath = ""
|
|
|
|
config.Identity.KeyPath = ""
|
|
|
|
config.Metainfo.DatabaseURL = ""
|
|
|
|
config.Console.ContactInfoURL = ""
|
|
|
|
config.Console.FrameAncestors = ""
|
|
|
|
config.Console.LetUsKnowURL = ""
|
|
|
|
config.Console.SEO = ""
|
|
|
|
config.Console.SatelliteName = ""
|
|
|
|
config.Console.SatelliteOperator = ""
|
|
|
|
config.Console.TermsAndConditionsURL = ""
|
|
|
|
config.Console.PartneredSatellites = ""
|
|
|
|
config.Console.GeneralRequestURL = ""
|
|
|
|
config.Console.ProjectLimitsIncreaseRequestURL = ""
|
|
|
|
config.Console.GatewayCredentialsRequestURL = ""
|
|
|
|
config.Console.DocumentationURL = ""
|
|
|
|
config.Console.LinksharingURL = ""
|
|
|
|
config.Console.PathwayOverviewEnabled = false
|
|
|
|
config.Compensation.Rates.AtRestGBHours = compensation.Rate{}
|
|
|
|
config.Compensation.Rates.GetTB = compensation.Rate{}
|
|
|
|
config.Compensation.Rates.GetRepairTB = compensation.Rate{}
|
|
|
|
config.Compensation.Rates.GetAuditTB = compensation.Rate{}
|
|
|
|
config.Compensation.WithheldPercents = nil
|
|
|
|
config.Compensation.DisposePercent = 0
|
|
|
|
config.ProjectLimit.CacheCapacity = 0
|
|
|
|
config.ProjectLimit.CacheExpiration = 0
|
|
|
|
config.Metainfo.SegmentLoop.ListLimit = 0
|
|
|
|
|
|
|
|
// Actual testplanet-specific configuration
|
|
|
|
config.Server.Address = "127.0.0.1:0"
|
|
|
|
config.Server.PrivateAddress = "127.0.0.1:0"
|
|
|
|
config.Admin.Address = "127.0.0.1:0"
|
|
|
|
config.Console.Address = "127.0.0.1:0"
|
|
|
|
config.Server.Config.PeerCAWhitelistPath = planet.whitelistPath
|
|
|
|
config.Server.Config.UsePeerCAWhitelist = true
|
|
|
|
config.Version = planet.NewVersionConfig()
|
|
|
|
config.Metainfo.RS.Min = atLeastOne(planet.config.StorageNodeCount * 1 / 5)
|
|
|
|
config.Metainfo.RS.Repair = atLeastOne(planet.config.StorageNodeCount * 2 / 5)
|
|
|
|
config.Metainfo.RS.Success = atLeastOne(planet.config.StorageNodeCount * 3 / 5)
|
|
|
|
config.Metainfo.RS.Total = atLeastOne(planet.config.StorageNodeCount * 4 / 5)
|
|
|
|
config.Orders.EncryptionKeys = *encryptionKeys
|
|
|
|
config.LiveAccounting.StorageBackend = "redis://" + redis.Addr() + "?db=0"
|
|
|
|
config.Mail.TemplatePath = filepath.Join(developmentRoot, "web/satellite/static/emails")
|
|
|
|
config.Console.StaticDir = filepath.Join(developmentRoot, "web/satellite")
|
|
|
|
|
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
|
|
|
|
2021-03-24 19:22:50 +00:00
|
|
|
liveAccounting, err := live.OpenCache(ctx, log.Named("live-accounting"), config.LiveAccounting)
|
2020-10-29 11:58:36 +00:00
|
|
|
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-12-22 10:38:32 +00:00
|
|
|
peer, err := satellite.New(log, identity, db, metabaseDB, revocationDB, liveAccounting, rollupsWriteCache, versionInfo, &config, nil)
|
2020-10-29 11:58:36 +00:00
|
|
|
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
|
|
|
|
2021-02-11 11:58:22 +00:00
|
|
|
err = metabaseDB.MigrateToLatest(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-12-22 10:38:32 +00:00
|
|
|
api, err := planet.newAPI(ctx, index, identity, db, metabaseDB, config, versionInfo)
|
2020-10-29 11:58:36 +00:00
|
|
|
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-12-22 10:38:32 +00:00
|
|
|
repairerPeer, err := planet.newRepairer(ctx, index, identity, db, metabaseDB, config, versionInfo)
|
2020-10-29 11:58:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-09-17 21:14:49 +01:00
|
|
|
|
2020-12-22 10:38:32 +00:00
|
|
|
gcPeer, err := planet.newGarbageCollection(ctx, index, identity, db, metabaseDB, config, versionInfo)
|
2020-10-29 11:58:36 +00:00
|
|
|
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
|
2020-12-31 18:43:13 +00:00
|
|
|
system.Overlay.DQStrayNodes = peer.Overlay.DQStrayNodes
|
2019-10-14 21:01:53 +01:00
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
system.Reputation.Service = peer.Reputation.Service
|
|
|
|
|
2021-09-07 09:15:47 +01:00
|
|
|
// system.Metainfo.Metabase = api.Metainfo.Metabase
|
2021-06-16 17:19:14 +01:00
|
|
|
system.Metainfo.Endpoint = api.Metainfo.Endpoint
|
2021-09-07 09:15:47 +01:00
|
|
|
// system.Metainfo.SegmentLoop = peer.Metainfo.SegmentLoop
|
|
|
|
|
|
|
|
system.Metabase.DB = api.Metainfo.Metabase
|
|
|
|
system.Metabase.SegmentLoop = peer.Metainfo.SegmentLoop
|
2019-10-14 21:01:53 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
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
|
2021-05-06 12:54:10 +01:00
|
|
|
system.ZombieDeletion.Chore = peer.ZombieDeletion.Chore
|
2020-04-15 20:20:16 +01:00
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
system.Accounting.Tally = peer.Accounting.Tally
|
2021-06-01 17:44:09 +01:00
|
|
|
system.Accounting.NodeTally = peer.Accounting.NodeTally
|
2019-10-14 21:01:53 +01:00
|
|
|
system.Accounting.Rollup = peer.Accounting.Rollup
|
2020-09-09 20:20:44 +01:00
|
|
|
system.Accounting.ProjectUsage = api.Accounting.ProjectUsage
|
2020-07-07 15:48:09 +01:00
|
|
|
system.Accounting.ProjectBWCleanup = peer.Accounting.ProjectBWCleanupChore
|
2020-11-30 19:34:42 +00:00
|
|
|
system.Accounting.RollupArchive = peer.Accounting.RollupArchiveChore
|
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.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
|
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
return system
|
|
|
|
}
|
|
|
|
|
2021-05-13 09:14:18 +01:00
|
|
|
func (planet *Planet) newAPI(ctx context.Context, index int, identity *identity.FullIdentity, db satellite.DB, metabaseDB *metabase.DB, config satellite.Config, versionInfo version.Info) (*satellite.API, error) {
|
2020-10-29 11:58:36 +00:00
|
|
|
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)
|
|
|
|
|
2021-03-24 19:22:50 +00:00
|
|
|
liveAccounting, err := live.OpenCache(ctx, log.Named("live-accounting"), config.LiveAccounting)
|
2019-10-16 17:50:29 +01:00
|
|
|
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-12-22 10:38:32 +00:00
|
|
|
return satellite.NewAPI(log, identity, db, metabaseDB, 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
|
|
|
}
|
|
|
|
|
2021-05-13 09:14:18 +01:00
|
|
|
func (planet *Planet) newRepairer(ctx context.Context, index int, identity *identity.FullIdentity, db satellite.DB, metabaseDB *metabase.DB, config satellite.Config, versionInfo version.Info) (*satellite.Repairer, error) {
|
2020-10-29 11:58:36 +00:00
|
|
|
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})
|
|
|
|
|
2021-07-15 15:14:13 +01:00
|
|
|
return satellite.NewRepairer(log, identity, metabaseDB, revocationDB, db.RepairQueue(), db.Buckets(), db.OverlayCache(), db.Reputation(), rollupsWriteCache, 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
|
|
|
|
2021-05-13 09:14:18 +01:00
|
|
|
func (planet *Planet) newGarbageCollection(ctx context.Context, index int, identity *identity.FullIdentity, db satellite.DB, metabaseDB *metabase.DB, config satellite.Config, versionInfo version.Info) (*satellite.GarbageCollection, error) {
|
2020-10-29 11:58:36 +00:00
|
|
|
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-12-22 10:38:32 +00:00
|
|
|
return satellite.NewGarbageCollection(log, identity, db, metabaseDB, 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
|
|
|
|
}
|