mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
s3api: answer KeyTooLongError when the filer refuses an object's name (#13349)
* s3api: answer KeyTooLongError when the routed PUT's name is refused The filer checks an entry's name length before its first mutation stores anything, so a routed PUT refused with ENTRY_NAME_TOO_LONG on mutation 0 is a definite refusal, not an ambiguous outcome. Treating it as ambiguous sent a zero-byte PUT, which has no chunks to verify, to 503. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: test a routed PUT refused for its name length Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: keep the filer's error code when a routed mkfile is refused routedMkFile flattened the transaction's error into a string, so callers could not tell a refused name from an internal failure, and a CopyObject to a name the filer refuses answered 500. Wrap the code's sentinel, as CreateEntry does, so the existing error mapping answers KeyTooLongError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: test a routed mkfile keeps the filer's error code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3api: answer KeyTooLongError when a multipart completion's name is refused Completing an upload whose last key segment the filer refuses answered 500 InternalError. The refused create stores nothing, so answer KeyTooLongError as PutObject does. 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
4f6c138beb
commit
18ba10b535
5 files changed
+80
No files matched your search
@@ -976,6 +976,9 @@ func (s3a *S3ApiServer) completeMultipartUpload(r *http.Request, input *s3.Compl
|
||||
if errors.Is(err, errObjectPrecondition) {
|
||||
return s3err.ErrPreconditionFailed
|
||||
}
|
||||
if errors.Is(err, filer_pb.ErrEntryNameTooLong) {
|
||||
return s3err.ErrKeyTooLongError
|
||||
}
|
||||
// The transaction may have committed the object before failing on
|
||||
// the upload removal; a surviving entry references the manifests.
|
||||
if exists, err := s3a.exists(dirName, entryName, false); err != nil || exists {
|
||||
@@ -1074,6 +1077,9 @@ func (s3a *S3ApiServer) completeMultipartUpload(r *http.Request, input *s3.Compl
|
||||
if errors.Is(err, errObjectPrecondition) {
|
||||
return s3err.ErrPreconditionFailed
|
||||
}
|
||||
if errors.Is(err, filer_pb.ErrEntryNameTooLong) {
|
||||
return s3err.ErrKeyTooLongError
|
||||
}
|
||||
// The transaction may have committed the object before failing on
|
||||
// the upload removal; a surviving entry references the manifests.
|
||||
if exists, err := s3a.exists(dirName, entryName, false); err != nil || exists {
|
||||
|
||||
@@ -1268,6 +1268,9 @@ func (s3a *S3ApiServer) putToFiler(r *http.Request, filePath string, dataReader
|
||||
glog.Warningf("putToFiler: routed PUT to %s failed for %s, falling back to lock: %v", owner, filePath, err)
|
||||
case resp.ErrorCode == filer_pb.FilerError_PRECONDITION_FAILED:
|
||||
createCode, routed = s3err.ErrPreconditionFailed, true
|
||||
case resp.ErrorCode == filer_pb.FilerError_ENTRY_NAME_TOO_LONG && resp.FailedMutation != nil && *resp.FailedMutation == 0:
|
||||
// The filer refuses the name before the first mutation stores anything.
|
||||
createCode, routed = s3err.ErrKeyTooLongError, true
|
||||
case resp.Error != "":
|
||||
// A mutation can store the entry before a later step of the
|
||||
// same mutation fails, so even an error from the first mutation
|
||||
|
||||
@@ -222,6 +222,8 @@ type ambiguousPutFiler struct {
|
||||
supersede *filer_pb.Entry
|
||||
txnErr error
|
||||
txnNoApply bool
|
||||
// txnResp, when set, is the transaction's answer and nothing is applied.
|
||||
txnResp *filer_pb.ObjectTransactionResponse
|
||||
// beforeCreate runs inside CreateEntry's lock, before the condition is
|
||||
// evaluated, letting a test land a racing write at the worst moment.
|
||||
// beforeLookup runs inside LookupDirectoryEntry, letting a test delete a
|
||||
@@ -339,6 +341,9 @@ func (f *ambiguousPutFiler) ObjectTransaction(_ context.Context, req *filer_pb.O
|
||||
if f.txnCheck != nil {
|
||||
f.txnCheck(req)
|
||||
}
|
||||
if f.txnResp != nil {
|
||||
return f.txnResp, nil
|
||||
}
|
||||
key := req.LockKey
|
||||
if req.ConditionKey != "" {
|
||||
key = req.ConditionKey
|
||||
@@ -1122,6 +1127,42 @@ func TestPutToFilerRoutedAmbiguousEmptyPutForeignWriteId(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A routed PUT whose name the filer refuses stored nothing, so it answers
|
||||
// KeyTooLongError whatever the body's size, and the uploaded chunks are freed.
|
||||
func TestPutToFilerRoutedNameTooLong(t *testing.T) {
|
||||
for _, body := range []string{"", "hello world"} {
|
||||
t.Run(fmt.Sprintf("%d-byte body", len(body)), func(t *testing.T) {
|
||||
volume := startFakeVolumeServer(t)
|
||||
firstMutation := int32(0)
|
||||
filerImpl := &ambiguousPutFiler{
|
||||
volume: volume,
|
||||
entries: map[string]*filer_pb.Entry{},
|
||||
txnResp: &filer_pb.ObjectTransactionResponse{
|
||||
Error: "mutation 0: entry name too long",
|
||||
ErrorCode: filer_pb.FilerError_ENTRY_NAME_TOO_LONG,
|
||||
FailedMutation: &firstMutation,
|
||||
},
|
||||
}
|
||||
filerAddr := startFakeFiler(t, filerImpl)
|
||||
s3a := newPutTestServer(t, filerAddr)
|
||||
s3a.objectWriteLockClient = cluster.NewLockClient(s3a.option.GrpcDialOption, filerAddr)
|
||||
s3a.objectWriteLockClient.SetRing([]pb.ServerAddress{filerAddr}, 1)
|
||||
|
||||
r := httptest.NewRequest(http.MethodPut, "/b/o", nil)
|
||||
_, code, _ := s3a.putToFiler(r, "/buckets/b/o", strings.NewReader(body), "b", "o", 1, 0, nil, false, "")
|
||||
if code != s3err.ErrKeyTooLongError {
|
||||
t.Fatalf("putToFiler returned %v, want KeyTooLongError", code)
|
||||
}
|
||||
if filerImpl.txnCount != 1 || filerImpl.stores != 0 {
|
||||
t.Fatalf("refused PUT was retried: %d transactions, %d creates", filerImpl.txnCount, filerImpl.stores)
|
||||
}
|
||||
if body != "" && len(volume.deleted()) == 0 {
|
||||
t.Fatal("the refused PUT's chunks were not deleted")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A volume-encrypted chunk must be decrypted before SSE decryption sees it:
|
||||
// fetchChunkData feeds ciphered chunks through the cipher-aware read path and
|
||||
// slices plaintext space, while plain chunks keep streaming range reads.
|
||||
|
||||
@@ -282,6 +282,9 @@ func (s3a *S3ApiServer) routedMkFile(owner pb.ServerAddress, routeKey, parentDir
|
||||
return 0, errUploadRemoved
|
||||
}
|
||||
if resp.Error != "" {
|
||||
if sentinel := filer_pb.FilerErrorToSentinel(resp.ErrorCode); sentinel != nil {
|
||||
return 0, fmt.Errorf("routed mkfile %s/%s: %w", parentDir, name, sentinel)
|
||||
}
|
||||
return 0, fmt.Errorf("routed mkfile %s/%s: %s", parentDir, name, resp.Error)
|
||||
}
|
||||
return resp.LogTsNs, nil
|
||||
|
||||
@@ -2,6 +2,7 @@ package s3api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -657,6 +658,32 @@ func TestRoutedMultipartFinalize(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A routed mkfile the filer refuses keeps the refusal's sentinel, so callers
|
||||
// map it as they map the same refusal from CreateEntry.
|
||||
func TestRoutedMkFileKeepsFilerErrorCode(t *testing.T) {
|
||||
firstMutation := int32(0)
|
||||
fake := &fakeTxnFiler{resp: &filer_pb.ObjectTransactionResponse{
|
||||
Error: "mutation 0: entry name too long",
|
||||
ErrorCode: filer_pb.FilerError_ENTRY_NAME_TOO_LONG,
|
||||
FailedMutation: &firstMutation,
|
||||
}}
|
||||
owner := startFakeFiler(t, fake)
|
||||
s3a := &S3ApiServer{
|
||||
option: &S3ApiServerOption{
|
||||
BucketsPath: "/buckets",
|
||||
GrpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
},
|
||||
}
|
||||
|
||||
_, err := s3a.writeMultipartObject(owner, "s3.object.write:/buckets/b/o", "/buckets/b", "o", nil, nil, nil, nil, "")
|
||||
if !errors.Is(err, filer_pb.ErrEntryNameTooLong) {
|
||||
t.Fatalf("writeMultipartObject returned %v, want ErrEntryNameTooLong", err)
|
||||
}
|
||||
if code := filerErrorToS3Error(err); code != s3err.ErrKeyTooLongError {
|
||||
t.Fatalf("filerErrorToS3Error(%v) = %v, want KeyTooLongError", err, code)
|
||||
}
|
||||
}
|
||||
|
||||
// A non-versioned multipart completion removes .uploads/<id> metadata-only in
|
||||
// the same transaction as the object's PUT.
|
||||
func TestWriteMultipartObjectRemovesUploadDir(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user