2018-11-21 12:56:28 +08:00
|
|
|
package filer2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2018-11-23 16:26:15 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2018-11-21 12:56:28 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/operation"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (f *Filer) loopProcessingDeletion() {
|
|
|
|
|
|
|
|
ticker := time.NewTicker(5 * time.Second)
|
|
|
|
|
|
|
|
lookupFunc := func(vids []string) (map[string]operation.LookupResult, error) {
|
|
|
|
m := make(map[string]operation.LookupResult)
|
|
|
|
for _, vid := range vids {
|
2019-07-28 18:58:13 +08:00
|
|
|
locs, _ := f.MasterClient.GetVidLocations(vid)
|
2018-11-21 12:56:28 +08:00
|
|
|
var locations []operation.Location
|
|
|
|
for _, loc := range locs {
|
|
|
|
locations = append(locations, operation.Location{
|
|
|
|
Url: loc.Url,
|
|
|
|
PublicUrl: loc.PublicUrl,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
m[vid] = operation.LookupResult{
|
|
|
|
VolumeId: vid,
|
|
|
|
Locations: locations,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var fileIds []string
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case fid := <-f.fileIdDeletionChan:
|
|
|
|
fileIds = append(fileIds, fid)
|
|
|
|
if len(fileIds) >= 4096 {
|
|
|
|
glog.V(1).Infof("deleting fileIds len=%d", len(fileIds))
|
2019-02-19 04:11:52 +08:00
|
|
|
operation.DeleteFilesWithLookupVolumeId(f.GrpcDialOption, fileIds, lookupFunc)
|
2018-11-21 12:56:28 +08:00
|
|
|
fileIds = fileIds[:0]
|
|
|
|
}
|
|
|
|
case <-ticker.C:
|
|
|
|
if len(fileIds) > 0 {
|
|
|
|
glog.V(1).Infof("timed deletion fileIds len=%d", len(fileIds))
|
2019-02-19 04:11:52 +08:00
|
|
|
operation.DeleteFilesWithLookupVolumeId(f.GrpcDialOption, fileIds, lookupFunc)
|
2018-11-21 12:56:28 +08:00
|
|
|
fileIds = fileIds[:0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-13 16:23:05 +08:00
|
|
|
func (f *Filer) DeleteChunks(chunks []*filer_pb.FileChunk) {
|
2018-11-21 12:56:28 +08:00
|
|
|
for _, chunk := range chunks {
|
2019-06-23 11:04:56 +08:00
|
|
|
f.fileIdDeletionChan <- chunk.GetFileIdString()
|
2018-11-21 12:56:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 04:57:45 +08:00
|
|
|
// DeleteFileByFileId direct delete by file id.
|
|
|
|
// Only used when the fileId is not being managed by snapshots.
|
2018-11-21 12:56:28 +08:00
|
|
|
func (f *Filer) DeleteFileByFileId(fileId string) {
|
|
|
|
f.fileIdDeletionChan <- fileId
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Filer) deleteChunksIfNotNew(oldEntry, newEntry *Entry) {
|
|
|
|
|
|
|
|
if oldEntry == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if newEntry == nil {
|
2019-12-13 16:23:05 +08:00
|
|
|
f.DeleteChunks(oldEntry.Chunks)
|
2018-11-21 12:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var toDelete []*filer_pb.FileChunk
|
2019-06-23 04:22:22 +08:00
|
|
|
newChunkIds := make(map[string]bool)
|
|
|
|
for _, newChunk := range newEntry.Chunks {
|
|
|
|
newChunkIds[newChunk.GetFileIdString()] = true
|
|
|
|
}
|
2018-11-21 12:56:28 +08:00
|
|
|
|
|
|
|
for _, oldChunk := range oldEntry.Chunks {
|
2019-06-23 04:22:22 +08:00
|
|
|
if _, found := newChunkIds[oldChunk.GetFileIdString()]; !found {
|
2018-11-21 12:56:28 +08:00
|
|
|
toDelete = append(toDelete, oldChunk)
|
|
|
|
}
|
|
|
|
}
|
2019-12-13 16:23:05 +08:00
|
|
|
f.DeleteChunks(toDelete)
|
2018-11-21 12:56:28 +08:00
|
|
|
}
|