mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-10 00:20:42 +02:00
* volume: an already-deleted EC needle is not a delete failure Deleting a needle that is already gone is what the caller asked for, and the non-EC paths have always said so: BatchDelete reports StatusNotModified when DeleteVolumeNeedle finds nothing to do, and DeleteHandler answers 404 from its ReadVolumeNeedle pre-check. The EC branches had no such case, so ErrorDeleted fell through to a generic failure -- 500 from both, and DeleteHandler also counted it in VolumeServerFileWriteFailures, inflating a failure metric on a replayed or duplicated delete. The filer already tolerates this by string-matching "already deleted" on the result, which leaves an error message load-bearing; the status is now right at the source instead. Claude-Session: https://claude.ai/code/session_01P3pE6J2UPFp6G3ksfMV4s1 * volume: close the EC fixture's disk location Close stops the location's disk-space goroutine and releases the mounted EC volume's file handles, which otherwise live until the test binary exits. Claude-Session: https://claude.ai/code/session_01P3pE6J2UPFp6G3ksfMV4s1
148 lines
4.0 KiB
Go
148 lines
4.0 KiB
Go
package weed_server
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
)
|
|
|
|
func (vs *VolumeServer) BatchDelete(ctx context.Context, req *volume_server_pb.BatchDeleteRequest) (*volume_server_pb.BatchDeleteResponse, error) {
|
|
resp := &volume_server_pb.BatchDeleteResponse{}
|
|
|
|
if err := vs.checkGrpcAdminAuth(ctx); err != nil {
|
|
return resp, err
|
|
}
|
|
|
|
if err := vs.CheckMaintenanceMode(); err != nil {
|
|
return resp, err
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
n := new(needle.Needle)
|
|
volumeId, _ := needle.NewVolumeId(vid)
|
|
if req.SkipCookieCheck {
|
|
n.Id, _, err = needle.ParseNeedleIdCookie(id_cookie)
|
|
if err != nil {
|
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
|
|
FileId: fid,
|
|
Status: http.StatusBadRequest,
|
|
Error: err.Error()})
|
|
continue
|
|
}
|
|
} else {
|
|
if err := n.ParsePath(id_cookie); err != nil {
|
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
|
|
FileId: fid,
|
|
Status: http.StatusBadRequest,
|
|
Error: err.Error()})
|
|
continue
|
|
}
|
|
}
|
|
|
|
ecVolume, isEcVolume := vs.store.FindEcVolume(volumeId)
|
|
if !req.SkipCookieCheck {
|
|
cookie := n.Cookie
|
|
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
|
|
}
|
|
}
|
|
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.",
|
|
})
|
|
continue
|
|
}
|
|
}
|
|
|
|
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
|
|
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()},
|
|
)
|
|
} else if size == 0 {
|
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
|
|
FileId: fid,
|
|
Status: http.StatusNotModified},
|
|
)
|
|
} else {
|
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
|
|
FileId: fid,
|
|
Status: http.StatusAccepted,
|
|
Size: uint32(size)},
|
|
)
|
|
}
|
|
} else {
|
|
size, err := vs.store.DeleteEcShardNeedle(ecVolume, n, n.Cookie)
|
|
if errors.Is(err, storage.ErrorDeleted) {
|
|
// Already gone, which is what the caller asked for. The
|
|
// non-EC branch above reports that as StatusNotModified.
|
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{
|
|
FileId: fid,
|
|
Status: http.StatusNotModified},
|
|
)
|
|
} else if 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)},
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|