2018-10-12 18:49:49 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package checker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2018-10-30 19:16:40 +00:00
|
|
|
"go.uber.org/zap"
|
2018-11-20 15:54:22 +00:00
|
|
|
|
2018-10-30 19:16:40 +00:00
|
|
|
"storj.io/storj/pkg/datarepair/queue"
|
|
|
|
"storj.io/storj/pkg/overlay"
|
2018-11-20 15:54:22 +00:00
|
|
|
mock "storj.io/storj/pkg/overlay/mocks"
|
|
|
|
"storj.io/storj/pkg/pb"
|
2018-10-30 19:16:40 +00:00
|
|
|
"storj.io/storj/pkg/pointerdb"
|
2018-10-12 18:49:49 +01:00
|
|
|
"storj.io/storj/pkg/provider"
|
2018-10-30 19:16:40 +00:00
|
|
|
"storj.io/storj/storage/redis"
|
2018-10-12 18:49:49 +01:00
|
|
|
)
|
|
|
|
|
2018-11-08 16:18:28 +00:00
|
|
|
// Config contains configurable values for checker
|
2018-10-12 18:49:49 +01:00
|
|
|
type Config struct {
|
2018-10-30 19:16:40 +00:00
|
|
|
QueueAddress string `help:"data checker queue address" default:"redis://127.0.0.1:6378?db=1&password=abc123"`
|
2018-10-12 18:49:49 +01:00
|
|
|
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) {
|
2018-11-20 15:54:22 +00:00
|
|
|
pdb := pointerdb.LoadFromContext(ctx)
|
|
|
|
var o pb.OverlayServer
|
|
|
|
x := overlay.LoadServerFromContext(ctx)
|
|
|
|
if x == nil {
|
|
|
|
o = mock.LoadServerFromContext(ctx)
|
|
|
|
} else {
|
|
|
|
o = x
|
|
|
|
}
|
2018-11-08 13:53:27 +00:00
|
|
|
redisQ, err := redis.NewQueueFrom(c.QueueAddress)
|
2018-10-30 19:16:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, Error.Wrap(err)
|
|
|
|
}
|
2018-11-08 13:53:27 +00:00
|
|
|
repairQueue := queue.NewQueue(redisQ)
|
2018-11-20 15:54:22 +00:00
|
|
|
return newChecker(pdb, repairQueue, o, 0, zap.L(), c.Interval), nil
|
2018-10-12 18:49:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2018-11-08 16:18:28 +00:00
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
2018-10-31 16:22:35 +00:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
if err := check.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 checker", zap.Error(err))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return server.Run(ctx)
|
2018-10-12 18:49:49 +01:00
|
|
|
}
|