snapshot of https://github.com/seaweedfs/seaweedfs.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
This commit is contained in:
460
weed/s3api/s3api_object_handlers_rename.go
Normal file
460
weed/s3api/s3api_object_handlers_rename.go
Normal file
@@ -0,0 +1,460 @@
|
||||
package s3api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
||||
stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var renameSourceConditionalHeaders = sourceConditionalHeaderNames{
|
||||
ifMatch: s3_constants.AmzRenameSourceIfMatch,
|
||||
ifNoneMatch: s3_constants.AmzRenameSourceIfNoneMatch,
|
||||
ifModifiedSince: s3_constants.AmzRenameSourceIfModifiedSince,
|
||||
ifUnmodifiedSince: s3_constants.AmzRenameSourceIfUnmodifiedSince,
|
||||
}
|
||||
|
||||
// RenameObjectHandler implements RenameObject:
|
||||
//
|
||||
// PUT /{bucket}/{destination key}?renameObject
|
||||
// x-amz-rename-source: /{bucket}/{source key}
|
||||
//
|
||||
// The object is moved by the filer's AtomicRenameEntry, so its bytes are never
|
||||
// read or rewritten and its metadata (ETag, tags, SSE keys) travels unchanged.
|
||||
// x-amz-client-token travels with it too, so a rename whose response was lost
|
||||
// answers its own retry instead of the NoSuchKey its vanished source would give.
|
||||
// Versioned buckets are rejected: the move would have to rebuild the .versions
|
||||
// chain, and AWS itself only offers RenameObject on directory buckets, which
|
||||
// cannot be versioned.
|
||||
func (s3a *S3ApiServer) RenameObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||
bucket, dstObject := s3_constants.GetBucketAndObject(r)
|
||||
|
||||
candidates, errCode := renameSourceCandidates(r, bucket)
|
||||
if errCode != s3err.ErrNone {
|
||||
s3err.WriteErrorResponse(w, r, errCode)
|
||||
return
|
||||
}
|
||||
srcObject := s3a.pickRenameSource(bucket, candidates)
|
||||
|
||||
glog.V(3).Infof("RenameObjectHandler %s: %s => %s", bucket, srcObject, dstObject)
|
||||
|
||||
if len(dstObject) > s3_constants.MaxS3ObjectKeyLength {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrKeyTooLongError)
|
||||
return
|
||||
}
|
||||
if err := s3a.validateTableBucketObjectPath(bucket, dstObject); err != nil {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrAccessDenied)
|
||||
return
|
||||
}
|
||||
// A trailing slash names a directory, and renaming one would move a whole
|
||||
// subtree rather than an object.
|
||||
if strings.HasSuffix(dstObject, "/") {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
|
||||
return
|
||||
}
|
||||
if strings.HasSuffix(srcObject, "/") {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey)
|
||||
return
|
||||
}
|
||||
if srcObject == dstObject {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrRenameDestinationSameAsSource)
|
||||
return
|
||||
}
|
||||
|
||||
// The route's Auth middleware only authorized the destination, because that
|
||||
// is what the request URL names. The source arrives in a header and loses
|
||||
// its key, so it needs both read and delete permission checked here.
|
||||
if errCode := s3a.authorizeRenameSource(r, bucket, srcObject); errCode != s3err.ErrNone {
|
||||
s3err.WriteErrorResponse(w, r, errCode)
|
||||
return
|
||||
}
|
||||
|
||||
versioningState, err := s3a.getVersioningState(bucket)
|
||||
if err != nil {
|
||||
if errors.Is(err, filer_pb.ErrNotFound) {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchBucket)
|
||||
return
|
||||
}
|
||||
glog.Errorf("RenameObjectHandler: versioning state for bucket %s: %v", bucket, err)
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
|
||||
return
|
||||
}
|
||||
if versioningState != "" {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
clientToken := r.Header.Get(s3_constants.AmzClientToken)
|
||||
renameSource := r.Header.Get(s3_constants.AmzRenameSource)
|
||||
|
||||
errCode = s3a.withRenameWriteLocks(bucket, srcObject, dstObject, func() s3err.ErrorCode {
|
||||
entry, err := s3a.resolveCopySourceEntry(bucket, srcObject, "", "")
|
||||
srcIsPrefixObject := entry.IsPrefixObject()
|
||||
entry = prefixObjectSource(entry)
|
||||
srcErrCode := classifyCopySourceError(entry, err)
|
||||
|
||||
dstEntry, errCode := s3a.lookupRenameDestination(bucket, dstObject)
|
||||
if errCode != s3err.ErrNone {
|
||||
return errCode
|
||||
}
|
||||
if errCode, settled := retryRenameDecision(dstEntry, clientToken, renameSource, dstObject, srcErrCode); settled {
|
||||
return errCode
|
||||
}
|
||||
if srcErrCode != s3err.ErrNone {
|
||||
return srcErrCode
|
||||
}
|
||||
if errCode := validateSourceConditionalHeaders(r, entry, renameSourceConditionalHeaders); errCode != s3err.ErrNone {
|
||||
return errCode
|
||||
}
|
||||
if errCode := s3a.checkConditionalHeaders(r, bucket, dstObject); errCode != s3err.ErrNone {
|
||||
return errCode
|
||||
}
|
||||
|
||||
// AtomicRenameEntry moves a directory by moving everything under it, and the keys
|
||||
// nested under either end of this rename are not part of what is being renamed.
|
||||
keyHoldsNestedKeys := srcIsPrefixObject || (dstEntry != nil && dstEntry.IsDirectory)
|
||||
if clientToken != "" {
|
||||
s3a.stampRenameToken(bucket, srcObject, dstObject, entry, clientToken, renameSource, keyHoldsNestedKeys)
|
||||
}
|
||||
return s3a.renameObjectEntry(r.Context(), bucket, srcObject, dstObject, entry, keyHoldsNestedKeys)
|
||||
})
|
||||
if errCode != s3err.ErrNone {
|
||||
s3err.WriteErrorResponse(w, r, errCode)
|
||||
return
|
||||
}
|
||||
|
||||
stats_collect.RecordBucketActiveTime(bucket)
|
||||
writeSuccessResponseEmpty(w, r)
|
||||
}
|
||||
|
||||
// renameSourceCandidates reads x-amz-rename-source into the source keys it may
|
||||
// mean, best guess first.
|
||||
//
|
||||
// AWS spells the source both ways: its CLI, Java and Rust examples pass a bare
|
||||
// key, while a second CLI example and the boto3 conditional example pass
|
||||
// bucket/key. A value is therefore read as a literal key first — that is the
|
||||
// form AWS leads with, and it is the only reading that can never name the wrong
|
||||
// object — and, when it is prefixed with the request's own bucket, as that
|
||||
// bucket-qualified form second. There is no cross-bucket reading: RenameObject
|
||||
// moves within one bucket, and the filer refuses to move an entry between two.
|
||||
func renameSourceCandidates(r *http.Request, bucket string) ([]string, s3err.ErrorCode) {
|
||||
rawSource := r.Header.Get(s3_constants.AmzRenameSource)
|
||||
if rawSource == "" {
|
||||
return nil, s3err.ErrInvalidRenameSource
|
||||
}
|
||||
// PathUnescape, not QueryUnescape: the value is a path, where '+' is a
|
||||
// literal plus and not a space.
|
||||
source, err := url.PathUnescape(rawSource)
|
||||
if err != nil {
|
||||
source = rawSource
|
||||
}
|
||||
|
||||
// NormalizeObjectKey drops the leading slash both forms may carry.
|
||||
source = s3_constants.NormalizeObjectKey(source)
|
||||
if source == "" {
|
||||
return nil, s3err.ErrInvalidRenameSource
|
||||
}
|
||||
|
||||
candidates := []string{source}
|
||||
if qualified := strings.TrimPrefix(source, bucket+"/"); qualified != source && qualified != "" {
|
||||
candidates = append(candidates, qualified)
|
||||
}
|
||||
// `.`/`..` segments are collapsed by the filer's path join, so reject them
|
||||
// here as the request URL's own key already is.
|
||||
for _, candidate := range candidates {
|
||||
if !s3_constants.IsValidObjectKey(candidate) {
|
||||
return nil, s3err.ErrInvalidRenameSource
|
||||
}
|
||||
}
|
||||
return candidates, s3err.ErrNone
|
||||
}
|
||||
|
||||
// pickRenameSource resolves which reading of the source header the bucket
|
||||
// actually holds. A single candidate is returned unprobed, so the common bare
|
||||
// key costs no extra lookup; when both readings are possible the one the bucket
|
||||
// holds wins, and when neither does the last is reported missing.
|
||||
//
|
||||
// Only a proven absence moves on to the next reading. A path that holds
|
||||
// something the rename cannot move — a directory, say — is still the path the
|
||||
// caller named, and answering for it beats renaming a different object under
|
||||
// the other reading; so is a path whose lookup merely failed, since a blip must
|
||||
// not be able to redirect a rename.
|
||||
func (s3a *S3ApiServer) pickRenameSource(bucket string, candidates []string) string {
|
||||
for _, candidate := range candidates[:len(candidates)-1] {
|
||||
// A trailing slash never names an object, and never reaches a usable
|
||||
// directory/name split either.
|
||||
if strings.HasSuffix(candidate, "/") {
|
||||
continue
|
||||
}
|
||||
if !renameSourceAbsent(s3a.resolveCopySourceEntry(bucket, candidate, "", "")) {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
return candidates[len(candidates)-1]
|
||||
}
|
||||
|
||||
// renameSourceAbsent reports whether a lookup proved the candidate absent. Only
|
||||
// the filer saying so counts; a lookup that failed for any other reason is not
|
||||
// a proof of absence.
|
||||
func renameSourceAbsent(entry *filer_pb.Entry, err error) bool {
|
||||
if entry != nil {
|
||||
return false
|
||||
}
|
||||
return err == nil || errors.Is(err, filer_pb.ErrNotFound) || status.Code(err) == codes.NotFound
|
||||
}
|
||||
|
||||
func (s3a *S3ApiServer) authorizeRenameSource(r *http.Request, bucket, srcObject string) s3err.ErrorCode {
|
||||
if s3a.iam == nil || !s3a.iam.isEnabled() {
|
||||
return s3err.ErrNone
|
||||
}
|
||||
var identity *Identity
|
||||
if id, ok := s3_constants.GetIdentityFromContext(r).(*Identity); ok {
|
||||
identity = id
|
||||
}
|
||||
// The rename both reads the source object and removes it from its key.
|
||||
if errCode := s3a.iam.AuthorizeCopySource(r, identity, bucket, srcObject, ""); errCode != s3err.ErrNone {
|
||||
return errCode
|
||||
}
|
||||
return s3a.iam.AuthorizeObjectDelete(r, identity, bucket, srcObject, "")
|
||||
}
|
||||
|
||||
// renameTokenValidity bounds how long a committed rename answers for its own
|
||||
// retry. An SDK gives up retrying long before this, so the window covers every
|
||||
// retry there is, while a token that comes back days later no longer stands in
|
||||
// for a move the caller means to happen now.
|
||||
const renameTokenValidity = 24 * time.Hour
|
||||
|
||||
// renameToken is what a rename leaves on the object it moves, so that the same
|
||||
// request replayed after its response was lost can be answered from the
|
||||
// destination instead of from a source that is no longer there.
|
||||
//
|
||||
// Source is the x-amz-rename-source header as it was sent. A retry resends the
|
||||
// request byte for byte, so equality on the raw value recognises it, and any
|
||||
// other value is the token used for a different rename. Dest is the key the
|
||||
// rename wrote, which tells a token that travelled here some other way - on a
|
||||
// CopyObject of a renamed object, say - from one this rename left.
|
||||
type renameToken struct {
|
||||
Token string `json:"token"`
|
||||
Source string `json:"source"`
|
||||
Dest string `json:"dest"`
|
||||
Unix int64 `json:"unix"`
|
||||
}
|
||||
|
||||
type renameTokenVerdict int
|
||||
|
||||
const (
|
||||
// renameTokenUnrelated: the destination carries no live token of this request's.
|
||||
renameTokenUnrelated renameTokenVerdict = iota
|
||||
// renameTokenSameRequest: this very rename already committed here.
|
||||
renameTokenSameRequest
|
||||
// renameTokenReused: the same token was sent for a different rename.
|
||||
renameTokenReused
|
||||
)
|
||||
|
||||
// classifyRenameToken reads what the destination object says about a request
|
||||
// carrying clientToken.
|
||||
func classifyRenameToken(dstEntry *filer_pb.Entry, clientToken, renameSource, dstObject string) renameTokenVerdict {
|
||||
if clientToken == "" || dstEntry == nil {
|
||||
return renameTokenUnrelated
|
||||
}
|
||||
stamped, found := dstEntry.Extended[s3_constants.SeaweedFSRenameToken]
|
||||
if !found {
|
||||
return renameTokenUnrelated
|
||||
}
|
||||
var token renameToken
|
||||
if err := json.Unmarshal(stamped, &token); err != nil {
|
||||
glog.Warningf("RenameObject: unreadable rename token on %s: %v", dstEntry.Name, err)
|
||||
return renameTokenUnrelated
|
||||
}
|
||||
if token.Token != clientToken || token.Dest != dstObject || time.Since(time.Unix(token.Unix, 0)) > renameTokenValidity {
|
||||
return renameTokenUnrelated
|
||||
}
|
||||
if token.Source != renameSource {
|
||||
return renameTokenReused
|
||||
}
|
||||
return renameTokenSameRequest
|
||||
}
|
||||
|
||||
// retryRenameDecision says what to do with a request whose destination carries
|
||||
// a rename token. settled=true means the request is answered (return errCode);
|
||||
// settled=false means continue with the rename.
|
||||
//
|
||||
// A reused token is refused. A token from this very rename is answered as
|
||||
// success only when the source is gone — the move already committed and only
|
||||
// its response was lost. A source that is back is not that retry: the move is
|
||||
// still to be made, and making it is what leaves the caller where it asked to
|
||||
// be, so the decision falls through and the rename proceeds.
|
||||
func retryRenameDecision(dstEntry *filer_pb.Entry, clientToken, renameSource, dstObject string, srcErrCode s3err.ErrorCode) (s3err.ErrorCode, bool) {
|
||||
switch classifyRenameToken(dstEntry, clientToken, renameSource, dstObject) {
|
||||
case renameTokenReused:
|
||||
return s3err.ErrIdempotentParameterMismatch, true
|
||||
case renameTokenSameRequest:
|
||||
if srcErrCode == s3err.ErrNoSuchKey {
|
||||
return s3err.ErrNone, true
|
||||
}
|
||||
}
|
||||
return s3err.ErrNone, false
|
||||
}
|
||||
|
||||
// markRenameToken puts the client token on the entry the rename moves.
|
||||
func markRenameToken(srcEntry *filer_pb.Entry, clientToken, renameSource, dstObject string) error {
|
||||
stamped, err := json.Marshal(renameToken{Token: clientToken, Source: renameSource, Dest: dstObject, Unix: time.Now().Unix()})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if srcEntry.Extended == nil {
|
||||
srcEntry.Extended = make(map[string][]byte)
|
||||
}
|
||||
srcEntry.Extended[s3_constants.SeaweedFSRenameToken] = stamped
|
||||
return nil
|
||||
}
|
||||
|
||||
// stampRenameToken records the client token on the object about to be moved, so
|
||||
// that the move carries it to the destination.
|
||||
//
|
||||
// The token goes on before the move rather than after it: a move that commits
|
||||
// and then loses its token is exactly the failure the token exists to cover,
|
||||
// while a token left on a move that never happened simply rides along with the
|
||||
// next attempt. Failing to record it costs this rename its idempotency and
|
||||
// nothing else, so the move goes ahead either way.
|
||||
func (s3a *S3ApiServer) stampRenameToken(bucket, srcObject, dstObject string, srcEntry *filer_pb.Entry, clientToken, renameSource string, keyHoldsNestedKeys bool) {
|
||||
// The ETag as it stands now, read before the token joins it.
|
||||
expected := map[string][]byte{s3_constants.ExtETagKey: srcEntry.Extended[s3_constants.ExtETagKey]}
|
||||
|
||||
if err := markRenameToken(srcEntry, clientToken, renameSource, dstObject); err != nil {
|
||||
glog.Errorf("RenameObject %s: rename token for %s: %v", bucket, srcObject, err)
|
||||
return
|
||||
}
|
||||
|
||||
// renameKeyHoldingNestedKeys writes the destination out of this entry, so the
|
||||
// token reaches it without a write of its own.
|
||||
if keyHoldsNestedKeys {
|
||||
return
|
||||
}
|
||||
|
||||
// AtomicRenameEntry moves the entry as the filer holds it, so the token has to
|
||||
// be on the source for the move to carry it. markRenameToken already mutated
|
||||
// srcEntry.Extended in place, so the move carries the token to the destination
|
||||
// whether or not this UpdateEntry succeeds — the write only persists the token
|
||||
// on the source ahead of the move, and a lost write costs idempotency, not
|
||||
// correctness. The precondition keeps the write off an object another gateway
|
||||
// replaced in the meantime.
|
||||
srcDir, _ := util.FullPath(s3a.toFilerPath(bucket, srcObject)).DirAndName()
|
||||
if err := s3a.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
||||
return filer_pb.UpdateEntry(context.Background(), client, &filer_pb.UpdateEntryRequest{
|
||||
Directory: srcDir,
|
||||
Entry: srcEntry,
|
||||
ExpectedExtended: expected,
|
||||
})
|
||||
}); err != nil {
|
||||
glog.Warningf("RenameObject %s: record rename token on %s: %v", bucket, srcObject, err)
|
||||
}
|
||||
}
|
||||
|
||||
// withRenameWriteLocks holds the object write lock of both keys across the
|
||||
// precondition checks and the move. The keys are locked in a fixed order so a
|
||||
// rename in the opposite direction cannot deadlock against this one.
|
||||
func (s3a *S3ApiServer) withRenameWriteLocks(bucket, srcObject, dstObject string, fn func() s3err.ErrorCode) s3err.ErrorCode {
|
||||
first, second := srcObject, dstObject
|
||||
if second < first {
|
||||
first, second = second, first
|
||||
}
|
||||
return s3a.withObjectWriteLock(bucket, first, nil, func() s3err.ErrorCode {
|
||||
return s3a.withObjectWriteLock(bucket, second, nil, fn)
|
||||
})
|
||||
}
|
||||
|
||||
// lookupRenameDestination reads what the destination key already holds. A key
|
||||
// nothing lives at is the ordinary case and comes back as a nil entry.
|
||||
//
|
||||
// The move overwrites an existing destination object. A directory there is not a
|
||||
// conflict: it means other keys are nested under the destination key, and the
|
||||
// object goes onto the directory they live in, the way a PutObject of that key
|
||||
// would put it there.
|
||||
func (s3a *S3ApiServer) lookupRenameDestination(bucket, dstObject string) (*filer_pb.Entry, s3err.ErrorCode) {
|
||||
dstDir, dstName := util.FullPath(s3a.toFilerPath(bucket, dstObject)).DirAndName()
|
||||
|
||||
entry, err := s3a.getEntry(dstDir, dstName)
|
||||
if err != nil {
|
||||
if errors.Is(err, filer_pb.ErrNotFound) {
|
||||
return nil, s3err.ErrNone
|
||||
}
|
||||
glog.Errorf("RenameObject %s: destination %s: %v", bucket, dstObject, err)
|
||||
return nil, s3err.ErrInternalError
|
||||
}
|
||||
return entry, s3err.ErrNone
|
||||
}
|
||||
|
||||
func (s3a *S3ApiServer) renameObjectEntry(ctx context.Context, bucket, srcObject, dstObject string, srcEntry *filer_pb.Entry, keyHoldsNestedKeys bool) s3err.ErrorCode {
|
||||
srcDir, srcName := util.FullPath(s3a.toFilerPath(bucket, srcObject)).DirAndName()
|
||||
dstDir, dstName := util.FullPath(s3a.toFilerPath(bucket, dstObject)).DirAndName()
|
||||
|
||||
if keyHoldsNestedKeys {
|
||||
return s3a.renameKeyHoldingNestedKeys(bucket, srcObject, dstObject, srcEntry)
|
||||
}
|
||||
|
||||
err := s3a.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
||||
_, err := client.AtomicRenameEntry(ctx, &filer_pb.AtomicRenameEntryRequest{
|
||||
OldDirectory: srcDir,
|
||||
OldName: srcName,
|
||||
NewDirectory: dstDir,
|
||||
NewName: dstName,
|
||||
})
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("RenameObject %s: %s => %s: %v", bucket, srcObject, dstObject, err)
|
||||
if isTransientFilerError(err) {
|
||||
return s3err.ErrServiceUnavailable
|
||||
}
|
||||
return s3err.ErrInternalError
|
||||
}
|
||||
return s3err.ErrNone
|
||||
}
|
||||
|
||||
// renameKeyHoldingNestedKeys moves an object when either key of the rename is one
|
||||
// other keys are nested under. Such a key is stored on the directory those keys live
|
||||
// in, which has to stay where it is, so the object's own data is written at the
|
||||
// destination and then stripped off the source key - the entry survives as the plain
|
||||
// directory it also is. Both keys are held under their write locks for the whole
|
||||
// move, so no other S3 write interleaves; a crash between the two steps leaves the
|
||||
// destination written and the source still there, which a retry settles.
|
||||
func (s3a *S3ApiServer) renameKeyHoldingNestedKeys(bucket, srcObject, dstObject string, srcEntry *filer_pb.Entry) s3err.ErrorCode {
|
||||
dstPath := util.FullPath(s3a.toFilerPath(bucket, dstObject))
|
||||
dstDir, dstName := dstPath.DirAndName()
|
||||
|
||||
chunks, err := s3a.copyChunks(srcEntry, string(dstPath))
|
||||
if err != nil {
|
||||
glog.Errorf("RenameObject %s: copy chunks of %s: %v", bucket, srcObject, err)
|
||||
return s3err.ErrInternalError
|
||||
}
|
||||
|
||||
if err := s3a.mkFile(dstDir, dstName, chunks, func(entry *filer_pb.Entry) {
|
||||
copyEntryToTarget(entry, srcEntry)
|
||||
entry.Chunks = chunks
|
||||
}); err != nil {
|
||||
glog.Errorf("RenameObject %s: write %s: %v", bucket, dstObject, err)
|
||||
s3a.deleteOrphanedChunks(chunks)
|
||||
return filerErrorToS3Error(err)
|
||||
}
|
||||
|
||||
// The destination holds copies now, so the source's own chunks go with it.
|
||||
srcDir, srcName := util.FullPath(s3a.toFilerPath(bucket, srcObject)).DirAndName()
|
||||
if err := s3a.rmObject(context.Background(), srcDir, srcName, true, false); err != nil {
|
||||
glog.Errorf("RenameObject %s: strip %s: %v", bucket, srcObject, err)
|
||||
return s3err.ErrInternalError
|
||||
}
|
||||
return s3err.ErrNone
|
||||
}
|
||||
Reference in New Issue
Block a user