func ReplicatedDelete(masterNode string, store *storage.Store, volumeId storage.VolumeId, n *storage.Needle, r *http.Request) (ret uint32) { //check JWT jwt := security.GetJwt(r) ret, err := store.Delete(volumeId, n) if err != nil { glog.V(0).Infoln("delete error:", err) return } needToReplicate := !store.HasVolume(volumeId) if !needToReplicate && ret > 0 { needToReplicate = store.GetVolume(volumeId).NeedToReplicate() } if needToReplicate { //send to other replica locations if r.FormValue("type") != "replicate" { if !distributedOperation(masterNode, store, volumeId, func(location operation.Location) bool { return nil == util.Delete("http://"+location.Url+r.URL.Path+"?type=replicate", jwt) }) { ret = 0 } } } return }
func DeleteFile(master string, fileId string, jwt security.EncodedJwt) error { fileUrl, err := LookupFileId(master, fileId) if err != nil { return err } return util.Delete(fileUrl, jwt) }
func writeFiles(idChan chan int, fileIdLineChan chan string, s *stat) { defer wait.Done() delayedDeleteChan := make(chan *delayedFile, 100) var waitForDeletions sync.WaitGroup secret := security.Secret(*b.secretKey) for i := 0; i < 7; i++ { waitForDeletions.Add(1) go func() { defer waitForDeletions.Done() for df := range delayedDeleteChan { if df.enterTime.After(time.Now()) { time.Sleep(df.enterTime.Sub(time.Now())) } if e := util.Delete("http://"+df.fp.Server+"/"+df.fp.Fid, security.GenJwt(secret, df.fp.Fid)); e == nil { s.completed++ } else { s.failed++ } } }() } for id := range idChan { start := time.Now() fileSize := int64(*b.fileSize + rand.Intn(64)) fp := &operation.FilePart{Reader: &FakeReader{id: uint64(id), size: fileSize}, FileSize: fileSize} if assignResult, err := operation.Assign(*b.server, 1, "", *b.collection, ""); err == nil { fp.Server, fp.Fid, fp.Collection = assignResult.Url, assignResult.Fid, *b.collection if _, err := fp.Upload(0, *b.server, secret); err == nil { if rand.Intn(100) < *b.deletePercentage { s.total++ delayedDeleteChan <- &delayedFile{time.Now().Add(time.Second), fp} } else { fileIdLineChan <- fp.Fid } s.completed++ s.transferred += fileSize } else { s.failed++ fmt.Printf("Failed to write with error:%v\n", err) } writeStats.addSample(time.Now().Sub(start)) if *cmdBenchmark.IsDebug { fmt.Printf("writing %d file %s\n", id, fp.Fid) } } else { s.failed++ println("writing file error:", err.Error()) } } close(delayedDeleteChan) waitForDeletions.Wait() }
func DeleteFile(master string, fileId string, jwt security.EncodedJwt) error { fileUrl, err := LookupFileId(master, fileId) if err != nil { return fmt.Errorf("Failed to lookup %s:%v", fileId, err) } err = util.Delete(fileUrl, jwt) if err != nil { return fmt.Errorf("Failed to delete %s:%v", fileUrl, err) } return nil }