Exemplo n.º 1
0
func (sub *Sub) pushObjects(objectsToPush map[hash.Hash]struct{},
	logger *log.Logger) error {
	objQ, err := objectclient.NewObjectAdderQueue(sub.Client)
	if err != nil {
		logger.Printf("Error creating object adder queue for: %s: %s\n",
			sub, err)
		return err
	}
	for hashVal := range objectsToPush {
		length, reader, err := sub.ObjectGetter.GetObject(hashVal)
		if err != nil {
			logger.Printf("Error getting object: %x: %s\n", hashVal, err)
			objQ.Close()
			return ErrorFailedToGetObject
		}
		_, err = objQ.Add(reader, length)
		reader.Close()
		if err != nil {
			logger.Printf("Error pushing: %x to: %s: %s\n", hashVal, sub, err)
			objQ.Close()
			return err
		}
	}
	if err := objQ.Close(); err != nil {
		logger.Printf("Error pushing objects to: %s: %s\n", sub, err)
		return err
	}
	return nil
}
Exemplo n.º 2
0
func copyMissingObjects(fs *filesystem.FileSystem, imageSClient *srpc.Client,
	objectClient *objectclient.ObjectClient, subName string) error {
	// Check to see which objects are in the objectserver.
	hashes := make([]hash.Hash, 0, fs.NumRegularInodes)
	for hash, _ := range fs.HashToInodesTable() {
		hashes = append(hashes, hash)
	}
	objectSizes, err := objectClient.CheckObjects(hashes)
	if err != nil {
		return err
	}
	missingHashes := make([]hash.Hash, 0)
	for index, size := range objectSizes {
		if size < 1 {
			missingHashes = append(missingHashes, hashes[index])
		}
	}
	if len(missingHashes) < 1 {
		return nil
	}
	// Get missing objects from sub.
	filesForMissingObjects := make([]string, 0, len(missingHashes))
	for _, hash := range missingHashes {
		if inums, ok := fs.HashToInodesTable()[hash]; !ok {
			return fmt.Errorf("no inode for object: %x", hash)
		} else if files, ok := fs.InodeToFilenamesTable()[inums[0]]; !ok {
			return fmt.Errorf("no file for inode: %d", inums[0])
		} else {
			filesForMissingObjects = append(filesForMissingObjects, files[0])
		}
	}
	objAdderQueue, err := objectclient.NewObjectAdderQueue(imageSClient)
	if err != nil {
		return err
	}
	subClient, err := srpc.DialHTTP("tcp",
		fmt.Sprintf("%s:%d", subName, constants.SubPortNumber), 0)
	if err != nil {
		return fmt.Errorf("error dialing %s", err)
	}
	defer subClient.Close()
	if err := subclient.GetFiles(subClient, filesForMissingObjects,
		func(reader io.Reader, size uint64) error {
			_, err := objAdderQueue.Add(reader, size)
			return err
		}); err != nil {
		return err
	}
	return objAdderQueue.Close()
}
Exemplo n.º 3
0
func addObjects(address string, filenames []string) error {
	client, err := srpc.DialHTTP("tcp", address, 0)
	if err != nil {
		return err
	}
	defer client.Close()
	objQ, err := objectclient.NewObjectAdderQueue(client)
	if err != nil {
		return err
	}
	for _, filename := range filenames {
		if err := addObject(objQ, filename); err != nil {
			objQ.Close()
			return err
		}
	}
	return objQ.Close()
}
Exemplo n.º 4
0
func buildImage(imageSClient *srpc.Client, filter *filter.Filter,
	imageFilename string) (*filesystem.FileSystem, error) {
	var h hasher
	var err error
	h.objQ, err = objectclient.NewObjectAdderQueue(imageSClient)
	if err != nil {
		return nil, err
	}
	fs, err := buildImageWithHasher(imageSClient, filter, imageFilename, &h)
	if err != nil {
		h.objQ.Close()
		return nil, err
	}
	err = h.objQ.Close()
	if err != nil {
		return nil, err
	}
	return fs, nil
}