You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.3 KiB

6 years ago
6 years ago
6 years ago
  1. package weed_server
  2. import (
  3. "context"
  4. "net/http"
  5. "time"
  6. "github.com/chrislusf/seaweedfs/weed/operation"
  7. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  8. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  9. )
  10. func (vs *VolumeServer) BatchDelete(ctx context.Context, req *volume_server_pb.BatchDeleteRequest) (*volume_server_pb.BatchDeleteResponse, error) {
  11. resp := &volume_server_pb.BatchDeleteResponse{}
  12. now := uint64(time.Now().Unix())
  13. for _, fid := range req.FileIds {
  14. vid, id_cookie, err := operation.ParseFileId(fid)
  15. if err != nil {
  16. resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
  17. FileId: fid,
  18. Status: http.StatusBadRequest,
  19. Error: err.Error()})
  20. continue
  21. }
  22. n := new(needle.Needle)
  23. volumeId, _ := needle.NewVolumeId(vid)
  24. if req.SkipCookieCheck {
  25. n.Id, _, err = needle.ParseNeedleIdCookie(id_cookie)
  26. if err != nil {
  27. resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
  28. FileId: fid,
  29. Status: http.StatusBadRequest,
  30. Error: err.Error()})
  31. continue
  32. }
  33. } else {
  34. n.ParsePath(id_cookie)
  35. cookie := n.Cookie
  36. if _, err := vs.store.ReadVolumeNeedle(volumeId, n, nil, nil); err != nil {
  37. resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
  38. FileId: fid,
  39. Status: http.StatusNotFound,
  40. Error: err.Error(),
  41. })
  42. continue
  43. }
  44. if n.Cookie != cookie {
  45. resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
  46. FileId: fid,
  47. Status: http.StatusBadRequest,
  48. Error: "File Random Cookie does not match.",
  49. })
  50. break
  51. }
  52. }
  53. if n.IsChunkedManifest() {
  54. resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
  55. FileId: fid,
  56. Status: http.StatusNotAcceptable,
  57. Error: "ChunkManifest: not allowed in batch delete mode.",
  58. })
  59. continue
  60. }
  61. n.LastModified = now
  62. if size, err := vs.store.DeleteVolumeNeedle(volumeId, n); err != nil {
  63. resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
  64. FileId: fid,
  65. Status: http.StatusInternalServerError,
  66. Error: err.Error()},
  67. )
  68. } else {
  69. resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
  70. FileId: fid,
  71. Status: http.StatusAccepted,
  72. Size: uint32(size)},
  73. )
  74. }
  75. }
  76. return resp, nil
  77. }