mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-19 02:15:02 +01:00
* volume: fsync a needle delete that asks for it A delete now takes fsync like a write: the tombstone is synced before the needle map drops the needle, and the .idx row before the delete is acknowledged. A failed .dat sync takes the tombstone back off the .dat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: honor fsync=true on DELETE and forward it to replicas Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): fsync a needle delete that asks for it Mirrors the Go volume server: DELETE with fsync=true flushes the tombstone before the index drops the needle and the .idx before the ack, and a failed .dat flush takes the tombstone back off the .dat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: let a durable delete through on a full volume A queued delete hit the batch worker's volume size check, which a tombstone append is exempt from inline, so fsync=true deletes failed once the volume reached its hard limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: sync a durable delete of an already-deleted needle An earlier delete without fsync may have dropped the needle with its tombstone still unsynced, so the inline path syncs before acking anyway, as the batch worker already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: refuse a batch request that races the worker stopping stopWorker can close the batch channel between startWorker handing it out and the send, which panicked. The request now falls back to the inline path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): sync a durable delete of an already-deleted needle Mirrors the Go volume server: an earlier delete without fsync may have dropped the needle with its tombstone still unsynced. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): run a durable delete on a blocking thread Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: keep syncDelete's signature for existing callers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: refuse a write a delete cancelled before it appends A write cancelled while still queued behind the volume locks used to append, publish and then tombstone itself without a sync, after its delete may already have been acknowledged as durable. A crash could keep the row and lose the tombstone. Refuse it before the append. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): refuse a write a delete cancelled before it appends Mirrors the Go change: a write cancelled while still queued behind the volume locks no longer appends, publishes and tombstones itself without a sync after its delete may already be durable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): drop the write guards for a durable delete's flushes The durable delete held the write lease and the io write guard across both fsyncs, so reads of the volume waited on them. Append and publish the tombstone under the guards and flush with only the io read side, as write_synced_run and the Go path already do. do_delete_request keeps its signature. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: stop taking writes when a durable delete fails to index The needle map drops the needle before it appends the .idx row, so after a failed append a durable retry found nothing to delete and acked, and a later write could bury the unindexed tombstone so a reload brought the needle back. Fence the volume the way a failed durable write does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): stop taking writes when a durable delete fails to index Rust counterpart of the Go change: the needle map drops the needle before it appends the .idx row, so a failed append left a durable retry nothing to delete, and a later write could bury the unindexed tombstone. publish_delete_request now fences the volume for a durable delete, as publish_write does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: stop taking writes when any delete fails to index A non-durable delete whose .idx append failed left the volume writable with the needle already dropped from the map, so a later durable retry found nothing to delete and acknowledged without the missing row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): stop taking writes when any delete fails to index Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: take the fsync flag on the existing delete functions DeleteVolumeNeedle, deleteNeedle2 and syncDelete take fsync instead of gaining *WithFsync variants. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): take the fsync flag on the existing delete functions delete_volume_needle and delete_needle take fsync instead of gaining *_with_fsync variants; the durable path and the deletable checks fold back into delete_needle, and the cancelled-write check mirrors Go's isCancelledWrite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
154 lines
4.2 KiB
Go
154 lines
4.2 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"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
)
|
|
|
|
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)
|
|
var fidCookie types.Cookie
|
|
if req.SkipCookieCheck {
|
|
n.Id, fidCookie, 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, deleteReadOption(), 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 req.SkipCookieCheck {
|
|
// the delete cancels in-flight writes carrying this cookie
|
|
n.Cookie = fidCookie
|
|
}
|
|
if size, err := vs.store.DeleteVolumeNeedle(volumeId, n, false); 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
|
|
|
|
}
|