parent
f900167974
commit
0e7f6358fb
@ -5,7 +5,6 @@ package checker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"go.uber.org/zap"
|
||||
@ -15,44 +14,18 @@ import (
|
||||
"storj.io/storj/pkg/node"
|
||||
"storj.io/storj/pkg/pb"
|
||||
"storj.io/storj/pkg/pointerdb"
|
||||
"storj.io/storj/pkg/provider"
|
||||
"storj.io/storj/storage"
|
||||
)
|
||||
|
||||
// Config contains configurable values for checker
|
||||
type Config struct {
|
||||
// QueueAddress string `help:"data repair queue address" default:"redis://localhost:6379?db=5&password=123"`
|
||||
Interval time.Duration `help:"how frequently checker should audit segments" default:"30s"`
|
||||
}
|
||||
|
||||
// Run runs the checker with configured values
|
||||
func (c Config) Run(ctx context.Context, server *provider.Provider) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
zap.S().Info("Checker is starting up")
|
||||
|
||||
ticker := time.NewTicker(c.Interval)
|
||||
defer ticker.Stop()
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
zap.S().Info("Starting segment checker service")
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return server.Run(ctx)
|
||||
// Checker is the interface for the data repair queue
|
||||
type Checker interface {
|
||||
IdentifyInjuredSegments(ctx context.Context) (err error)
|
||||
Run() error
|
||||
Stop() error
|
||||
}
|
||||
|
||||
// Checker contains the information needed to do checks for missing pieces
|
||||
type Checker struct {
|
||||
type checker struct {
|
||||
pointerdb *pointerdb.Server
|
||||
repairQueue *queue.Queue
|
||||
overlay pb.OverlayServer
|
||||
@ -61,8 +34,8 @@ type Checker struct {
|
||||
}
|
||||
|
||||
// NewChecker creates a new instance of checker
|
||||
func NewChecker(pointerdb *pointerdb.Server, repairQueue *queue.Queue, overlay pb.OverlayServer, limit int, logger *zap.Logger) *Checker {
|
||||
return &Checker{
|
||||
func newChecker(pointerdb *pointerdb.Server, repairQueue *queue.Queue, overlay pb.OverlayServer, limit int, logger *zap.Logger) *checker {
|
||||
return &checker{
|
||||
pointerdb: pointerdb,
|
||||
repairQueue: repairQueue,
|
||||
overlay: overlay,
|
||||
@ -72,7 +45,7 @@ func NewChecker(pointerdb *pointerdb.Server, repairQueue *queue.Queue, overlay p
|
||||
}
|
||||
|
||||
// IdentifyInjuredSegments checks for missing pieces off of the pointerdb and overlay cache
|
||||
func (c *Checker) IdentifyInjuredSegments(ctx context.Context) (err error) {
|
||||
func (c *checker) IdentifyInjuredSegments(ctx context.Context) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
c.logger.Debug("entering pointerdb iterate")
|
||||
|
||||
@ -115,7 +88,7 @@ func (c *Checker) IdentifyInjuredSegments(ctx context.Context) (err error) {
|
||||
}
|
||||
|
||||
// returns the indices of offline and online nodes
|
||||
func (c *Checker) offlineNodes(ctx context.Context, nodeIDs []dht.NodeID) (offline []int32, err error) {
|
||||
func (c *checker) offlineNodes(ctx context.Context, nodeIDs []dht.NodeID) (offline []int32, err error) {
|
||||
responses, err := c.overlay.BulkLookup(ctx, nodeIDsToLookupRequests(nodeIDs))
|
||||
if err != nil {
|
||||
return []int32{}, err
|
||||
@ -146,3 +119,13 @@ func lookupResponsesToNodes(responses *pb.LookupResponses) []*pb.Node {
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// Run
|
||||
func (c *checker) Run() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop
|
||||
func (c *checker) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func TestIdentifyInjuredSegments(t *testing.T) {
|
||||
//fill a overlay cache
|
||||
overlayServer := mocks.NewOverlay(nodes)
|
||||
limit := 0
|
||||
checker := NewChecker(pointerdb, repairQueue, overlayServer, limit, logger)
|
||||
checker := newChecker(pointerdb, repairQueue, overlayServer, limit, logger)
|
||||
err := checker.IdentifyInjuredSegments(ctx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@ -128,7 +128,7 @@ func TestOfflineAndOnlineNodes(t *testing.T) {
|
||||
}
|
||||
overlayServer := mocks.NewOverlay(nodes)
|
||||
limit := 0
|
||||
checker := NewChecker(pointerdb, repairQueue, overlayServer, limit, logger)
|
||||
checker := newChecker(pointerdb, repairQueue, overlayServer, limit, logger)
|
||||
offline, err := checker.offlineNodes(ctx, nodeIDs)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedOffline, offline)
|
||||
@ -197,7 +197,7 @@ func BenchmarkIdentifyInjuredSegments(b *testing.B) {
|
||||
limit := 0
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
checker := NewChecker(pointerdb, repairQueue, overlayServer, limit, logger)
|
||||
checker := newChecker(pointerdb, repairQueue, overlayServer, limit, logger)
|
||||
err = checker.IdentifyInjuredSegments(ctx)
|
||||
assert.NoError(b, err)
|
||||
|
||||
|
31
pkg/datarepair/checker/config.go
Normal file
31
pkg/datarepair/checker/config.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package checker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"storj.io/storj/pkg/provider"
|
||||
)
|
||||
|
||||
// Config contains configurable values for repairer
|
||||
type Config struct {
|
||||
QueueAddress string `help:"data repair queue address" default:"redis://localhost:6379?db=5&password=123"`
|
||||
Interval time.Duration `help:"how frequently checker should audit segments" default:"30s"`
|
||||
}
|
||||
|
||||
// Initialize a Checker struct
|
||||
func (c Config) initialize(ctx context.Context) (Checker, error) {
|
||||
return &checker{}, nil
|
||||
}
|
||||
|
||||
// Run runs the checker with configured values
|
||||
func (c Config) Run(ctx context.Context, server *provider.Provider) (err error) {
|
||||
check, err := c.initialize(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return check.Run()
|
||||
}
|
47
pkg/datarepair/repairer/config.go
Normal file
47
pkg/datarepair/repairer/config.go
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package repairer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
q "storj.io/storj/pkg/datarepair/queue"
|
||||
"storj.io/storj/pkg/provider"
|
||||
"storj.io/storj/storage/redis"
|
||||
)
|
||||
|
||||
// Config contains configurable values for repairer
|
||||
type Config struct {
|
||||
QueueAddress string `help:"data repair queue address" default:"redis://localhost:6379?db=5&password=123"`
|
||||
MaxRepair int `help:"maximum segments that can be repaired concurrently" default:"100"`
|
||||
Interval time.Duration `help:"how frequently checker should audit segments" default:"3600s"`
|
||||
}
|
||||
|
||||
// Initialize a repairer struct
|
||||
func (c Config) initialize(ctx context.Context) (Repairer, error) {
|
||||
var r repairer
|
||||
r.ctx, r.cancel = context.WithCancel(ctx)
|
||||
|
||||
client, err := redis.NewClientFrom(c.QueueAddress)
|
||||
if err != nil {
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
r.queue = q.NewQueue(client)
|
||||
|
||||
r.cond.L = &r.mu
|
||||
r.maxRepair = c.MaxRepair
|
||||
r.interval = c.Interval
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
// Run runs the repairer with configured values
|
||||
func (c Config) Run(ctx context.Context, server *provider.Provider) (err error) {
|
||||
r, err := c.initialize(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return r.Run()
|
||||
}
|
@ -11,9 +11,7 @@ import (
|
||||
|
||||
q "storj.io/storj/pkg/datarepair/queue"
|
||||
"storj.io/storj/pkg/pb"
|
||||
"storj.io/storj/pkg/provider"
|
||||
"storj.io/storj/pkg/utils"
|
||||
"storj.io/storj/storage/redis"
|
||||
)
|
||||
|
||||
// Repairer is the interface for the data repair queue
|
||||
@ -23,40 +21,6 @@ type Repairer interface {
|
||||
Stop() error
|
||||
}
|
||||
|
||||
// Config contains configurable values for repairer
|
||||
type Config struct {
|
||||
QueueAddress string `help:"data repair queue address" default:"redis://localhost:6379?db=5&password=123"`
|
||||
MaxRepair int `help:"maximum segments that can be repaired concurrently" default:"100"`
|
||||
Interval time.Duration `help:"how frequently checker should audit segments" default:"3600s"`
|
||||
}
|
||||
|
||||
// Initialize a repairer struct
|
||||
func (c Config) initialize(ctx context.Context) (Repairer, error) {
|
||||
var r repairer
|
||||
r.ctx, r.cancel = context.WithCancel(ctx)
|
||||
|
||||
client, err := redis.NewClientFrom(c.QueueAddress)
|
||||
if err != nil {
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
r.queue = q.NewQueue(client)
|
||||
|
||||
r.cond.L = &r.mu
|
||||
r.maxRepair = c.MaxRepair
|
||||
r.interval = c.Interval
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
// Run runs the repairer with configured values
|
||||
func (c Config) Run(ctx context.Context, server *provider.Provider) (err error) {
|
||||
r, err := c.initialize(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return r.Run()
|
||||
}
|
||||
|
||||
// repairer holds important values for data repair
|
||||
type repairer struct {
|
||||
ctx context.Context
|
||||
|
Loading…
Reference in New Issue
Block a user