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
547 lines
21 KiB
Go
547 lines
21 KiB
Go
package example
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/http"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
v1credentials "github.com/aws/aws-sdk-go/aws/credentials"
|
|
v1signer "github.com/aws/aws-sdk-go/aws/signer/v4"
|
|
"github.com/aws/aws-sdk-go/service/s3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestS3PrefixObjectKeys covers keys that are a strict prefix of other keys: S3's
|
|
// namespace is flat, so "collision/foo" and "collision/foo/bar" are independent
|
|
// objects that coexist in either write order.
|
|
func TestS3PrefixObjectKeys(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("Skipping integration test in short mode")
|
|
}
|
|
|
|
cluster, err := startMiniCluster(t)
|
|
require.NoError(t, err)
|
|
defer cluster.Stop()
|
|
|
|
put := func(t *testing.T, bucket, key string, body []byte) {
|
|
t.Helper()
|
|
_, err := cluster.s3Client.PutObject(&s3.PutObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String(key),
|
|
Body: bytes.NewReader(body),
|
|
})
|
|
require.NoError(t, err, "put %s", key)
|
|
}
|
|
// read checks both paths a client reaches an object by, since a directory entry
|
|
// carrying an object is served by neither the directory nor the plain object path
|
|
// alone.
|
|
read := func(t *testing.T, bucket, key string, want []byte) {
|
|
t.Helper()
|
|
head, err := cluster.s3Client.HeadObject(&s3.HeadObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String(key),
|
|
})
|
|
require.NoError(t, err, "head %s", key)
|
|
assert.Equal(t, int64(len(want)), aws.Int64Value(head.ContentLength), "head %s", key)
|
|
|
|
get, err := cluster.s3Client.GetObject(&s3.GetObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String(key),
|
|
})
|
|
require.NoError(t, err, "get %s", key)
|
|
defer get.Body.Close()
|
|
got, err := io.ReadAll(get.Body)
|
|
require.NoError(t, err, "read %s", key)
|
|
assert.Equal(t, want, got, "get %s", key)
|
|
}
|
|
// gone checks the key answers as absent rather than lingering on a directory
|
|
// entry that outlived the object.
|
|
gone := func(t *testing.T, bucket, key string) {
|
|
t.Helper()
|
|
_, err := cluster.s3Client.GetObject(&s3.GetObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String(key),
|
|
})
|
|
var missing awserr.RequestFailure
|
|
require.ErrorAs(t, err, &missing, "get %s", key)
|
|
assert.Equal(t, http.StatusNotFound, missing.StatusCode(), "get %s", key)
|
|
|
|
_, err = cluster.s3Client.HeadObject(&s3.HeadObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String(key),
|
|
})
|
|
require.ErrorAs(t, err, &missing, "head %s", key)
|
|
assert.Equal(t, http.StatusNotFound, missing.StatusCode(), "head %s", key)
|
|
}
|
|
listKeys := func(t *testing.T, bucket string) []string {
|
|
t.Helper()
|
|
resp, err := cluster.s3Client.ListObjectsV2(&s3.ListObjectsV2Input{Bucket: aws.String(bucket)})
|
|
require.NoError(t, err)
|
|
keys := collectKeys(resp.Contents)
|
|
sort.Strings(keys)
|
|
return keys
|
|
}
|
|
|
|
body := []byte("prefix object")
|
|
// Distinct bodies, so a read that resolves to the wrong entry cannot pass.
|
|
nested := []byte("nested under the prefix object")
|
|
|
|
// The reported order: the nested key is written first, so the prefix key has to
|
|
// land on a path the filer already holds a directory at.
|
|
t.Run("ChildFirst", func(t *testing.T) {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-child-first-")
|
|
put(t, bucket, "collision/foo/bar", nested)
|
|
put(t, bucket, "collision/foo", body)
|
|
|
|
assert.Equal(t, []string{"collision/foo", "collision/foo/bar"}, listKeys(t, bucket))
|
|
read(t, bucket, "collision/foo", body)
|
|
read(t, bucket, "collision/foo/bar", nested)
|
|
})
|
|
|
|
// The opposite order used to keep the prefix key's data but hide the key.
|
|
t.Run("PrefixFirst", func(t *testing.T) {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-first-")
|
|
put(t, bucket, "collision/foo", body)
|
|
put(t, bucket, "collision/foo/bar", nested)
|
|
|
|
assert.Equal(t, []string{"collision/foo", "collision/foo/bar"}, listKeys(t, bucket))
|
|
read(t, bucket, "collision/foo", body)
|
|
read(t, bucket, "collision/foo/bar", nested)
|
|
})
|
|
|
|
// An empty object leaves no chunks, content or mime behind, so it is the case a
|
|
// promoted directory carries no other trace of.
|
|
t.Run("EmptyObject", func(t *testing.T) {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-empty-")
|
|
put(t, bucket, "a/foo/bar", nil)
|
|
put(t, bucket, "a/foo", nil)
|
|
put(t, bucket, "b/foo", nil)
|
|
put(t, bucket, "b/foo/bar", nil)
|
|
|
|
assert.Equal(t, []string{"a/foo", "a/foo/bar", "b/foo", "b/foo/bar"}, listKeys(t, bucket))
|
|
read(t, bucket, "a/foo", []byte{})
|
|
read(t, bucket, "b/foo", []byte{})
|
|
})
|
|
|
|
// The key has no trailing slash, and the keys nested under it still roll up into
|
|
// their own CommonPrefix.
|
|
t.Run("Delimiter", func(t *testing.T) {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-delimiter-")
|
|
put(t, bucket, "collision/foo/bar", nested)
|
|
put(t, bucket, "collision/foo", body)
|
|
put(t, bucket, "collision/other", body)
|
|
|
|
resp, err := cluster.s3Client.ListObjectsV2(&s3.ListObjectsV2Input{
|
|
Bucket: aws.String(bucket),
|
|
Prefix: aws.String("collision/"),
|
|
Delimiter: aws.String("/"),
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
keys := collectKeys(resp.Contents)
|
|
sort.Strings(keys)
|
|
assert.Equal(t, []string{"collision/foo", "collision/other"}, keys)
|
|
assert.Equal(t, []string{"collision/foo/"}, collectPrefixes(resp.CommonPrefixes))
|
|
|
|
// Listing the prefix itself names only what is under it.
|
|
resp, err = cluster.s3Client.ListObjectsV2(&s3.ListObjectsV2Input{
|
|
Bucket: aws.String(bucket),
|
|
Prefix: aws.String("collision/foo/"),
|
|
Delimiter: aws.String("/"),
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []string{"collision/foo/bar"}, collectKeys(resp.Contents))
|
|
assert.Empty(t, collectPrefixes(resp.CommonPrefixes))
|
|
})
|
|
|
|
// The key and the CommonPrefix its nested keys fold into come off one filer
|
|
// entry, so a page boundary must not drop either of them.
|
|
t.Run("Paged", func(t *testing.T) {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-paged-")
|
|
for _, key := range []string{"foo", "foo/bar", "foobar", "other", "zed", "zed/a"} {
|
|
put(t, bucket, key, body)
|
|
}
|
|
|
|
for _, maxKeys := range []int64{1, 2, 3, 4, 5} {
|
|
var keys, prefixes []string
|
|
var token *string
|
|
for page := 0; page < 12; page++ {
|
|
resp, err := cluster.s3Client.ListObjectsV2(&s3.ListObjectsV2Input{
|
|
Bucket: aws.String(bucket),
|
|
Delimiter: aws.String("/"),
|
|
MaxKeys: aws.Int64(maxKeys),
|
|
ContinuationToken: token,
|
|
})
|
|
require.NoError(t, err)
|
|
// One entry over the budget is the documented same-entry exception;
|
|
// anything more means the unsigned budget wrapped.
|
|
assert.LessOrEqual(t, int64(len(resp.Contents)+len(resp.CommonPrefixes)), maxKeys+1,
|
|
"maxKeys=%d page %d", maxKeys, page)
|
|
keys = append(keys, collectKeys(resp.Contents)...)
|
|
prefixes = append(prefixes, collectPrefixes(resp.CommonPrefixes)...)
|
|
if !aws.BoolValue(resp.IsTruncated) {
|
|
token = nil
|
|
break
|
|
}
|
|
token = resp.NextContinuationToken
|
|
require.NotNil(t, token, "a truncated page must name where to resume")
|
|
}
|
|
require.Nil(t, token, "maxKeys=%d did not finish", maxKeys)
|
|
assert.Equal(t, []string{"foo", "foobar", "other", "zed"}, keys, "maxKeys=%d", maxKeys)
|
|
assert.Equal(t, []string{"foo/", "zed/"}, prefixes, "maxKeys=%d", maxKeys)
|
|
}
|
|
})
|
|
|
|
// Versioning reaches a prefix object from two directions: a suspended bucket
|
|
// writes the null version at the key's own path, and a bucket versioned later
|
|
// finds one already sitting there. Both leave a key that is a directory with
|
|
// version history beside it.
|
|
t.Run("Versioned", func(t *testing.T) {
|
|
setVersioning := func(t *testing.T, bucket, status string) {
|
|
t.Helper()
|
|
_, err := cluster.s3Client.PutBucketVersioning(&s3.PutBucketVersioningInput{
|
|
Bucket: aws.String(bucket),
|
|
VersioningConfiguration: &s3.VersioningConfiguration{Status: aws.String(status)},
|
|
})
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
// Both write orders, in a bucket that is versioned and in one where versioning
|
|
// was suspended - the suspended one is the case that writes at the key's path.
|
|
for _, state := range []string{"Enabled", "Suspended"} {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-"+strings.ToLower(state)+"-")
|
|
setVersioning(t, bucket, "Enabled")
|
|
if state == "Suspended" {
|
|
setVersioning(t, bucket, "Suspended")
|
|
}
|
|
put(t, bucket, "child/foo/bar", nested)
|
|
put(t, bucket, "child/foo", body)
|
|
put(t, bucket, "prefix/foo", body)
|
|
put(t, bucket, "prefix/foo/bar", nested)
|
|
|
|
assert.Equal(t, []string{"child/foo", "child/foo/bar", "prefix/foo", "prefix/foo/bar"},
|
|
listKeys(t, bucket), state)
|
|
for _, key := range []string{"child/foo", "prefix/foo"} {
|
|
read(t, bucket, key, body)
|
|
}
|
|
for _, key := range []string{"child/foo/bar", "prefix/foo/bar"} {
|
|
read(t, bucket, key, nested)
|
|
}
|
|
}
|
|
|
|
// A prefix object written before versioning is the key's null version. Removing
|
|
// that version by id must not take the keys nested under it with it.
|
|
bucket := createTestBucket(t, cluster, "test-prefix-nullversion-")
|
|
put(t, bucket, "collision/foo/bar", nested)
|
|
put(t, bucket, "collision/foo", body)
|
|
setVersioning(t, bucket, "Enabled")
|
|
newer := []byte("written after versioning was enabled")
|
|
versioned, err := cluster.s3Client.PutObject(&s3.PutObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String("collision/foo"),
|
|
Body: bytes.NewReader(newer),
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
for _, v := range []struct {
|
|
id string
|
|
want []byte
|
|
}{{"null", body}, {aws.StringValue(versioned.VersionId), newer}} {
|
|
got, err := cluster.s3Client.GetObject(&s3.GetObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String("collision/foo"),
|
|
VersionId: aws.String(v.id),
|
|
})
|
|
require.NoError(t, err, "get version %s", v.id)
|
|
body, err := io.ReadAll(got.Body)
|
|
require.NoError(t, err)
|
|
got.Body.Close()
|
|
assert.Equal(t, v.want, body, "get version %s", v.id)
|
|
}
|
|
|
|
_, err = cluster.s3Client.DeleteObject(&s3.DeleteObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String("collision/foo"),
|
|
VersionId: aws.String("null"),
|
|
})
|
|
require.NoError(t, err, "the null version sits on a directory other keys live in")
|
|
|
|
read(t, bucket, "collision/foo", newer)
|
|
read(t, bucket, "collision/foo/bar", nested)
|
|
remaining, err := cluster.s3Client.ListObjectVersions(&s3.ListObjectVersionsInput{
|
|
Bucket: aws.String(bucket),
|
|
Prefix: aws.String("collision/foo"),
|
|
})
|
|
require.NoError(t, err)
|
|
for _, v := range remaining.Versions {
|
|
if aws.StringValue(v.Key) != "collision/foo" {
|
|
// collision/foo/bar predates versioning too, and keeps its null version.
|
|
continue
|
|
}
|
|
assert.NotEqual(t, "null", aws.StringValue(v.VersionId), "the null version was deleted")
|
|
}
|
|
})
|
|
|
|
// The two listings walk the tree differently, and a prefix object is the entry
|
|
// they disagree about: it is a directory the version listing descends through and
|
|
// a key at the same time. They have to name the same keys and the same prefixes.
|
|
t.Run("VersionListingMatchesObjectListing", func(t *testing.T) {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-parity-")
|
|
for _, key := range []string{"foo", "foo/bar", "other", "a/foo", "a/foo/bar", "a/z"} {
|
|
put(t, bucket, key, body)
|
|
}
|
|
|
|
for _, q := range []struct{ prefix, delimiter string }{
|
|
{"", ""},
|
|
{"foo/", ""},
|
|
{"a/", ""},
|
|
{"a/foo/", ""},
|
|
{"", "/"},
|
|
{"a/", "/"},
|
|
} {
|
|
name := "prefix=" + q.prefix + " delimiter=" + q.delimiter
|
|
|
|
objects, err := cluster.s3Client.ListObjectsV2(&s3.ListObjectsV2Input{
|
|
Bucket: aws.String(bucket),
|
|
Prefix: aws.String(q.prefix),
|
|
Delimiter: aws.String(q.delimiter),
|
|
})
|
|
require.NoError(t, err, name)
|
|
|
|
versions, err := cluster.s3Client.ListObjectVersions(&s3.ListObjectVersionsInput{
|
|
Bucket: aws.String(bucket),
|
|
Prefix: aws.String(q.prefix),
|
|
Delimiter: aws.String(q.delimiter),
|
|
})
|
|
require.NoError(t, err, name)
|
|
|
|
versionKeys := make([]string, 0, len(versions.Versions))
|
|
for _, v := range versions.Versions {
|
|
versionKeys = append(versionKeys, aws.StringValue(v.Key))
|
|
}
|
|
versionPrefixes := make([]string, 0, len(versions.CommonPrefixes))
|
|
for _, p := range versions.CommonPrefixes {
|
|
versionPrefixes = append(versionPrefixes, aws.StringValue(p.Prefix))
|
|
}
|
|
sort.Strings(versionKeys)
|
|
sort.Strings(versionPrefixes)
|
|
|
|
objectKeys := collectKeys(objects.Contents)
|
|
objectPrefixes := collectPrefixes(objects.CommonPrefixes)
|
|
sort.Strings(objectKeys)
|
|
sort.Strings(objectPrefixes)
|
|
|
|
assert.Equal(t, objectKeys, versionKeys, "keys, %s", name)
|
|
assert.Equal(t, objectPrefixes, versionPrefixes, "prefixes, %s", name)
|
|
}
|
|
})
|
|
|
|
// A prefix object written before versioning is the key's null version, so the
|
|
// version written after it has to take the latest flag off it.
|
|
t.Run("VersionedAfterPrefixObject", func(t *testing.T) {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-versioned-")
|
|
put(t, bucket, "collision/foo/bar", nested)
|
|
put(t, bucket, "collision/foo", body)
|
|
_, err := cluster.s3Client.PutBucketVersioning(&s3.PutBucketVersioningInput{
|
|
Bucket: aws.String(bucket),
|
|
VersioningConfiguration: &s3.VersioningConfiguration{Status: aws.String("Enabled")},
|
|
})
|
|
require.NoError(t, err)
|
|
newer := []byte("written after versioning was enabled")
|
|
put(t, bucket, "collision/foo", newer)
|
|
|
|
resp, err := cluster.s3Client.ListObjectVersions(&s3.ListObjectVersionsInput{Bucket: aws.String(bucket)})
|
|
require.NoError(t, err)
|
|
|
|
latest := map[string]int{}
|
|
var nullSize int64 = -1
|
|
for _, v := range resp.Versions {
|
|
if aws.BoolValue(v.IsLatest) {
|
|
latest[aws.StringValue(v.Key)]++
|
|
}
|
|
if aws.StringValue(v.Key) == "collision/foo" && aws.StringValue(v.VersionId) == "null" {
|
|
nullSize = aws.Int64Value(v.Size)
|
|
assert.False(t, aws.BoolValue(v.IsLatest), "the newer version is the latest one")
|
|
}
|
|
}
|
|
assert.Equal(t, 1, latest["collision/foo"], "exactly one version of a key is the latest")
|
|
assert.Equal(t, int64(len(body)), nullSize, "the null version keeps the prefix object's size")
|
|
read(t, bucket, "collision/foo", newer)
|
|
read(t, bucket, "collision/foo/bar", nested)
|
|
})
|
|
|
|
// A key that other keys are nested under is a copy source and a copy destination
|
|
// like any other. The keys nested under either end are not part of the copy.
|
|
t.Run("Copy", func(t *testing.T) {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-copy-")
|
|
copyObject := func(t *testing.T, src, dst string) {
|
|
t.Helper()
|
|
_, err := cluster.s3Client.CopyObject(&s3.CopyObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String(dst),
|
|
CopySource: aws.String(bucket + "/" + src),
|
|
})
|
|
require.NoError(t, err, "copy %s to %s", src, dst)
|
|
}
|
|
|
|
put(t, bucket, "collision/foo", body)
|
|
put(t, bucket, "collision/foo/bar", nested)
|
|
|
|
// Out of a prefix object, into a key of its own.
|
|
copyObject(t, "collision/foo", "plain")
|
|
read(t, bucket, "plain", body)
|
|
read(t, bucket, "collision/foo", body)
|
|
read(t, bucket, "collision/foo/bar", nested)
|
|
|
|
// Into a key that other keys are nested under.
|
|
put(t, bucket, "target/child", nested)
|
|
copyObject(t, "plain", "target")
|
|
read(t, bucket, "target", body)
|
|
read(t, bucket, "target/child", nested)
|
|
|
|
// And between two of them.
|
|
put(t, bucket, "other", []byte("copied between prefix keys"))
|
|
copyObject(t, "other", "collision/foo")
|
|
read(t, bucket, "collision/foo", []byte("copied between prefix keys"))
|
|
read(t, bucket, "collision/foo/bar", nested)
|
|
|
|
assert.Equal(t, []string{"collision/foo", "collision/foo/bar", "other", "plain", "target", "target/child"},
|
|
listKeys(t, bucket))
|
|
})
|
|
|
|
// Rename moves the object off the key without moving the keys nested under it,
|
|
// which is not what the filer's atomic rename of a directory would do.
|
|
t.Run("Rename", func(t *testing.T) {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-rename-")
|
|
renameObject := func(t *testing.T, src, dst string) {
|
|
t.Helper()
|
|
req, _ := http.NewRequest(http.MethodPut, cluster.s3Endpoint+"/"+bucket+"/"+dst+"?renameObject=", nil)
|
|
req.Header.Set("x-amz-rename-source", "/"+bucket+"/"+src)
|
|
signer := v1signer.NewSigner(v1credentials.NewStaticCredentials(testAccessKey, testSecretKey, ""))
|
|
_, err := signer.Sign(req, nil, "s3", testRegion, time.Now())
|
|
require.NoError(t, err)
|
|
|
|
resp, err := (&http.Client{Timeout: 20 * time.Second}).Do(req)
|
|
require.NoError(t, err, "rename %s to %s", src, dst)
|
|
defer resp.Body.Close()
|
|
io.Copy(io.Discard, resp.Body)
|
|
require.Equal(t, http.StatusOK, resp.StatusCode, "rename %s to %s", src, dst)
|
|
}
|
|
|
|
put(t, bucket, "collision/foo", body)
|
|
put(t, bucket, "collision/foo/bar", nested)
|
|
|
|
// Off a prefix object: the key goes, the keys under it stay.
|
|
renameObject(t, "collision/foo", "moved")
|
|
read(t, bucket, "moved", body)
|
|
read(t, bucket, "collision/foo/bar", nested)
|
|
gone(t, bucket, "collision/foo")
|
|
|
|
// Onto a key other keys are nested under.
|
|
put(t, bucket, "target/child", nested)
|
|
renameObject(t, "moved", "target")
|
|
read(t, bucket, "target", body)
|
|
read(t, bucket, "target/child", nested)
|
|
gone(t, bucket, "moved")
|
|
|
|
assert.Equal(t, []string{"collision/foo/bar", "target", "target/child"}, listKeys(t, bucket))
|
|
})
|
|
|
|
// A directory SeaweedFS keeps its own state in is not a prefix a key can be
|
|
// stored on: the object would replace that state with its own.
|
|
t.Run("ReservedDirectory", func(t *testing.T) {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-reserved-")
|
|
_, err := cluster.s3Client.PutBucketVersioning(&s3.PutBucketVersioningInput{
|
|
Bucket: aws.String(bucket),
|
|
VersioningConfiguration: &s3.VersioningConfiguration{Status: aws.String("Enabled")},
|
|
})
|
|
require.NoError(t, err)
|
|
put(t, bucket, "foo", body)
|
|
_, err = cluster.s3Client.PutBucketVersioning(&s3.PutBucketVersioningInput{
|
|
Bucket: aws.String(bucket),
|
|
VersioningConfiguration: &s3.VersioningConfiguration{Status: aws.String("Suspended")},
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
_, err = cluster.s3Client.PutObject(&s3.PutObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String("foo.versions"),
|
|
Body: bytes.NewReader(body),
|
|
})
|
|
// Not just any error: a permanently impossible write must not come back as a
|
|
// 500 the SDK retries.
|
|
var refused awserr.RequestFailure
|
|
require.ErrorAs(t, err, &refused, "the version history of foo is not a prefix of foo.versions")
|
|
assert.Equal(t, http.StatusConflict, refused.StatusCode())
|
|
assert.Equal(t, "ExistingObjectIsDirectory", refused.Code())
|
|
|
|
versions, err := cluster.s3Client.ListObjectVersions(&s3.ListObjectVersionsInput{Bucket: aws.String(bucket)})
|
|
require.NoError(t, err)
|
|
require.Len(t, versions.Versions, 1)
|
|
assert.Equal(t, "foo", aws.StringValue(versions.Versions[0].Key))
|
|
read(t, bucket, "foo", body)
|
|
|
|
// The multipart staging folder is the other one, and an in-flight upload has
|
|
// to survive the attempt.
|
|
staging := createTestBucket(t, cluster, "test-prefix-uploads-")
|
|
created, err := cluster.s3Client.CreateMultipartUpload(&s3.CreateMultipartUploadInput{
|
|
Bucket: aws.String(staging),
|
|
Key: aws.String("mp.bin"),
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
_, err = cluster.s3Client.PutObject(&s3.PutObjectInput{
|
|
Bucket: aws.String(staging),
|
|
Key: aws.String(".uploads"),
|
|
Body: bytes.NewReader(body),
|
|
})
|
|
require.ErrorAs(t, err, &refused, "the multipart staging folder is not a prefix of .uploads")
|
|
assert.Equal(t, http.StatusConflict, refused.StatusCode())
|
|
assert.Equal(t, "ExistingObjectIsDirectory", refused.Code())
|
|
|
|
uploads, err := cluster.s3Client.ListMultipartUploads(&s3.ListMultipartUploadsInput{Bucket: aws.String(staging)})
|
|
require.NoError(t, err)
|
|
require.Len(t, uploads.Uploads, 1)
|
|
assert.Equal(t, "mp.bin", aws.StringValue(uploads.Uploads[0].Key))
|
|
_, err = cluster.s3Client.AbortMultipartUpload(&s3.AbortMultipartUploadInput{
|
|
Bucket: aws.String(staging),
|
|
Key: aws.String("mp.bin"),
|
|
UploadId: created.UploadId,
|
|
})
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
// Either key can be deleted without touching the other.
|
|
t.Run("Delete", func(t *testing.T) {
|
|
bucket := createTestBucket(t, cluster, "test-prefix-delete-")
|
|
put(t, bucket, "collision/foo/bar", nested)
|
|
put(t, bucket, "collision/foo", body)
|
|
|
|
_, err := cluster.s3Client.DeleteObject(&s3.DeleteObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String("collision/foo"),
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []string{"collision/foo/bar"}, listKeys(t, bucket))
|
|
read(t, bucket, "collision/foo/bar", nested)
|
|
gone(t, bucket, "collision/foo")
|
|
|
|
put(t, bucket, "collision/foo", body)
|
|
_, err = cluster.s3Client.DeleteObject(&s3.DeleteObjectInput{
|
|
Bucket: aws.String(bucket),
|
|
Key: aws.String("collision/foo/bar"),
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []string{"collision/foo"}, listKeys(t, bucket))
|
|
read(t, bucket, "collision/foo", body)
|
|
gone(t, bucket, "collision/foo/bar")
|
|
})
|
|
}
|