mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
* s3api: free the parts a multipart completion does not name prepareMultipartCompletionState skipped every entry of the upload directory whose part number the request does not name: it was neither a part of the object nor one of the unused entries freed with their data. The completion then removes the upload directory metadata-only, since the object's chunks are its parts' chunks, so the skipped parts' chunks stayed on the volume servers with nothing referencing them until a volume.fsck purge. Once the upload is completed they cannot be listed, completed or aborted any more. The completion now keeps those entries aside and, once its object is committed and the upload directory is gone, deletes their chunks by file id, resolving manifest chunks first. They are not freed before the commit, as the unused attempts are on the routed paths: until a completion succeeds the upload stays open with all its parts, and the commit transaction can still refuse the write. When another completion of the upload owns the commit (metadataOnlyCleanup), its object can hold them, and they are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: give the unrequested-part cleanup one deadline and check the committed object first The client waits for the completion it already committed, so the cleanup of the parts the request did not name gets one deadline, unrequestedPartsCleanupTimeout, instead of a lookup timeout for each part with manifests: the chunks of the parts without manifests are deleted first, then manifests are resolved part by part while time is left. deleteOrphanedChunksWithContext passes the deadline to the volume lookups and deletes; deleteOrphanedChunks keeps its behaviour. A completion without a ring owner commits under the object lock without the upload-directory precondition, so a routed completion of the same upload can commit after it with a list that names those parts, and remove the directory. The cleanup now frees them only when the key's current object is this completion's commit (this upload, the same chunks), checked once the directory is gone, when no routed completion can commit any more. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: deleteOrphanedChunks takes the context its lookups and deletes use Fold deleteOrphanedChunksWithContext into deleteOrphanedChunks instead of keeping a second name; the existing callers pass context.Background(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: check the entry the completion wrote, under the cleanup deadline The check before freeing the unrequested parts resolved the object by its key, outside the cleanup deadline. A key ending in "/" is written inside the directory it names ("dir/" at dir/dir), so the check read another entry and kept the parts, and a filer that stopped answering after the commit could hold the completion without a limit. The completion now records where it writes its object (the version file on a versioned bucket), and the cleanup reads that entry back, from the write owner when there is one, under the same deadline as the deletes. Each part whose manifests resolve is deleted before the next manifest is read, so a read that runs out the deadline no longer strands the parts resolved before it. The cleanup's filer reads, that check and deleteOrphanedChunks' volume lookup, go through withFilerClient with the deadline, so the deadline running out is not booked as a failure of the filer and does not open its circuit for other requests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
60 lines
2.3 KiB
Go
60 lines
2.3 KiB
Go
package s3api
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"math"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
)
|
|
|
|
// saveManifestChunk stores manifest blobs, assigning volumes against the
|
|
// object's filer path so bucket placement rules apply.
|
|
func (s3a *S3ApiServer) saveManifestChunk(filePath string, bucket string, ttlSec int32) filer.SaveDataAsChunkFunctionType {
|
|
collection := ""
|
|
if s3a.option.FilerGroup != "" {
|
|
collection = s3a.getCollectionName(bucket)
|
|
}
|
|
return func(reader io.Reader, name string, offset int64, tsNs int64, expectedDataSize uint64) (*filer_pb.FileChunk, error) {
|
|
return filer.SaveGatewayDataAsChunk(filer.GatewayChunkUploadRequest{
|
|
FilerClient: s3a,
|
|
Reader: reader,
|
|
FullPath: filePath,
|
|
Offset: offset,
|
|
TsNs: tsNs,
|
|
Collection: collection,
|
|
TtlSec: ttlSec,
|
|
DataCenter: s3a.option.DataCenter,
|
|
Cipher: s3a.cipher,
|
|
})
|
|
}
|
|
}
|
|
|
|
// manifestizeChunks folds a large flat chunk list into manifest chunks. A
|
|
// failed fold falls back to the flat list, which is still a correct object.
|
|
func (s3a *S3ApiServer) manifestizeChunks(filePath string, bucket string, ttlSec int32, chunks []*filer_pb.FileChunk) []*filer_pb.FileChunk {
|
|
folded, err := filer.MaybeManifestize(s3a.saveManifestChunk(filePath, bucket, ttlSec), func(orphaned []*filer_pb.FileChunk) { s3a.deleteOrphanedChunks(context.Background(), orphaned) }, chunks)
|
|
if err != nil {
|
|
glog.V(0).Infof("MaybeManifestize %s: %v", filePath, err)
|
|
}
|
|
return folded
|
|
}
|
|
|
|
// flattenManifestChunks resolves manifest chunks into flat data chunks, cut to
|
|
// each manifest's span since the flat list no longer carries it, returning the
|
|
// resolved-away manifests for callers that must delete the superseded blobs
|
|
// once they own the data chunks.
|
|
func (s3a *S3ApiServer) flattenManifestChunks(ctx context.Context, entry *filer_pb.Entry) ([]*filer_pb.FileChunk, error) {
|
|
if entry == nil || !filer.HasChunkManifest(entry.GetChunks()) {
|
|
return nil, nil
|
|
}
|
|
dataChunks, manifestChunks, err := filer.ResolveChunkManifest(ctx, s3a.createLookupFileIdFunction(), entry.GetChunks(), 0, math.MaxInt64, s3a.filerClient, true)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
entry.Chunks = dataChunks
|
|
return manifestChunks, nil
|
|
}
|