seaweedfs/weed/filer2/filer_deletion.go

88 lines
2.2 KiB
Go
Raw Normal View History

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() {
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 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 deletionCount int
2018-11-21 12:56:28 +08:00
for {
deletionCount = 0
f.fileIdDeletionQueue.Consume(func(fileIds []string) {
deletionCount = len(fileIds)
2020-03-21 14:38:24 +08:00
deleteResults, err := operation.DeleteFilesWithLookupVolumeId(f.GrpcDialOption, fileIds, lookupFunc)
if err != nil {
glog.V(0).Infof("deleting fileIds len=%d error: %v", deletionCount, err)
} else {
glog.V(1).Infof("deleting fileIds len=%d", deletionCount)
2018-11-21 12:56:28 +08:00
}
2020-03-21 14:38:24 +08:00
if len(deleteResults) != deletionCount {
glog.V(0).Infof("delete %d fileIds actual %d", deletionCount, len(deleteResults))
}
})
if deletionCount == 0 {
time.Sleep(1123 * time.Millisecond)
2018-11-21 12:56:28 +08:00
}
}
}
func (f *Filer) DeleteChunks(chunks []*filer_pb.FileChunk) {
2018-11-21 12:56:28 +08:00
for _, chunk := range chunks {
f.fileIdDeletionQueue.EnQueue(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.fileIdDeletionQueue.EnQueue(fileId)
2018-11-21 12:56:28 +08:00
}
func (f *Filer) deleteChunksIfNotNew(oldEntry, newEntry *Entry) {
if oldEntry == nil {
return
}
if newEntry == nil {
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)
}
}
f.DeleteChunks(toDelete)
2018-11-21 12:56:28 +08:00
}