seaweedfs/weed/filesys/wfs_deletion.go

70 lines
1.6 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
"github.com/chrislusf/seaweedfs/weed/filer2"
"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"
2019-06-21 12:57:17 +08:00
"google.golang.org/grpc"
2019-01-01 18:33:57 +08:00
)
2019-03-16 08:20:24 +08:00
func (wfs *WFS) deleteFileChunks(ctx context.Context, chunks []*filer_pb.FileChunk) {
2019-01-06 14:51:50 +08:00
if len(chunks) == 0 {
return
}
var fileIds []string
for _, chunk := range chunks {
2019-06-23 11:04:56 +08:00
fileIds = append(fileIds, chunk.GetFileIdString())
2019-01-06 14:51:50 +08:00
}
2019-05-03 15:24:35 +08:00
wfs.WithFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {
2019-03-16 08:20:24 +08:00
deleteFileIds(ctx, 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 deleteFileIds(ctx context.Context, grpcDialOption grpc.DialOption, client filer_pb.SeaweedFilerClient, fileIds []string) error {
var vids []string
for _, fileId := range fileIds {
vids = append(vids, filer2.VolumeId(fileId))
}
lookupFunc := func(vids []string) (map[string]operation.LookupResult, error) {
m := make(map[string]operation.LookupResult)
glog.V(4).Infof("remove file lookup volume id locations: %v", vids)
resp, err := client.LookupVolume(ctx, &filer_pb.LookupVolumeRequest{
VolumeIds: vids,
})
if err != nil {
return m, err
}
for _, vid := range vids {
lr := operation.LookupResult{
VolumeId: vid,
Locations: nil,
}
locations := resp.LocationsMap[vid]
for _, loc := range locations.Locations {
lr.Locations = append(lr.Locations, operation.Location{
Url: loc.Url,
PublicUrl: loc.PublicUrl,
})
}
m[vid] = lr
}
return m, err
}
_, err := operation.DeleteFilesWithLookupVolumeId(grpcDialOption, fileIds, lookupFunc)
return err
}