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() }
func enoughBytesForBenchmark(objectServer *objectclient.ObjectClient, request sub.FetchRequest) bool { lengths, err := objectServer.CheckObjects(request.Hashes) if err != nil { return false } var totalLength uint64 for _, length := range lengths { totalLength += length } if totalLength > 1024*1024*64 { return true } return false }
func writeObjects(objectClient *objectclient.ObjectClient, hashes []hash.Hash, inums []uint64, lengths []uint64, inodesDir string) error { objectsReader, err := objectClient.GetObjects(hashes) if err != nil { return errors.New(fmt.Sprintf("Error getting object reader: %s\n", err.Error())) } defer objectsReader.Close() for index, hash := range hashes { err = writeObject(objectsReader, hash, inums[index], lengths[index], inodesDir) if err != nil { return err } } return nil }
func getAnnotation(objectClient *objectclient.ObjectClient, name string) ( *image.Annotation, error) { if name == "" { return nil, nil } file, err := os.Open(name) if err != nil { return &image.Annotation{URL: name}, nil } defer file.Close() fi, err := file.Stat() if err != nil { return nil, err } reader := bufio.NewReader(file) hash, _, err := objectClient.AddObject(reader, uint64(fi.Size()), nil) return &image.Annotation{Object: &hash}, nil }