mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +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>
201 lines
7.6 KiB
Go
201 lines
7.6 KiB
Go
package postgres_flat
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
|
|
"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 TestS3Versioning(t *testing.T) {
|
|
c := startCluster(t)
|
|
client := c.s3Client()
|
|
ctx := context.Background()
|
|
bucket := "pgflat-versioned"
|
|
b := aws.String(bucket)
|
|
|
|
put := func(t *testing.T, key, body string) string {
|
|
t.Helper()
|
|
out, err := client.PutObject(ctx, &s3.PutObjectInput{Bucket: b, Key: aws.String(key), Body: strings.NewReader(body)})
|
|
require.NoError(t, err, "put %s", key)
|
|
return aws.ToString(out.VersionId)
|
|
}
|
|
get := func(t *testing.T, key, versionId string) (string, error) {
|
|
t.Helper()
|
|
in := &s3.GetObjectInput{Bucket: b, Key: aws.String(key)}
|
|
if versionId != "" {
|
|
in.VersionId = aws.String(versionId)
|
|
}
|
|
out, err := client.GetObject(ctx, in)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer out.Body.Close()
|
|
data, err := io.ReadAll(out.Body)
|
|
require.NoError(t, err)
|
|
return string(data), nil
|
|
}
|
|
mustGet := func(t *testing.T, key, versionId string) string {
|
|
t.Helper()
|
|
body, err := get(t, key, versionId)
|
|
require.NoError(t, err, "get %s %s", key, versionId)
|
|
return body
|
|
}
|
|
type version struct {
|
|
key, id string
|
|
latest bool
|
|
marker bool
|
|
}
|
|
listVersions := func(t *testing.T, prefix string, maxKeys int32) []version {
|
|
t.Helper()
|
|
in := &s3.ListObjectVersionsInput{Bucket: b, Prefix: aws.String(prefix)}
|
|
if maxKeys > 0 {
|
|
in.MaxKeys = aws.Int32(maxKeys)
|
|
}
|
|
var all []version
|
|
for {
|
|
out, err := client.ListObjectVersions(ctx, in)
|
|
require.NoError(t, err)
|
|
for _, v := range out.Versions {
|
|
all = append(all, version{aws.ToString(v.Key), aws.ToString(v.VersionId), aws.ToBool(v.IsLatest), false})
|
|
}
|
|
for _, m := range out.DeleteMarkers {
|
|
all = append(all, version{aws.ToString(m.Key), aws.ToString(m.VersionId), aws.ToBool(m.IsLatest), true})
|
|
}
|
|
if !aws.ToBool(out.IsTruncated) {
|
|
return all
|
|
}
|
|
in.KeyMarker, in.VersionIdMarker = out.NextKeyMarker, out.NextVersionIdMarker
|
|
}
|
|
}
|
|
listKeys := func(t *testing.T, delimiter string) (keys, prefixes []string) {
|
|
t.Helper()
|
|
in := &s3.ListObjectsV2Input{Bucket: b}
|
|
if delimiter != "" {
|
|
in.Delimiter = aws.String(delimiter)
|
|
}
|
|
out, err := client.ListObjectsV2(ctx, in)
|
|
require.NoError(t, err)
|
|
for _, o := range out.Contents {
|
|
keys = append(keys, aws.ToString(o.Key))
|
|
}
|
|
for _, p := range out.CommonPrefixes {
|
|
prefixes = append(prefixes, aws.ToString(p.Prefix))
|
|
}
|
|
return
|
|
}
|
|
notFound := func(t *testing.T, key, versionId string) {
|
|
t.Helper()
|
|
_, err := get(t, key, versionId)
|
|
var re *awshttp.ResponseError
|
|
require.ErrorAs(t, err, &re, "get %s %s", key, versionId)
|
|
require.Equal(t, http.StatusNotFound, re.HTTPStatusCode(), "get %s %s", key, versionId)
|
|
}
|
|
|
|
_, err := client.CreateBucket(ctx, &s3.CreateBucketInput{Bucket: b})
|
|
require.NoError(t, err)
|
|
eventually(t, "the bucket has a table", func() bool { return c.tableExists(t, bucket) })
|
|
_, err = client.PutBucketVersioning(ctx, &s3.PutBucketVersioningInput{Bucket: b,
|
|
VersioningConfiguration: &types.VersioningConfiguration{Status: types.BucketVersioningStatusEnabled}})
|
|
require.NoError(t, err)
|
|
|
|
var docIds, topIds []string
|
|
for i := 1; i <= 3; i++ {
|
|
docIds = append(docIds, put(t, "doc/v.txt", "doc "+string(rune('0'+i))))
|
|
}
|
|
for i := 1; i <= 2; i++ {
|
|
topIds = append(topIds, put(t, "top.txt", "top "+string(rune('0'+i))))
|
|
}
|
|
|
|
t.Run("each version is a row under the key's .versions folder", func(t *testing.T) {
|
|
rows := c.paths(t, bucket, "/")
|
|
for _, id := range docIds {
|
|
require.NotEmpty(t, id)
|
|
require.Contains(t, rows, "/doc/v.txt.versions/v_"+id)
|
|
}
|
|
for _, id := range topIds {
|
|
require.Contains(t, rows, "/top.txt.versions/v_"+id)
|
|
}
|
|
require.Equal(t, "doc 3", mustGet(t, "doc/v.txt", ""))
|
|
for i, id := range docIds {
|
|
require.Equal(t, "doc "+string(rune('1'+i)), mustGet(t, "doc/v.txt", id))
|
|
}
|
|
require.Empty(t, c.paths(t, "filemeta", "/buckets/"+bucket+"/"), "versions stay out of the default table")
|
|
})
|
|
|
|
t.Run("listings", func(t *testing.T) {
|
|
all := listVersions(t, "", 0)
|
|
require.Equal(t, []version{
|
|
{"doc/v.txt", docIds[2], true, false}, {"doc/v.txt", docIds[1], false, false}, {"doc/v.txt", docIds[0], false, false},
|
|
{"top.txt", topIds[1], true, false}, {"top.txt", topIds[0], false, false},
|
|
}, all)
|
|
require.Equal(t, all, listVersions(t, "", 1), "one version a page")
|
|
require.Equal(t, all[:3], listVersions(t, "doc/", 0))
|
|
|
|
keys, _ := listKeys(t, "")
|
|
require.Equal(t, []string{"doc/v.txt", "top.txt"}, keys, ".versions folders are not keys")
|
|
keys, prefixes := listKeys(t, "/")
|
|
require.Equal(t, []string{"top.txt"}, keys)
|
|
require.Equal(t, []string{"doc/"}, prefixes)
|
|
})
|
|
|
|
t.Run("a delete marker hides the key until it is deleted", func(t *testing.T) {
|
|
out, err := client.DeleteObject(ctx, &s3.DeleteObjectInput{Bucket: b, Key: aws.String("doc/v.txt")})
|
|
require.NoError(t, err)
|
|
require.True(t, aws.ToBool(out.DeleteMarker))
|
|
markerId := aws.ToString(out.VersionId)
|
|
require.Contains(t, c.paths(t, bucket, "/doc/v.txt.versions/"), "/doc/v.txt.versions/v_"+markerId)
|
|
|
|
notFound(t, "doc/v.txt", "")
|
|
require.Equal(t, "doc 2", mustGet(t, "doc/v.txt", docIds[1]))
|
|
keys, _ := listKeys(t, "")
|
|
require.Equal(t, []string{"top.txt"}, keys)
|
|
require.Equal(t, version{"doc/v.txt", markerId, true, true}, listVersions(t, "doc/", 0)[3])
|
|
|
|
_, err = client.DeleteObject(ctx, &s3.DeleteObjectInput{Bucket: b, Key: aws.String("doc/v.txt"), VersionId: aws.String(markerId)})
|
|
require.NoError(t, err)
|
|
require.NotContains(t, c.paths(t, bucket, "/doc/v.txt.versions/"), "/doc/v.txt.versions/v_"+markerId)
|
|
require.Equal(t, "doc 3", mustGet(t, "doc/v.txt", ""))
|
|
})
|
|
|
|
t.Run("deleting the latest version promotes the one before", func(t *testing.T) {
|
|
_, err := client.DeleteObject(ctx, &s3.DeleteObjectInput{Bucket: b, Key: aws.String("doc/v.txt"), VersionId: aws.String(docIds[2])})
|
|
require.NoError(t, err)
|
|
require.NotContains(t, c.paths(t, bucket, "/doc/v.txt.versions/"), "/doc/v.txt.versions/v_"+docIds[2])
|
|
notFound(t, "doc/v.txt", docIds[2])
|
|
require.Equal(t, "doc 2", mustGet(t, "doc/v.txt", ""))
|
|
require.Equal(t, []version{{"doc/v.txt", docIds[1], true, false}, {"doc/v.txt", docIds[0], false, false}}, listVersions(t, "doc/", 0))
|
|
})
|
|
|
|
t.Run("suspended versioning writes the null version", func(t *testing.T) {
|
|
_, err := client.PutBucketVersioning(ctx, &s3.PutBucketVersioningInput{Bucket: b,
|
|
VersioningConfiguration: &types.VersioningConfiguration{Status: types.BucketVersioningStatusSuspended}})
|
|
require.NoError(t, err)
|
|
put(t, "top.txt", "top null")
|
|
put(t, "top.txt", "top null again")
|
|
require.Equal(t, "top null again", mustGet(t, "top.txt", ""))
|
|
require.Equal(t, "top null again", mustGet(t, "top.txt", "null"))
|
|
require.Equal(t, "top 1", mustGet(t, "top.txt", topIds[0]))
|
|
require.ElementsMatch(t, []version{{"top.txt", "null", true, false}, {"top.txt", topIds[1], false, false}, {"top.txt", topIds[0], false, false}},
|
|
listVersions(t, "top", 0))
|
|
})
|
|
|
|
t.Run("deleting every version and the bucket drops its table", func(t *testing.T) {
|
|
for _, v := range listVersions(t, "", 0) {
|
|
_, err := client.DeleteObject(ctx, &s3.DeleteObjectInput{Bucket: b, Key: aws.String(v.key), VersionId: aws.String(v.id)})
|
|
require.NoError(t, err, "delete %s %s", v.key, v.id)
|
|
}
|
|
require.Empty(t, listVersions(t, "", 0))
|
|
_, err := client.DeleteBucket(ctx, &s3.DeleteBucketInput{Bucket: b})
|
|
require.NoError(t, err)
|
|
eventually(t, "the bucket table is dropped", func() bool { return !c.tableExists(t, bucket) })
|
|
})
|
|
}
|