seaweedfs/weed/filer2/filer_deletion.go

88 lines
2.1 KiB
Go
Raw Normal View History

2018-11-21 04:56:28 +00:00
package filer2
import (
"time"
2018-11-23 08:26:15 +00:00
"github.com/chrislusf/seaweedfs/weed/glog"
2018-11-21 04:56:28 +00: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 {
locs, _ := f.MasterClient.GetVidLocations(vid)
2018-11-21 04:56:28 +00: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-18 20:11:52 +00:00
operation.DeleteFilesWithLookupVolumeId(f.GrpcDialOption, fileIds, lookupFunc)
2018-11-21 04:56:28 +00:00
fileIds = fileIds[:0]
}
case <-ticker.C:
if len(fileIds) > 0 {
glog.V(1).Infof("timed deletion fileIds len=%d", len(fileIds))
2019-02-18 20:11:52 +00:00
operation.DeleteFilesWithLookupVolumeId(f.GrpcDialOption, fileIds, lookupFunc)
2018-11-21 04:56:28 +00:00
fileIds = fileIds[:0]
}
}
}
}
func (f *Filer) DeleteChunks(chunks []*filer_pb.FileChunk) {
2018-11-21 04:56:28 +00:00
for _, chunk := range chunks {
2019-06-23 03:04:56 +00:00
f.fileIdDeletionChan <- chunk.GetFileIdString()
2018-11-21 04:56:28 +00:00
}
}
2019-04-16 20:57:45 +00:00
// DeleteFileByFileId direct delete by file id.
// Only used when the fileId is not being managed by snapshots.
2018-11-21 04:56:28 +00:00
func (f *Filer) DeleteFileByFileId(fileId string) {
f.fileIdDeletionChan <- fileId
}
func (f *Filer) deleteChunksIfNotNew(oldEntry, newEntry *Entry) {
if oldEntry == nil {
return
}
if newEntry == nil {
f.DeleteChunks(oldEntry.Chunks)
2018-11-21 04:56:28 +00:00
}
var toDelete []*filer_pb.FileChunk
2019-06-22 20:22:22 +00:00
newChunkIds := make(map[string]bool)
for _, newChunk := range newEntry.Chunks {
newChunkIds[newChunk.GetFileIdString()] = true
}
2018-11-21 04:56:28 +00:00
for _, oldChunk := range oldEntry.Chunks {
2019-06-22 20:22:22 +00:00
if _, found := newChunkIds[oldChunk.GetFileIdString()]; !found {
2018-11-21 04:56:28 +00:00
toDelete = append(toDelete, oldChunk)
}
}
f.DeleteChunks(toDelete)
2018-11-21 04:56:28 +00:00
}