Pull files in random-ish order again

This commit is contained in:
Jakob Borg 2014-08-05 09:46:11 +02:00
parent 5a07f9ddee
commit f6c9642d72

View File

@ -7,6 +7,7 @@ package model
import ( import (
"bytes" "bytes"
"errors" "errors"
"math/rand"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
@ -641,10 +642,17 @@ func (p *puller) queueNeededBlocks(prevVer uint64) (uint64, int) {
} }
queued := 0 queued := 0
files := make([]protocol.FileInfo, 0, indexBatchSize)
for _, f := range p.model.NeedFilesRepo(p.repoCfg.ID) { for _, f := range p.model.NeedFilesRepo(p.repoCfg.ID) {
if _, ok := p.openFiles[f.Name]; ok { if _, ok := p.openFiles[f.Name]; ok {
continue continue
} }
files = append(files, f)
}
perm := rand.Perm(len(files))
for _, idx := range perm {
f := files[idx]
lf := p.model.CurrentRepoFile(p.repoCfg.ID, f.Name) lf := p.model.CurrentRepoFile(p.repoCfg.ID, f.Name)
have, need := scanner.BlockDiff(lf.Blocks, f.Blocks) have, need := scanner.BlockDiff(lf.Blocks, f.Blocks)
if debug { if debug {
@ -657,6 +665,7 @@ func (p *puller) queueNeededBlocks(prevVer uint64) (uint64, int) {
need: need, need: need,
}) })
} }
if debug && queued > 0 { if debug && queued > 0 {
l.Debugf("%q: queued %d items", p.repoCfg.ID, queued) l.Debugf("%q: queued %d items", p.repoCfg.ID, queued)
} }