Example #1
0
func checkEnumerate(idx *index.Index, want []blob.SizedRef, args *enumArgs) error {
	if args == nil {
		args = &enumArgs{}
	}
	if args.ctx == nil {
		args.ctx = context.TODO()
	}
	if args.dest == nil {
		args.dest = make(chan blob.SizedRef)
	}
	if args.limit == 0 {
		args.limit = 5000
	}
	errCh := make(chan error)
	go func() {
		errCh <- idx.EnumerateBlobs(args.ctx, args.dest, args.after, args.limit)
	}()
	for k, sbr := range want {
		got, ok := <-args.dest
		if !ok {
			return fmt.Errorf("could not enumerate blob %d", k)
		}
		if got != sbr {
			return fmt.Errorf("enumeration %d: got %v, wanted %v", k, got, sbr)
		}
	}
	_, ok := <-args.dest
	if ok {
		return errors.New("chan was not closed after enumeration")
	}
	return <-errCh
}
Example #2
0
func (f *FetcherEnumerator) Index(ch chan blobserver.BlobAndToken, dst *index.Index) {
	var long time.Duration
	for b := range ch {
		valid := b.ValidContents()

		f.mu.Lock()
		if valid {
			b := b
			f.Add(b.Blob)
		}
		f.stats.blobs++
		f.stats.bytes += uint64(b.Size())
		f.mu.Unlock()

		start := time.Now()
		r := b.Open()
		_, err := dst.ReceiveBlob(b.Ref(), r)
		if err != nil {
			log.Print(err)
		}
		r.Close()
		if elapsed := time.Now().Sub(start); elapsed > time.Second {
			long += elapsed
			fmt.Printf("elapsed %s to index sha1-%s at '%s' (cumulative %s)\n",
				elapsed, b.Ref().Digest(), b.Token, long)
			// pull some data out of the index to
			// describe blob? print continuation
			// token for easier restart?
		}
	}
}
Example #3
0
func checkStat(idx *index.Index, want []blob.SizedRef) error {
	dest := make(chan blob.SizedRef)
	defer close(dest)
	errCh := make(chan error)
	input := make([]blob.Ref, len(want))
	for _, sbr := range want {
		input = append(input, sbr.Ref)
	}
	go func() {
		errCh <- idx.StatBlobs(dest, input)
	}()
	for k, sbr := range want {
		got, ok := <-dest
		if !ok {
			return fmt.Errorf("could not get stat number %d", k)
		}
		if got != sbr {
			return fmt.Errorf("stat %d: got %v, wanted %v", k, got, sbr)
		}
	}
	return <-errCh
}