2018-10-11 08:16:33 +00:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
2018-10-11 08:16:33 +00: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 04:43:36 +00:00
|
|
|
n := new(needle.Needle)
|
|
|
|
volumeId, _ := needle.NewVolumeId(vid)
|
2023-01-04 06:05:26 +00:00
|
|
|
ecVolume, isEcVolume := vs.store.FindEcVolume(volumeId)
|
2020-03-25 09:21:15 +00:00
|
|
|
if req.SkipCookieCheck {
|
2021-06-19 10:46:39 +00:00
|
|
|
n.Id, _, err = needle.ParseNeedleIdCookie(id_cookie)
|
2020-03-25 09:21:15 +00: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
|
2023-01-04 06:05:26 +00:00
|
|
|
if !isEcVolume {
|
|
|
|
if _, err := vs.store.ReadVolumeNeedle(volumeId, n, nil, nil); err != nil {
|
|
|
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
|
|
|
|
FileId: fid,
|
|
|
|
Status: http.StatusNotFound,
|
|
|
|
Error: err.Error(),
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if _, err := vs.store.ReadEcShardNeedle(volumeId, n, nil); err != nil {
|
|
|
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
|
|
|
|
FileId: fid,
|
|
|
|
Status: http.StatusNotFound,
|
|
|
|
Error: err.Error(),
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
2020-03-25 09:21:15 +00:00
|
|
|
}
|
|
|
|
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 08:16:33 +00: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
|
2023-01-04 06:05:26 +00:00
|
|
|
if !isEcVolume {
|
|
|
|
if size, err := vs.store.DeleteVolumeNeedle(volumeId, n); err != nil {
|
|
|
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
|
|
|
|
FileId: fid,
|
|
|
|
Status: http.StatusInternalServerError,
|
|
|
|
Error: err.Error()},
|
|
|
|
)
|
2023-10-12 15:15:20 +00:00
|
|
|
} else if size == 0 {
|
|
|
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
|
|
|
|
FileId: fid,
|
|
|
|
Status: http.StatusNotModified},
|
|
|
|
)
|
2023-01-04 06:05:26 +00:00
|
|
|
} else {
|
|
|
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
|
|
|
|
FileId: fid,
|
|
|
|
Status: http.StatusAccepted,
|
|
|
|
Size: uint32(size)},
|
|
|
|
)
|
|
|
|
}
|
2018-10-11 08:16:33 +00:00
|
|
|
} else {
|
2023-01-04 06:05:26 +00:00
|
|
|
if size, err := vs.store.DeleteEcShardNeedle(ecVolume, n, n.Cookie); err != nil {
|
|
|
|
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 08:16:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
|
|
|
|
}
|