2018-10-12 18:49:49 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package repairer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2018-11-06 14:52:11 +00:00
|
|
|
"github.com/vivint/infectious"
|
2018-10-31 16:22:35 +00:00
|
|
|
"go.uber.org/zap"
|
2018-11-29 18:39:27 +00:00
|
|
|
|
2018-11-01 14:03:45 +00:00
|
|
|
"storj.io/storj/pkg/datarepair/queue"
|
2018-11-06 14:52:11 +00:00
|
|
|
"storj.io/storj/pkg/eestream"
|
|
|
|
"storj.io/storj/pkg/miniogw"
|
|
|
|
"storj.io/storj/pkg/overlay"
|
2018-12-11 17:30:14 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-11-06 14:52:11 +00:00
|
|
|
"storj.io/storj/pkg/pointerdb/pdbclient"
|
2018-10-12 18:49:49 +01:00
|
|
|
"storj.io/storj/pkg/provider"
|
2018-11-06 14:52:11 +00:00
|
|
|
ecclient "storj.io/storj/pkg/storage/ec"
|
|
|
|
segment "storj.io/storj/pkg/storage/segments"
|
2018-10-12 18:49:49 +01:00
|
|
|
"storj.io/storj/storage/redis"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config contains configurable values for repairer
|
|
|
|
type Config struct {
|
2018-10-30 19:16:40 +00:00
|
|
|
QueueAddress string `help:"data repair queue address" default:"redis://127.0.0.1:6378?db=1&password=abc123"`
|
2018-10-12 18:49:49 +01:00
|
|
|
MaxRepair int `help:"maximum segments that can be repaired concurrently" default:"100"`
|
|
|
|
Interval time.Duration `help:"how frequently checker should audit segments" default:"3600s"`
|
2018-12-11 17:30:14 +00:00
|
|
|
miniogw.NodeSelectionConfig
|
2018-11-06 14:52:11 +00:00
|
|
|
miniogw.ClientConfig
|
|
|
|
miniogw.RSConfig
|
2018-10-12 18:49:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run runs the repairer with configured values
|
|
|
|
func (c Config) Run(ctx context.Context, server *provider.Provider) (err error) {
|
2018-11-08 13:53:27 +00:00
|
|
|
redisQ, err := redis.NewQueueFrom(c.QueueAddress)
|
2018-10-12 18:49:49 +01:00
|
|
|
if err != nil {
|
2018-10-24 13:35:59 +01:00
|
|
|
return Error.Wrap(err)
|
2018-10-12 18:49:49 +01:00
|
|
|
}
|
|
|
|
|
2018-11-08 13:53:27 +00:00
|
|
|
queue := queue.NewQueue(redisQ)
|
2018-11-06 14:52:11 +00:00
|
|
|
|
|
|
|
ss, err := c.getSegmentStore(ctx, server.Identity())
|
|
|
|
if err != nil {
|
|
|
|
return Error.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
repairer := newRepairer(queue, ss, c.Interval, c.MaxRepair)
|
2018-10-31 16:22:35 +00:00
|
|
|
|
2018-11-08 16:18:28 +00:00
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
|
|
|
2018-10-31 16:22:35 +00:00
|
|
|
// TODO(coyle): we need to figure out how to propagate the error up to cancel the service
|
|
|
|
go func() {
|
|
|
|
if err := repairer.Run(ctx); err != nil {
|
2018-11-08 16:18:28 +00:00
|
|
|
defer cancel()
|
2018-10-31 16:22:35 +00:00
|
|
|
zap.L().Error("Error running repairer", zap.Error(err))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return server.Run(ctx)
|
2018-10-12 18:49:49 +01:00
|
|
|
}
|
2018-11-06 14:52:11 +00:00
|
|
|
|
|
|
|
// getSegmentStore creates a new segment store from storeConfig values
|
|
|
|
func (c Config) getSegmentStore(ctx context.Context, identity *provider.FullIdentity) (ss segment.Store, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
var oc overlay.Client
|
|
|
|
oc, err = overlay.NewOverlayClient(identity, c.OverlayAddr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
pdb, err := pdbclient.NewClient(identity, c.PointerDBAddr, c.APIKey)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-11-06 17:49:17 +00:00
|
|
|
ec := ecclient.NewClient(identity, c.MaxBufferMem)
|
2018-11-06 14:52:11 +00:00
|
|
|
fc, err := infectious.NewFEC(c.MinThreshold, c.MaxThreshold)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
rs, err := eestream.NewRedundancyStrategy(eestream.NewRSScheme(fc, c.ErasureShareSize), c.RepairThreshold, c.SuccessThreshold)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-12-11 17:30:14 +00:00
|
|
|
ns := &pb.NodeStats{
|
|
|
|
UptimeRatio: c.UptimeRatio,
|
|
|
|
AuditSuccessRatio: c.AuditSuccessRatio,
|
|
|
|
UptimeCount: c.UptimeCount,
|
|
|
|
AuditCount: c.AuditCount,
|
|
|
|
}
|
|
|
|
|
|
|
|
return segment.NewSegmentStore(oc, ec, pdb, rs, c.MaxInlineSize, ns), nil
|
2018-11-06 14:52:11 +00:00
|
|
|
}
|