mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactoring
This commit is contained in:
parent
3106065b58
commit
eebc44cce3
|
@ -9,12 +9,10 @@ import (
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/filer2"
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/operation"
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
"github.com/gabriel-vasile/mimetype"
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"github.com/seaweedfs/fuse"
|
"github.com/seaweedfs/fuse"
|
||||||
"github.com/seaweedfs/fuse/fs"
|
"github.com/seaweedfs/fuse/fs"
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileHandle struct {
|
type FileHandle struct {
|
||||||
|
@ -172,44 +170,3 @@ func (fh *FileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,7 +2,12 @@ package filesys
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/operation"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (wfs *WFS) deleteFileChunks(ctx context.Context, chunks []*filer_pb.FileChunk) {
|
func (wfs *WFS) deleteFileChunks(ctx context.Context, chunks []*filer_pb.FileChunk) {
|
||||||
|
@ -20,3 +25,45 @@ func (wfs *WFS) deleteFileChunks(ctx context.Context, chunks []*filer_pb.FileChu
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue