seaweedfs/weed/filesys/wfs_deletion.go

85 lines
2.1 KiB
Go
Raw Normal View History

2019-01-01 18:33:57 +08:00
package filesys
import (
"context"
2019-06-21 12:57:17 +08:00
"google.golang.org/grpc"
2020-09-01 15:21:19 +08:00
"github.com/chrislusf/seaweedfs/weed/filer"
2019-06-21 12:57:17 +08:00
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/operation"
2019-01-01 18:33:57 +08:00
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
)
func (wfs *WFS) deleteFileChunks(chunks []*filer_pb.FileChunk) {
2019-01-06 14:51:50 +08:00
if len(chunks) == 0 {
return
}
var fileIds []string
for _, chunk := range chunks {
if !chunk.IsChunkManifest {
fileIds = append(fileIds, chunk.GetFileIdString())
continue
}
2020-09-01 15:21:19 +08:00
dataChunks, manifestResolveErr := filer.ResolveOneChunkManifest(filer.LookupFn(wfs), chunk)
if manifestResolveErr != nil {
glog.V(0).Infof("failed to resolve manifest %s: %v", chunk.FileId, manifestResolveErr)
}
for _, dChunk := range dataChunks {
fileIds = append(fileIds, dChunk.GetFileIdString())
}
2020-08-31 15:16:03 +08:00
fileIds = append(fileIds, chunk.GetFileIdString())
2019-01-06 14:51:50 +08:00
}
wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
wfs.deleteFileIds(wfs.option.GrpcDialOption, client, fileIds)
2019-01-06 14:51:50 +08:00
return nil
})
2019-01-01 18:33:57 +08:00
}
2019-06-21 12:57:17 +08:00
func (wfs *WFS) deleteFileIds(grpcDialOption grpc.DialOption, client filer_pb.SeaweedFilerClient, fileIds []string) error {
2019-06-21 12:57:17 +08:00
var vids []string
for _, fileId := range fileIds {
2020-09-01 15:21:19 +08:00
vids = append(vids, filer.VolumeId(fileId))
2019-06-21 12:57:17 +08:00
}
lookupFunc := func(vids []string) (map[string]operation.LookupResult, error) {
m := make(map[string]operation.LookupResult)
2020-08-31 11:12:04 +08:00
glog.V(4).Infof("deleteFileIds lookup volume id locations: %v", vids)
resp, err := client.LookupVolume(context.Background(), &filer_pb.LookupVolumeRequest{
2019-06-21 12:57:17 +08:00
VolumeIds: vids,
})
if err != nil {
return m, err
}
for _, vid := range vids {
lr := operation.LookupResult{
VolumeId: vid,
Locations: nil,
}
2020-01-20 04:07:26 +08:00
locations, found := resp.LocationsMap[vid]
if !found {
continue
}
2019-06-21 12:57:17 +08:00
for _, loc := range locations.Locations {
lr.Locations = append(lr.Locations, operation.Location{
Url: wfs.AdjustedUrl(loc),
2019-06-21 12:57:17 +08:00
PublicUrl: loc.PublicUrl,
})
}
m[vid] = lr
}
return m, err
}
_, err := operation.DeleteFilesWithLookupVolumeId(grpcDialOption, fileIds, lookupFunc)
return err
}