remove random sleep in storagenode contact (#3243)

This commit is contained in:
Cameron 2019-10-11 16:44:18 -04:00 committed by Jennifer Li Johnson
parent a5d1776539
commit d17be58237
4 changed files with 4 additions and 27 deletions

View File

@ -121,7 +121,6 @@ func (planet *Planet) newStorageNodes(count int, whitelistedSatellites storj.Nod
},
Contact: contact.Config{
Interval: defaultInterval,
MaxSleep: 0 * time.Second,
},
}
if planet.config.Reconfigure.StorageNode != nil {

View File

@ -5,7 +5,6 @@ package contact
import (
"context"
"math/rand"
"time"
"github.com/zeebo/errs"
@ -28,12 +27,11 @@ type Chore struct {
trust *trust.Pool
maxSleep time.Duration
Loop *sync2.Cycle
Loop *sync2.Cycle
}
// NewChore creates a new contact chore
func NewChore(log *zap.Logger, interval time.Duration, maxSleep time.Duration, trust *trust.Pool, dialer rpc.Dialer, service *Service) *Chore {
func NewChore(log *zap.Logger, interval time.Duration, trust *trust.Pool, dialer rpc.Dialer, service *Service) *Chore {
return &Chore{
log: log,
service: service,
@ -41,8 +39,7 @@ func NewChore(log *zap.Logger, interval time.Duration, maxSleep time.Duration, t
trust: trust,
maxSleep: maxSleep,
Loop: sync2.NewCycle(interval),
Loop: sync2.NewCycle(interval),
}
}
@ -52,9 +49,6 @@ func (chore *Chore) Run(ctx context.Context) (err error) {
chore.log.Info("Storagenode contact chore starting up")
return chore.Loop.Run(ctx, func(ctx context.Context) error {
if err := chore.randomDurationSleep(ctx); err != nil {
return err
}
if err := chore.pingSatellites(ctx); err != nil {
chore.log.Error("pingSatellites failed", zap.Error(err))
}
@ -95,20 +89,6 @@ func (chore *Chore) pingSatellites(ctx context.Context) (err error) {
return group.Wait()
}
// randomDurationSleep sleeps for random interval in [0;maxSleep)
// returns error if context was cancelled
func (chore *Chore) randomDurationSleep(ctx context.Context) error {
if chore.maxSleep <= 0 {
return nil
}
jitter := time.Duration(rand.Int63n(int64(chore.maxSleep)))
if !sync2.Sleep(ctx, jitter) {
return ctx.Err()
}
return nil
}
// Close stops the contact chore
func (chore *Chore) Close() error {
chore.Loop.Close()

View File

@ -26,8 +26,6 @@ type Config struct {
// Chore config values
Interval time.Duration `help:"how frequently the node contact chore should run" releaseDefault:"1h" devDefault:"30s"`
// MaxSleep should remain at default value to decrease traffic congestion to satellite
MaxSleep time.Duration `help:"maximum duration to wait before pinging satellites" releaseDefault:"45m" devDefault:"0s" hidden:"true"`
}
// Service is the contact service between storage nodes and satellites

View File

@ -230,7 +230,7 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, revocationDB exten
}
peer.Contact.PingStats = new(contact.PingStats)
peer.Contact.Service = contact.NewService(peer.Log.Named("contact:service"), self)
peer.Contact.Chore = contact.NewChore(peer.Log.Named("contact:chore"), config.Contact.Interval, config.Contact.MaxSleep, peer.Storage2.Trust, peer.Dialer, peer.Contact.Service)
peer.Contact.Chore = contact.NewChore(peer.Log.Named("contact:chore"), config.Contact.Interval, peer.Storage2.Trust, peer.Dialer, peer.Contact.Service)
peer.Contact.Endpoint = contact.NewEndpoint(peer.Log.Named("contact:endpoint"), peer.Contact.PingStats)
peer.Contact.KEndpoint = contact.NewKademliaEndpoint(peer.Log.Named("contact:nodes_service_endpoint"), peer.Contact.Service, peer.Storage2.Trust)
pb.RegisterContactServer(peer.Server.GRPC(), peer.Contact.Endpoint)