Esempio n. 1
0
func (p *puller) queueNeededBlocks(prevVer uint64) (uint64, int) {
	curVer := p.model.LocalVersion(p.repoCfg.ID)
	if curVer == prevVer {
		return curVer, 0
	}

	if debug {
		l.Debugf("%q: checking for more needed blocks", p.repoCfg.ID)
	}

	queued := 0
	files := make([]protocol.FileInfo, 0, indexBatchSize)
	for _, f := range p.model.NeedFilesRepoLimited(p.repoCfg.ID, indexBatchSize, pullIterationBlocks) {
		if _, ok := p.openFiles[f.Name]; ok {
			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)
		have, need := scanner.BlockDiff(lf.Blocks, f.Blocks)
		if debug {
			l.Debugf("need:\n  local: %v\n  global: %v\n  haveBlocks: %v\n  needBlocks: %v", lf, f, have, need)
		}
		queued++
		p.bq.put(bqAdd{
			file: f,
			have: have,
			need: need,
		})
	}

	if debug && queued > 0 {
		l.Debugf("%q: queued %d items", p.repoCfg.ID, queued)
	}

	if queued > 0 {
		return prevVer, queued
	} else {
		return curVer, 0
	}
}
Esempio n. 2
0
func (p *puller) queueNeededBlocks(prevVer uint64) (uint64, int) {
	curVer := p.model.LocalVersion(p.repoCfg.ID)
	if curVer == prevVer {
		return curVer, 0
	}

	if debug {
		l.Debugf("%q: checking for more needed blocks", p.repoCfg.ID)
	}

	queued := 0
	for _, f := range p.model.NeedFilesRepo(p.repoCfg.ID) {
		if _, ok := p.openFiles[f.Name]; ok {
			continue
		}
		lf := p.model.CurrentRepoFile(p.repoCfg.ID, f.Name)
		have, need := scanner.BlockDiff(lf.Blocks, f.Blocks)
		if debug {
			l.Debugf("need:\n  local: %v\n  global: %v\n  haveBlocks: %v\n  needBlocks: %v", lf, f, have, need)
		}
		queued++
		p.bq.put(bqAdd{
			file: f,
			have: have,
			need: need,
		})
	}
	if debug && queued > 0 {
		l.Debugf("%q: queued %d items", p.repoCfg.ID, queued)
	}

	if queued > 0 {
		return prevVer, queued
	} else {
		return curVer, 0
	}
}