2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-10-12 18:49:49 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package repairer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2019-01-14 21:19:15 +00:00
|
|
|
"storj.io/storj/internal/memory"
|
2018-11-06 14:52:11 +00:00
|
|
|
"storj.io/storj/pkg/overlay"
|
|
|
|
"storj.io/storj/pkg/pointerdb/pdbclient"
|
2018-12-20 13:57:54 +00:00
|
|
|
ecclient "storj.io/storj/pkg/storage/ec"
|
2018-12-13 07:12:36 +00:00
|
|
|
"storj.io/storj/pkg/storage/segments"
|
2019-02-11 11:17:32 +00:00
|
|
|
"storj.io/storj/pkg/transport"
|
2018-10-12 18:49:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config contains configurable values for repairer
|
|
|
|
type Config struct {
|
2018-12-11 18:40:54 +00: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"`
|
|
|
|
OverlayAddr string `help:"Address to contact overlay server through"`
|
|
|
|
PointerDBAddr string `help:"Address to contact pointerdb server through"`
|
2019-01-14 21:19:15 +00:00
|
|
|
MaxBufferMem memory.Size `help:"maximum buffer memory (in bytes) to be allocated for read buffers" default:"4M"`
|
2018-12-11 18:40:54 +00:00
|
|
|
APIKey string `help:"repairer-specific pointerdb access credential"`
|
2018-10-12 18:49:49 +01:00
|
|
|
}
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
// GetSegmentRepairer creates a new segment repairer from storeConfig values
|
2019-02-11 11:17:32 +00:00
|
|
|
func (c Config) GetSegmentRepairer(ctx context.Context, tc transport.Client) (ss SegmentRepairer, err error) {
|
2018-11-06 14:52:11 +00:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
var oc overlay.Client
|
2019-02-11 11:17:32 +00:00
|
|
|
oc, err = overlay.NewClientContext(ctx, tc, c.OverlayAddr)
|
2018-11-06 14:52:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-02-11 11:17:32 +00:00
|
|
|
pdb, err := pdbclient.NewClientContext(ctx, tc, c.PointerDBAddr, c.APIKey)
|
2018-11-06 14:52:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-02-11 11:17:32 +00:00
|
|
|
ec := ecclient.NewClient(tc, c.MaxBufferMem.Int())
|
2018-12-17 21:05:05 +00:00
|
|
|
return segments.NewSegmentRepairer(oc, ec, pdb), nil
|
2018-11-06 14:52:11 +00:00
|
|
|
}
|