// Returns true if all required objects are available. func (sub *Sub) fetchMissingObjects(connection *rpc.Client, imageName string) ( bool, uint) { image := sub.herd.getImage(imageName) if image == nil { return false, statusImageNotReady } missingObjects := make(map[hash.Hash]bool) for _, inode := range image.FileSystem.InodeTable { if inode, ok := inode.(*filesystem.RegularInode); ok { if inode.Size > 0 { missingObjects[inode.Hash] = true } } } for _, hash := range sub.fileSystem.ObjectCache { delete(missingObjects, hash) } for _, inode := range sub.fileSystem.InodeTable { if inode, ok := inode.(*filesystem.RegularInode); ok { if inode.Size > 0 { delete(missingObjects, inode.Hash) } } } if len(missingObjects) < 1 { return true, statusSynced } logger := sub.herd.logger logger.Printf("Calling %s.Fetch() for: %d objects\n", sub.hostname, len(missingObjects)) var request subproto.FetchRequest var reply subproto.FetchResponse request.ServerAddress = sub.herd.imageServerAddress for hash := range missingObjects { request.Hashes = append(request.Hashes, hash) } if err := connection.Call("Subd.Fetch", request, &reply); err != nil { logger.Printf("Error calling %s.Fetch()\t%s\n", sub.hostname, err) return false, statusFailedToFetch } sub.generationCountAtChangeStart = sub.generationCount return false, statusFetching }
func fetch(srpcClient *srpc.Client, hashesFilename string) error { hashesFile, err := os.Open(hashesFilename) if err != nil { return err } defer hashesFile.Close() scanner := bufio.NewScanner(hashesFile) var request sub.FetchRequest var reply sub.FetchResponse request.ServerAddress = fmt.Sprintf("%s:%d", *objectServerHostname, *objectServerPortNum) for scanner.Scan() { hashval, err := objectcache.FilenameToHash(scanner.Text()) if err != nil { return err } request.Hashes = append(request.Hashes, hashval) } if err := scanner.Err(); err != nil { return err } return client.CallFetch(srpcClient, request, &reply) }