Skip to content

Commit 847b832

Browse files
author
Christopher Schinnerl
authored
Merge pull request #57 from SkynetLabs/ivo/no_sleep
Remove sleep between pins.
2 parents af1e2c8 + eededa9 commit 847b832

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

workers/scanner.go

+14-23
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@ var (
5959
// servers, ordered by how much data they are pinning, below which a server
6060
// will pin underpinned skylinks.
6161
PinningRangeThresholdPercent = 0.30
62-
// SleepBetweenPins defines how long we'll sleep between pinning files.
63-
// We want to add this sleep in order to prevent a single server from
64-
// grabbing all underpinned files and overloading itself. We also want to
65-
// allow for some time for the newly pinned files to reach full redundancy
66-
// before we pin more files.
67-
SleepBetweenPins = build.Select(
68-
build.Var{
69-
Standard: 10 * time.Second,
70-
Dev: time.Second,
71-
Testing: time.Millisecond,
72-
}).(time.Duration)
7362
// SleepBetweenHealthChecks defines the wait time between calls to skyd to
7463
// check the current health of a given file.
7564
SleepBetweenHealthChecks = build.Select(
@@ -79,14 +68,20 @@ var (
7968
Testing: time.Millisecond,
8069
}).(time.Duration)
8170

71+
// minDeadline defines the minimum time we're going to wait for a skylink to
72+
// reach full health before timing out.
73+
minDeadline = build.Select(build.Var{
74+
Standard: 30 * time.Second,
75+
Dev: time.Second,
76+
Testing: time.Millisecond,
77+
}).(time.Duration)
8278
// printPinningStatisticsPeriod defines how often we print intermediate
8379
// statistics while pinning underpinned files.
8480
printPinningStatisticsPeriod = build.Select(build.Var{
8581
Standard: 10 * time.Minute,
8682
Dev: 10 * time.Second,
8783
Testing: 500 * time.Millisecond,
8884
}).(time.Duration)
89-
9085
// sleepBetweenScans defines how often we'll scan the DB for underpinned
9186
// skylinks.
9287
// Needs to be at least twice as long as conf.SleepBetweenChecksForScan.
@@ -399,15 +394,6 @@ func (s *Scanner) managedPinUnderpinnedSkylinks() {
399394
s.staticWaitUntilHealthy(skylink, sp)
400395
continue
401396
}
402-
// In case of error we still want to sleep for a moment in order to
403-
// avoid a tight(ish) loop of errors when we either fail to pin or
404-
// fail to mark as pinned. Note that this only happens when we want
405-
// to continue scanning, otherwise we would have exited right after
406-
// managedFindAndPinOneUnderpinnedSkylink.
407-
stopped := s.staticSleepForOrUntilStopped(SleepBetweenPins)
408-
if stopped {
409-
return
410-
}
411397
}
412398
}
413399

@@ -522,7 +508,8 @@ func (s *Scanner) staticEstimateTimeToFull(skylink skymodules.Skylink) time.Dura
522508
if err != nil {
523509
err = errors.AddContext(err, "failed to get metadata for skylink")
524510
s.staticLogger.Error(err)
525-
return SleepBetweenPins
511+
// No metadata. Return some ballpark value that makes sense.
512+
return SleepBetweenHealthChecks
526513
}
527514
chunkSize := 10 * modules.SectorSizeStandard
528515
numChunks := meta.Length / chunkSize
@@ -657,5 +644,9 @@ func (s *Scanner) staticSleepForOrUntilStopped(dur time.Duration) bool {
657644
// healthy before giving up. It's twice the expected time, as returned by
658645
// staticEstimateTimeToFull.
659646
func (s *Scanner) staticDeadline(skylink skymodules.Skylink) *time.Timer {
660-
return time.NewTimer(2 * s.staticEstimateTimeToFull(skylink))
647+
deadline := 2 * s.staticEstimateTimeToFull(skylink)
648+
if deadline < minDeadline {
649+
deadline = minDeadline
650+
}
651+
return time.NewTimer(deadline)
661652
}

workers/scanner_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func testEstimateTimeToFull(t *testing.T, db *database.DB, cfg conf.Config, skyd
294294
}{
295295
"error": {
296296
err: errors.New("error while fetching metadata"),
297-
expTime: SleepBetweenPins, // 1ms
297+
expTime: SleepBetweenHealthChecks, // 1ms
298298
},
299299
"zero": {
300300
size: 0, // defaults to one chunk

0 commit comments

Comments
 (0)