// Assemble target files from stored chunks func (a *Assembler) Done(what lists.BlobMap) (err error) { logx.Tracef("assembling %s", what.Names()) var req, res []interface{} for k, v := range what { req = append(req, lists.BlobLink{v, k}) } err = a.model.BatchPool.Do( func(ctx context.Context, in interface{}) (out interface{}, err error) { r := in.(lists.BlobLink) lock, err := a.model.FdLocks.Take() if err != nil { return } defer lock.Release() w, err := os.Create(filepath.Join(a.model.WD, r.Name+r.Manifest.ID.String())) if err != nil { return } defer w.Close() for _, chunk := range r.Manifest.Chunks { if err = a.writeChunkTo(w, chunk.ID); err != nil { return } } err = a.commitBlob(r.Name, r.Manifest.ID) return }, &req, &res, concurrency.DefaultBatchOptions().AllowErrors(), ) if err != nil { return } defer a.Close() return }
func (u *Upload) SendCreateUpload(links lists.BlobMap) (missing []proto.ID, err error) { cli, err := u.Transport.tPool.Take() if err != nil { return } defer cli.Release() mans := proto.ManifestSlice(links.GetManifestSlice()) tSlice, err := mans.MarshalThrift() if err != nil { return } res1, err := cli.CreateUpload((*u.UUID)[:], tSlice, int64(u.ttl)) if err != nil { return } var r2 proto.IDSlice err = (&r2).UnmarshalThrift(res1) missing = r2 return }
func (m *Model) SquashBlobs(blobs lists.BlobMap) (err error) { logx.Tracef("squashing blobs %s", blobs.IDMap()) var req, res []interface{} for _, v := range blobs.ToSlice() { req = append(req, v) } err = m.BatchPool.Do( func(ctx context.Context, in interface{}) (out interface{}, err error) { r := in.(lists.BlobLink) lock, err := m.FdLocks.Take() if err != nil { return } defer lock.Release() absname := filepath.Join(m.WD, r.Name) backName := absname + ".bar-backup" os.Rename(absname, absname+".bar-backup") os.MkdirAll(filepath.Dir(absname), 0755) w, err := os.Create(absname) if err != nil { return } err = r.Manifest.Serialize(w) if err != nil { os.Remove(absname) os.Rename(backName, absname) return } defer os.Remove(backName) logx.Debugf("squashed %s", r.Name) return }, &req, &res, concurrency.DefaultBatchOptions().AllowErrors(), ) if err != nil { return } logx.Infof("blob %s squashed successfully", blobs.Names()) return }