mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-16 00:38:53 +01:00
s3 lifecycle: write the suspended expiration marker before deleting the null version (#12664)
* s3 test: evaluate mutation conditions and serve DeleteEntry in the fake filer The fake ObjectTransaction now checks each mutation's own condition before applying it, as the filer does, and reports the failed mutation. ETag clauses read the stored ETag attribute first, like the filer. DeleteEntry removes the entry so unrouted delete paths can run against the fake. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3 lifecycle: write the suspended expiration marker before deleting the null version A suspended-versioning expiration deleted the null version first and then wrote the delete marker. When the pointer read or the marker write failed in between, the retry found no null version, resolved as NOT_FOUND or VERSION_NOT_LATEST, and never wrote the marker, so an older version became the latest. The marker now goes first. The latest pointer outranks the null object, so the key reads as deleted once the marker lands, and a null delete that fails after it leaves a noncurrent null version rather than exposing an older one. The null delete is pinned to the entry read before the marker: on the owner it carries IF_ENTRY_EQUAL on that read, and off the ring the entry is re-read and compared by identity first. A null object written after the read is a newer write and is no longer deleted. When the null version is the one that passed the expiration checks, a missing or changed entry at that read resolves the request as STALE_IDENTITY before anything is written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3 lifecycle: retry a failed routed null delete instead of deleting on the default filer A routed null delete that failed fell through to the unrouted path, which reads and deletes on the default filer. That filer may not have the owner's newer null object yet, so the fallback could delete it without the owner-side IF_ENTRY_EQUAL guard. The failure now returns RETRY_LATER; the marker is already written, so the key keeps reading as deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3 lifecycle: recheck and delete an unrouted null version under the object write lock Without a ring owner the identity recheck and the null delete were separate calls, so a suspended PUT landing between them was deleted. Off the ring writers take the object write lock, so the recheck and the delete now run under it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3 test: strip quotes from the stored ETag in the fake filer The filer normalizes both sides of an ETag comparison; the fake now strips quotes from the stored ETag attribute as well as from the candidate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3 lifecycle: retry the null delete when the object lock lookup fails on a routed key Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3 lifecycle: check the suspended marker against the validated version A suspended expiration that validated a named version wrote its marker without comparing the pointer, so a null PUT landing after the checks was hidden, and deleted too when it landed before the null read. The marker now compares the latest the way the enabled path does and resolves the request as VERSION_NOT_LATEST. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3 test: count the marker's object write lock in the unrouted null delete Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3 lifecycle: recheck the attempt deadline after reading the null version Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c09009a74f
commit
5f7fefadae
3 files changed
+421
-69
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3lifecycle"
|
||||
stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
)
|
||||
|
||||
// LifecycleDelete executes one (rule, action) verdict: re-fetch, identity
|
||||
@@ -104,39 +105,24 @@ func (s3a *S3ApiServer) lifecycleDispatch(ctx context.Context, req *s3_lifecycle
|
||||
}
|
||||
return done(), nil
|
||||
case s3_constants.VersioningSuspended:
|
||||
// Best-effort null delete; NotFound is benign. Route it when an
|
||||
// owner resolves — on the default filer an absent entry deletes as
|
||||
// success, and a null version that only reached the owner would
|
||||
// linger. Lifecycle never bypasses retention.
|
||||
nullDeleted := false
|
||||
if owner := s3a.routableWriteOwner(req.Bucket, req.ObjectPath); owner != "" {
|
||||
worm, lockErr := s3a.isObjectLockEnabled(req.Bucket)
|
||||
if lockErr == nil {
|
||||
code, settled := s3a.routedDeleteNullVersion(owner, req.Bucket, req.ObjectPath, worm, false, metadataOnly, nil)
|
||||
if settled {
|
||||
if code == s3err.ErrAccessDenied {
|
||||
return retryLater("ACCESS_DENIED: deleteNullVersion: object lock"), nil
|
||||
}
|
||||
if code != s3err.ErrNone {
|
||||
return retryLater("TRANSPORT_ERROR: routedDeleteNullVersion: " + s3err.GetAPIError(code).Code), nil
|
||||
}
|
||||
nullDeleted = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !nullDeleted {
|
||||
if err := s3a.deleteSpecificObjectVersion(ctx, req.Bucket, req.ObjectPath, "null", metadataOnly); err != nil {
|
||||
if !errors.Is(err, filer_pb.ErrNotFound) && !errors.Is(err, ErrVersionNotFound) {
|
||||
return retryLater("TRANSPORT_ERROR: deleteNullVersion: " + err.Error()), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
// The null delete is done, so the marker must follow even past
|
||||
// the deadline: without it a retry finds an older version latest.
|
||||
if _, resp := s3a.lifecycleDeleteMarker(req.Bucket, req.ObjectPath, ""); resp != nil {
|
||||
// Marker first: the pointer outranks the null object, so the key
|
||||
// reads as deleted once it lands, and a null delete that fails
|
||||
// after it leaves a noncurrent version instead of exposing an
|
||||
// older one to a retry that then finds no null to expire.
|
||||
nullEntry, resp := s3a.lifecycleNullVersion(req, entry)
|
||||
if resp != nil {
|
||||
return resp, nil
|
||||
}
|
||||
return done(), nil
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, resp := s3a.lifecycleDeleteMarker(req.Bucket, req.ObjectPath, lifecycleAddressedVersion(req, entry)); resp != nil {
|
||||
return resp, nil
|
||||
}
|
||||
if nullEntry == nil {
|
||||
return done(), nil
|
||||
}
|
||||
return s3a.lifecycleDeleteNullVersion(req, nullEntry, metadataOnly), nil
|
||||
default:
|
||||
err := s3a.WithFilerClient(false, func(c filer_pb.SeaweedFilerClient) error {
|
||||
return s3a.deleteUnversionedObjectWithClient(ctx, c, req.Bucket, req.ObjectPath, metadataOnly)
|
||||
@@ -291,6 +277,77 @@ func (s3a *S3ApiServer) lifecycleDeleteMarkerIf(bucket, object, normalized, expe
|
||||
return false, retryLater("LATEST_CHANGED: createDeleteMarker")
|
||||
}
|
||||
|
||||
// lifecycleNullVersion reads the null object the suspended expiration will
|
||||
// delete. When it is the version validated for expiration, a different or
|
||||
// missing entry resolves the request as stale.
|
||||
func (s3a *S3ApiServer) lifecycleNullVersion(req *s3_lifecycle_pb.LifecycleDeleteRequest, validated *filer_pb.Entry) (*filer_pb.Entry, *s3_lifecycle_pb.LifecycleDeleteResponse) {
|
||||
nullEntry, err := s3a.getObjectEntryRoutedByKey(req.Bucket, req.ObjectPath)
|
||||
if err != nil && !isObjectEntryMiss(err) {
|
||||
return nil, retryLater("TRANSPORT_ERROR: null version lookup: " + err.Error())
|
||||
}
|
||||
if err != nil || !isNullVersionObject(nullEntry, req.ObjectPath) {
|
||||
nullEntry = nil
|
||||
}
|
||||
if lifecycleAddressedVersion(req, validated) == "null" && (nullEntry == nil || !identityMatches(computeEntryIdentity(nullEntry), computeEntryIdentity(validated))) {
|
||||
return nil, noopResolved("STALE_IDENTITY")
|
||||
}
|
||||
return nullEntry, nil
|
||||
}
|
||||
|
||||
// lifecycleDeleteNullVersion deletes the null version once the marker hides
|
||||
// it, even past the attempt deadline. Only the entry read before the marker is
|
||||
// deleted: a null object written since is newer and stays. Lifecycle never
|
||||
// bypasses retention.
|
||||
func (s3a *S3ApiServer) lifecycleDeleteNullVersion(req *s3_lifecycle_pb.LifecycleDeleteRequest, nullEntry *filer_pb.Entry, metadataOnly bool) *s3_lifecycle_pb.LifecycleDeleteResponse {
|
||||
if owner := s3a.routableWriteOwner(req.Bucket, req.ObjectPath); owner != "" {
|
||||
worm, lockErr := s3a.isObjectLockEnabled(req.Bucket)
|
||||
if lockErr != nil {
|
||||
return retryLater("TRANSPORT_ERROR: object lock lookup: " + lockErr.Error())
|
||||
}
|
||||
guard := &filer_pb.WriteCondition{Clauses: []*filer_pb.WriteCondition_Clause{{
|
||||
Kind: filer_pb.WriteCondition_IF_ENTRY_EQUAL,
|
||||
ExpectedEntry: nullEntry,
|
||||
}}}
|
||||
switch code, _ := s3a.routedDeleteNullVersion(owner, req.Bucket, req.ObjectPath, worm, false, metadataOnly, guard); code {
|
||||
case s3err.ErrNone, s3err.ErrPreconditionFailed:
|
||||
return done()
|
||||
case s3err.ErrAccessDenied:
|
||||
return retryLater("ACCESS_DENIED: deleteNullVersion: object lock")
|
||||
default:
|
||||
return retryLater("TRANSPORT_ERROR: routedDeleteNullVersion: " + s3err.GetAPIError(code).Code)
|
||||
}
|
||||
}
|
||||
// Off the ring, writers serialize on the object write lock instead.
|
||||
dir, name := util.NewFullPath(s3a.bucketDir(req.Bucket), req.ObjectPath).DirAndName()
|
||||
var opErr error
|
||||
code := s3a.withObjectWriteLock(req.Bucket, req.ObjectPath, func() s3err.ErrorCode {
|
||||
current, err := s3a.getEntry(dir, name)
|
||||
switch {
|
||||
case errors.Is(err, filer_pb.ErrNotFound):
|
||||
return s3err.ErrPreconditionFailed
|
||||
case err != nil:
|
||||
opErr = err
|
||||
return s3err.ErrInternalError
|
||||
case !identityMatches(computeEntryIdentity(current), computeEntryIdentity(nullEntry)):
|
||||
return s3err.ErrPreconditionFailed
|
||||
}
|
||||
return s3err.ErrNone
|
||||
}, func() s3err.ErrorCode {
|
||||
if opErr = s3a.deleteSpecificObjectVersion(context.Background(), req.Bucket, req.ObjectPath, "null", metadataOnly); opErr != nil {
|
||||
return s3err.ErrInternalError
|
||||
}
|
||||
return s3err.ErrNone
|
||||
})
|
||||
switch {
|
||||
case code == s3err.ErrNone || code == s3err.ErrPreconditionFailed:
|
||||
return done()
|
||||
case opErr != nil:
|
||||
return retryLater("TRANSPORT_ERROR: deleteNullVersion: " + opErr.Error())
|
||||
default:
|
||||
return retryLater("TRANSPORT_ERROR: deleteNullVersion: " + s3err.GetAPIError(code).Code)
|
||||
}
|
||||
}
|
||||
|
||||
// pointerLatestVersion reads the latest version off a .versions pointer the
|
||||
// way getLatestObjectVersion does: a named pointer with its file outranks the
|
||||
// null object, the null-is-latest signal names the null version, and anything
|
||||
|
||||
Reference in new issue
Block a user