diff --git a/cmd/captplanet/run.go b/cmd/captplanet/run.go index 9cca8dfc2..6f88d6326 100644 --- a/cmd/captplanet/run.go +++ b/cmd/captplanet/run.go @@ -14,6 +14,7 @@ import ( "storj.io/storj/pkg/kademlia" "storj.io/storj/pkg/miniogw" "storj.io/storj/pkg/overlay" + "storj.io/storj/pkg/datarepair/checker" psserver "storj.io/storj/pkg/piecestore/rpc/server" "storj.io/storj/pkg/pointerdb" "storj.io/storj/pkg/process" @@ -30,6 +31,7 @@ type Satellite struct { Kademlia kademlia.Config PointerDB pointerdb.Config Overlay overlay.Config + Checker checker.Config MockOverlay struct { Enabled bool `default:"true" help:"if false, use real overlay"` Host string `default:"" help:"if set, the mock overlay will return storage nodes with this host"` @@ -106,6 +108,7 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) { errch <- runCfg.Satellite.Identity.Run(ctx, runCfg.Satellite.Kademlia, runCfg.Satellite.PointerDB, + runCfg.Satellite.Checker, o) }() diff --git a/cmd/satellite/main.go b/cmd/satellite/main.go index 0ddb8449f..22573f19d 100644 --- a/cmd/satellite/main.go +++ b/cmd/satellite/main.go @@ -10,9 +10,10 @@ import ( "github.com/spf13/cobra" "storj.io/storj/pkg/cfgstruct" - // "storj.io/storj/pkg/datarepair/checker" + // "storj.io/storj/pkg/datarepair/queue" // "storj.io/storj/pkg/datarepair/repairer" + "storj.io/storj/pkg/datarepair/checker" "storj.io/storj/pkg/kademlia" "storj.io/storj/pkg/overlay" "storj.io/storj/pkg/pointerdb" @@ -40,6 +41,7 @@ var ( Identity provider.IdentityConfig Kademlia kademlia.Config PointerDB pointerdb.Config + Checker checker.Config Overlay overlay.Config MockOverlay overlay.MockConfig // RepairQueue queue.Config @@ -69,7 +71,7 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) { o = runCfg.MockOverlay } return runCfg.Identity.Run(process.Ctx(cmd), - runCfg.Kademlia, o, runCfg.PointerDB) + runCfg.Kademlia, o, runCfg.PointerDB, runCfg.Checker) } func cmdSetup(cmd *cobra.Command, args []string) (err error) { diff --git a/pkg/datarepair/checker/checker.go b/pkg/datarepair/checker/checker.go index f5495c3ea..1ec431757 100644 --- a/pkg/datarepair/checker/checker.go +++ b/pkg/datarepair/checker/checker.go @@ -5,17 +5,48 @@ package checker import ( "context" + "time" + + "github.com/zeebo/errs" + "go.uber.org/zap" + monkit "gopkg.in/spacemonkeygo/monkit.v2" + + "storj.io/storj/pkg/provider" +) + +var ( + mon = monkit.Package() + // Error is a standard error class for this package. + Error = errs.Class("checker error") ) // Config contains configurable values for checker type Config struct { - // queueAddress string `help:"data repair queue address" default:"localhost:7777"` + 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) (err error) { +func (c Config) Run(ctx context.Context, server *provider.Provider) (err error) { + defer mon.Task()(&ctx)(&err) - // TODO: start checker server + zap.S().Info("Checker is starting up") - return err + 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) }