batch delete EC needles

fix https://github.com/seaweedfs/seaweedfs/issues/4107
This commit is contained in:
chrislu 2023-01-03 22:05:26 -08:00
parent 8aec430df7
commit 7bdae5172e

View file

@ -28,6 +28,7 @@ func (vs *VolumeServer) BatchDelete(ctx context.Context, req *volume_server_pb.B
n := new(needle.Needle) n := new(needle.Needle)
volumeId, _ := needle.NewVolumeId(vid) volumeId, _ := needle.NewVolumeId(vid)
ecVolume, isEcVolume := vs.store.FindEcVolume(volumeId)
if req.SkipCookieCheck { if req.SkipCookieCheck {
n.Id, _, err = needle.ParseNeedleIdCookie(id_cookie) n.Id, _, err = needle.ParseNeedleIdCookie(id_cookie)
if err != nil { if err != nil {
@ -40,13 +41,24 @@ func (vs *VolumeServer) BatchDelete(ctx context.Context, req *volume_server_pb.B
} else { } else {
n.ParsePath(id_cookie) n.ParsePath(id_cookie)
cookie := n.Cookie cookie := n.Cookie
if _, err := vs.store.ReadVolumeNeedle(volumeId, n, nil, nil); err != nil { if !isEcVolume {
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{ if _, err := vs.store.ReadVolumeNeedle(volumeId, n, nil, nil); err != nil {
FileId: fid, resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
Status: http.StatusNotFound, FileId: fid,
Error: err.Error(), Status: http.StatusNotFound,
}) Error: err.Error(),
continue })
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
}
} }
if n.Cookie != cookie { if n.Cookie != cookie {
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{ resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
@ -68,18 +80,34 @@ func (vs *VolumeServer) BatchDelete(ctx context.Context, req *volume_server_pb.B
} }
n.LastModified = now n.LastModified = now
if size, err := vs.store.DeleteVolumeNeedle(volumeId, n); err != nil { if !isEcVolume {
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{ if size, err := vs.store.DeleteVolumeNeedle(volumeId, n); err != nil {
FileId: fid, resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
Status: http.StatusInternalServerError, FileId: fid,
Error: err.Error()}, Status: http.StatusInternalServerError,
) Error: err.Error()},
)
} else {
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
FileId: fid,
Status: http.StatusAccepted,
Size: uint32(size)},
)
}
} else { } else {
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{ if size, err := vs.store.DeleteEcShardNeedle(ecVolume, n, n.Cookie); err != nil {
FileId: fid, resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
Status: http.StatusAccepted, FileId: fid,
Size: uint32(size)}, Status: http.StatusInternalServerError,
) Error: err.Error()},
)
} else {
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
FileId: fid,
Status: http.StatusAccepted,
Size: uint32(size)},
)
}
} }
} }