seaweedfs/weed/server/volume_grpc_batch_delete.go

89 lines
2.3 KiB
Go
Raw Normal View History

2018-10-11 16:16:33 +08:00
package weed_server
import (
"context"
"net/http"
"time"
"github.com/chrislusf/seaweedfs/weed/operation"
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
2019-04-19 12:43:36 +08:00
"github.com/chrislusf/seaweedfs/weed/storage/needle"
2018-10-11 16:16:33 +08:00
)
func (vs *VolumeServer) BatchDelete(ctx context.Context, req *volume_server_pb.BatchDeleteRequest) (*volume_server_pb.BatchDeleteResponse, error) {
resp := &volume_server_pb.BatchDeleteResponse{}
now := uint64(time.Now().Unix())
for _, fid := range req.FileIds {
vid, id_cookie, err := operation.ParseFileId(fid)
if err != nil {
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
FileId: fid,
Status: http.StatusBadRequest,
Error: err.Error()})
continue
}
2019-04-19 12:43:36 +08:00
n := new(needle.Needle)
volumeId, _ := needle.NewVolumeId(vid)
2020-03-25 17:21:15 +08:00
if req.SkipCookieCheck {
n.Id, _, err = needle.ParseNeedleIdCookie(id_cookie)
2020-03-25 17:21:15 +08:00
if err != nil {
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
FileId: fid,
Status: http.StatusBadRequest,
Error: err.Error()})
continue
}
} else {
n.ParsePath(id_cookie)
cookie := n.Cookie
if _, err := vs.store.ReadVolumeNeedle(volumeId, n, nil, nil); err != nil {
2020-03-25 17:21:15 +08:00
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
FileId: fid,
Status: http.StatusNotFound,
Error: err.Error(),
})
continue
}
if n.Cookie != cookie {
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
FileId: fid,
Status: http.StatusBadRequest,
Error: "File Random Cookie does not match.",
})
break
}
2018-10-11 16:16:33 +08:00
}
if n.IsChunkedManifest() {
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
FileId: fid,
Status: http.StatusNotAcceptable,
Error: "ChunkManifest: not allowed in batch delete mode.",
})
continue
}
n.LastModified = now
2019-07-18 14:43:48 +08:00
if size, err := vs.store.DeleteVolumeNeedle(volumeId, n); err != nil {
2018-10-11 16:16:33 +08:00
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
FileId: fid,
Status: http.StatusInternalServerError,
Error: err.Error()},
)
} else {
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
FileId: fid,
Status: http.StatusAccepted,
Size: uint32(size)},
2018-10-11 16:16:33 +08:00
)
}
}
return resp, nil
}