mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* test/postgres_flat: S3 against a filer on the postgres_flat store A weed mini whose filer.toml enables postgres_flat in a schema of its own. Objects, listings, copies, multipart uploads, versions and bucket deletion are checked through S3 and against the rows of the bucket's table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * test/postgres_flat: a FUSE mount against the postgres_flat store Files, a directory longer than a listing page, renames, hard and symbolic links, tree removal and a bucket made through the mount, checked against the rows, then read back by a second mount with an empty metadata cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * ci: run the postgres_flat S3 and FUSE tests against Postgres Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * ci: run the postgres_flat tests on pull requests to any branch Like the S3 workflows, so a stacked pull request runs them too, and only when the code they reach changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * test/postgres_flat: fail fast when weed mini or the mount exits ProcessState is only set by Wait, which ran only at cleanup, so a mini or mount that died at startup was noticed only at the 45s or 90s deadline. Reap each command as it starts and check for its exit while waiting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci: run the postgres_flat tests on changes anywhere under weed/ The tests run master, volume, filer, S3 and a mount, so changes in packages such as weed/pb, weed/wdclient or weed/credential reach them too. Match the FUSE integration workflow and also trigger on the fusermount action the job uses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test/postgres_flat: versioned buckets on the postgres_flat store Versions and delete markers are rows under the key's .versions folder in the bucket's table. Covers version listings in one page and one version a page, delete markers, promoting the previous version, the null version under suspended versioning, and dropping the table once every version and the bucket are deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * ci: run the S3 versioning suite on a postgres_flat filer The whole test/s3/versioning suite, stress tests included, against a weed mini whose filer.toml enables postgres_flat. The job first checks that filemeta has the flat layout, so a filer on its default store cannot pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * test/postgres_flat: set up shared objects before the subtests The S3 and versioning suites wrote their objects and the second bucket inside the first subtest, so running one later subtest with -run left the version ids empty and panicked. The parent test now writes them and the subtests only check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test/postgres_flat: helpers fail the test that calls them paths, tableExists, count, filerList, start and mount take the caller's *testing.T, so a failure inside a subtest fails that subtest instead of calling FailNow on the parent and stopping its siblings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK * ci: wait for the filemeta table before the versioning suite Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test/postgres_flat: POSIX subtests set up their own fixtures Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test/postgres_flat: absent versions must answer 404 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
199 lines
8.1 KiB
Go
199 lines
8.1 KiB
Go
package postgres_flat
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
|
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestS3(t *testing.T) {
|
|
c := startCluster(t)
|
|
client := c.s3Client()
|
|
ctx := context.Background()
|
|
bucket := "pgflat-s3"
|
|
|
|
put := func(t *testing.T, bkt, key, body string) {
|
|
t.Helper()
|
|
_, err := client.PutObject(ctx, &s3.PutObjectInput{Bucket: aws.String(bkt), Key: aws.String(key), Body: strings.NewReader(body)})
|
|
require.NoError(t, err, "put %s", key)
|
|
}
|
|
get := func(t *testing.T, bkt, key string) string {
|
|
t.Helper()
|
|
out, err := client.GetObject(ctx, &s3.GetObjectInput{Bucket: aws.String(bkt), Key: aws.String(key)})
|
|
require.NoError(t, err, "get %s", key)
|
|
defer out.Body.Close()
|
|
data, err := io.ReadAll(out.Body)
|
|
require.NoError(t, err)
|
|
return string(data)
|
|
}
|
|
listAll := func(t *testing.T, in s3.ListObjectsV2Input) (keys, prefixes []string) {
|
|
t.Helper()
|
|
in.Bucket = aws.String(bucket)
|
|
p := s3.NewListObjectsV2Paginator(client, &in)
|
|
for p.HasMorePages() {
|
|
page, err := p.NextPage(ctx)
|
|
require.NoError(t, err)
|
|
for _, o := range page.Contents {
|
|
keys = append(keys, aws.ToString(o.Key))
|
|
}
|
|
for _, cp := range page.CommonPrefixes {
|
|
prefixes = append(prefixes, aws.ToString(cp.Prefix))
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
_, err := client.CreateBucket(ctx, &s3.CreateBucketInput{Bucket: aws.String(bucket)})
|
|
require.NoError(t, err)
|
|
eventually(t, "the bucket has a table", func() bool { return c.tableExists(t, bucket) })
|
|
|
|
deep := strings.Repeat(strings.Repeat("k", 200)+"/", 5) + "deep.txt"
|
|
keys := []string{
|
|
"top.txt",
|
|
"a/x.txt",
|
|
"a/b/c.txt",
|
|
"a/b/d.txt",
|
|
"a+b=c.txt",
|
|
"dir with space/f %_!.txt",
|
|
"日本/語.txt",
|
|
deep,
|
|
}
|
|
sorted := append([]string(nil), keys...)
|
|
sort.Strings(sorted)
|
|
for _, k := range keys {
|
|
put(t, bucket, k, "body of "+k)
|
|
}
|
|
|
|
vb := "pgflat-versioned"
|
|
_, err = client.CreateBucket(ctx, &s3.CreateBucketInput{Bucket: aws.String(vb)})
|
|
require.NoError(t, err)
|
|
_, err = client.PutBucketVersioning(ctx, &s3.PutBucketVersioningInput{Bucket: aws.String(vb),
|
|
VersioningConfiguration: &types.VersioningConfiguration{Status: types.BucketVersioningStatusEnabled}})
|
|
require.NoError(t, err)
|
|
|
|
t.Run("objects are rows keyed by their key", func(t *testing.T) {
|
|
for _, k := range keys {
|
|
require.Equal(t, "body of "+k, get(t, bucket, k))
|
|
}
|
|
rows := c.paths(t, bucket, "/")
|
|
for _, k := range keys {
|
|
require.Contains(t, rows, "/"+k)
|
|
}
|
|
require.Contains(t, rows, "/a/b", "parent directories are rows too")
|
|
require.Empty(t, c.paths(t, "filemeta", "/buckets/"+bucket+"/"), "bucket entries stay out of the default table")
|
|
})
|
|
|
|
t.Run("list", func(t *testing.T) {
|
|
got, _ := listAll(t, s3.ListObjectsV2Input{})
|
|
require.Equal(t, sorted, got, "recursive listing in key order")
|
|
got, _ = listAll(t, s3.ListObjectsV2Input{MaxKeys: aws.Int32(2)})
|
|
require.Equal(t, sorted, got, "recursive listing in pages of two")
|
|
|
|
require.Equal(t, []string{"a", "a+b=c.txt", "dir with space", deep[:200], "top.txt", "日本"}, c.filerList(t, "/buckets/"+bucket, 2))
|
|
|
|
got, prefixes := listAll(t, s3.ListObjectsV2Input{Delimiter: aws.String("/")})
|
|
require.Equal(t, []string{"a+b=c.txt", "top.txt"}, got)
|
|
require.Equal(t, []string{"a/", "dir with space/", deep[:201], "日本/"}, prefixes)
|
|
|
|
got, prefixes = listAll(t, s3.ListObjectsV2Input{Prefix: aws.String("a/"), Delimiter: aws.String("/"), MaxKeys: aws.Int32(1)})
|
|
require.Equal(t, []string{"a/x.txt"}, got)
|
|
require.Equal(t, []string{"a/b/"}, prefixes)
|
|
|
|
got, _ = listAll(t, s3.ListObjectsV2Input{Prefix: aws.String("a/b/")})
|
|
require.Equal(t, []string{"a/b/c.txt", "a/b/d.txt"}, got)
|
|
got, _ = listAll(t, s3.ListObjectsV2Input{Prefix: aws.String("a/b/d")})
|
|
require.Equal(t, []string{"a/b/d.txt"}, got)
|
|
got, _ = listAll(t, s3.ListObjectsV2Input{StartAfter: aws.String("a/b/c.txt")})
|
|
require.Equal(t, sorted[sort.SearchStrings(sorted, "a/b/c.txt")+1:], got)
|
|
got, _ = listAll(t, s3.ListObjectsV2Input{Prefix: aws.String("dir with space/f %_")})
|
|
require.Equal(t, []string{"dir with space/f %_!.txt"}, got)
|
|
})
|
|
|
|
t.Run("overwrite, copy and delete", func(t *testing.T) {
|
|
put(t, bucket, "a/x.txt", "replaced")
|
|
require.Equal(t, "replaced", get(t, bucket, "a/x.txt"))
|
|
require.Equal(t, 1, c.count(t, `SELECT count(*) FROM "`+bucket+`" WHERE path = '/a/x.txt'`))
|
|
|
|
_, err := client.CopyObject(ctx, &s3.CopyObjectInput{Bucket: aws.String(bucket), Key: aws.String("copied/x.txt"), CopySource: aws.String(bucket + "/a/x.txt")})
|
|
require.NoError(t, err)
|
|
require.Equal(t, "replaced", get(t, bucket, "copied/x.txt"))
|
|
require.Contains(t, c.paths(t, bucket, "/copied/"), "/copied/x.txt")
|
|
|
|
_, err = client.DeleteObject(ctx, &s3.DeleteObjectInput{Bucket: aws.String(bucket), Key: aws.String("copied/x.txt")})
|
|
require.NoError(t, err)
|
|
require.NotContains(t, c.paths(t, bucket, "/copied/"), "/copied/x.txt")
|
|
_, err = client.HeadObject(ctx, &s3.HeadObjectInput{Bucket: aws.String(bucket), Key: aws.String("copied/x.txt")})
|
|
require.Error(t, err)
|
|
|
|
_, err = client.DeleteObjects(ctx, &s3.DeleteObjectsInput{Bucket: aws.String(bucket), Delete: &types.Delete{Objects: []types.ObjectIdentifier{
|
|
{Key: aws.String("a/b/c.txt")}, {Key: aws.String("a/b/d.txt")},
|
|
}}})
|
|
require.NoError(t, err)
|
|
require.Empty(t, c.paths(t, bucket, "/a/b/"))
|
|
got, _ := listAll(t, s3.ListObjectsV2Input{Prefix: aws.String("a/")})
|
|
require.Equal(t, []string{"a/x.txt"}, got)
|
|
})
|
|
|
|
t.Run("multipart upload", func(t *testing.T) {
|
|
key := "multi/part.bin"
|
|
created, err := client.CreateMultipartUpload(ctx, &s3.CreateMultipartUploadInput{Bucket: aws.String(bucket), Key: aws.String(key)})
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, c.paths(t, bucket, "/.uploads/"), "the upload lives in the bucket table")
|
|
parts := [][]byte{bytes.Repeat([]byte{'1'}, 5<<20), []byte("tail")}
|
|
var completed []types.CompletedPart
|
|
for i, p := range parts {
|
|
out, err := client.UploadPart(ctx, &s3.UploadPartInput{Bucket: aws.String(bucket), Key: aws.String(key), UploadId: created.UploadId,
|
|
PartNumber: aws.Int32(int32(i + 1)), Body: bytes.NewReader(p)})
|
|
require.NoError(t, err)
|
|
completed = append(completed, types.CompletedPart{ETag: out.ETag, PartNumber: aws.Int32(int32(i + 1))})
|
|
}
|
|
_, err = client.CompleteMultipartUpload(ctx, &s3.CompleteMultipartUploadInput{Bucket: aws.String(bucket), Key: aws.String(key), UploadId: created.UploadId,
|
|
MultipartUpload: &types.CompletedMultipartUpload{Parts: completed}})
|
|
require.NoError(t, err)
|
|
require.Equal(t, string(parts[0])+string(parts[1]), get(t, bucket, key))
|
|
require.Contains(t, c.paths(t, bucket, "/multi/"), "/multi/part.bin")
|
|
eventually(t, "the upload folder is gone", func() bool {
|
|
return len(c.paths(t, bucket, "/.uploads/"+aws.ToString(created.UploadId))) == 0
|
|
})
|
|
})
|
|
|
|
t.Run("versioning", func(t *testing.T) {
|
|
first, err := client.PutObject(ctx, &s3.PutObjectInput{Bucket: aws.String(vb), Key: aws.String("doc/v.txt"), Body: strings.NewReader("one")})
|
|
require.NoError(t, err)
|
|
put(t, vb, "doc/v.txt", "two")
|
|
require.Equal(t, "two", get(t, vb, "doc/v.txt"))
|
|
|
|
out, err := client.GetObject(ctx, &s3.GetObjectInput{Bucket: aws.String(vb), Key: aws.String("doc/v.txt"), VersionId: first.VersionId})
|
|
require.NoError(t, err)
|
|
data, err := io.ReadAll(out.Body)
|
|
out.Body.Close()
|
|
require.NoError(t, err)
|
|
require.Equal(t, "one", string(data))
|
|
|
|
versions, err := client.ListObjectVersions(ctx, &s3.ListObjectVersionsInput{Bucket: aws.String(vb)})
|
|
require.NoError(t, err)
|
|
require.Len(t, versions.Versions, 2)
|
|
require.True(t, c.tableExists(t, vb))
|
|
})
|
|
|
|
t.Run("delete bucket drops its table", func(t *testing.T) {
|
|
keys, _ := listAll(t, s3.ListObjectsV2Input{})
|
|
for _, k := range keys {
|
|
_, err := client.DeleteObject(ctx, &s3.DeleteObjectInput{Bucket: aws.String(bucket), Key: aws.String(k)})
|
|
require.NoError(t, err)
|
|
}
|
|
_, err := client.DeleteBucket(ctx, &s3.DeleteBucketInput{Bucket: aws.String(bucket)})
|
|
require.NoError(t, err)
|
|
eventually(t, "the bucket table is dropped", func() bool { return !c.tableExists(t, bucket) })
|
|
require.True(t, c.tableExists(t, vb), "other buckets keep their tables")
|
|
})
|
|
}
|