2019-01-01 10:33:57 +00:00
|
|
|
package filesys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-06-21 04:57:17 +00:00
|
|
|
|
2020-02-27 00:46:01 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2019-06-21 04:57:17 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/operation"
|
2019-01-01 10:33:57 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
|
|
|
)
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
func (wfs *WFS) deleteFileChunks(chunks []*filer_pb.FileChunk) {
|
2019-01-06 06:51:50 +00:00
|
|
|
if len(chunks) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var fileIds []string
|
|
|
|
for _, chunk := range chunks {
|
2019-06-23 03:04:56 +00:00
|
|
|
fileIds = append(fileIds, chunk.GetFileIdString())
|
2019-01-06 06:51:50 +00:00
|
|
|
}
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
2020-02-27 00:46:01 +00:00
|
|
|
wfs.deleteFileIds(wfs.option.GrpcDialOption, client, fileIds)
|
2019-01-06 06:51:50 +00:00
|
|
|
return nil
|
|
|
|
})
|
2019-01-01 10:33:57 +00:00
|
|
|
}
|
2019-06-21 04:57:17 +00:00
|
|
|
|
2020-02-27 00:46:01 +00:00
|
|
|
func (wfs *WFS) deleteFileIds(grpcDialOption grpc.DialOption, client filer_pb.SeaweedFilerClient, fileIds []string) error {
|
2019-06-21 04:57:17 +00:00
|
|
|
|
|
|
|
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)
|
2020-02-26 05:50:12 +00:00
|
|
|
resp, err := client.LookupVolume(context.Background(), &filer_pb.LookupVolumeRequest{
|
2019-06-21 04:57:17 +00:00
|
|
|
VolumeIds: vids,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return m, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, vid := range vids {
|
|
|
|
lr := operation.LookupResult{
|
|
|
|
VolumeId: vid,
|
|
|
|
Locations: nil,
|
|
|
|
}
|
2020-01-19 20:07:26 +00:00
|
|
|
locations, found := resp.LocationsMap[vid]
|
|
|
|
if !found {
|
|
|
|
continue
|
|
|
|
}
|
2019-06-21 04:57:17 +00:00
|
|
|
for _, loc := range locations.Locations {
|
|
|
|
lr.Locations = append(lr.Locations, operation.Location{
|
2020-02-27 00:46:01 +00:00
|
|
|
Url: wfs.AdjustedUrl(loc.Url),
|
2019-06-21 04:57:17 +00:00
|
|
|
PublicUrl: loc.PublicUrl,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
m[vid] = lr
|
|
|
|
}
|
|
|
|
|
|
|
|
return m, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := operation.DeleteFilesWithLookupVolumeId(grpcDialOption, fileIds, lookupFunc)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|