mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-28 03:46:24 +00:00
* filer: keep the sentinel when CreateEntry reports an update failure CreateEntry flattened the error UpdateEntry wraps, so errors.Is stopped matching and ErrExistingIsDirectory and ErrExistingIsFile never reached the S3 mapper, which answered a retryable 500 instead. * s3: let a key that is a prefix of other keys be an object S3 keys are flat, so "a/b" and "a/b/c" are independent objects that coexist in either write order. The filer stores a key as a path, so one of them has to live on the directory the other is nested under. Writing the nested key first refused the prefix key outright. Writing it second promoted the file to a directory, which kept its data but lost the key: an empty object left nothing to recognise it by and disappeared, and one with data listed under a trailing slash it never had. Mark the directory that carries such a key, and write the object onto it when the path is already a directory. The mark makes an empty prefix object visible to listings and readable by GET and HEAD, keeps the empty folder cleaner off it, and lists it under the key it was written with. Deleting the key strips the mark back off along with the data. * filer: keep a TTL off a directory that stands for an object An expired entry is deleted a row at a time, so expiring a directory removes it and leaves everything under it unreachable. Promoting a file to a directory carried its TTL across, and a promoted file is exactly the one that has keys nested under it. Drop the TTL on promotion, and leave one an older build wrote alone. The lifecycle worker still expires the object, through the delete that leaves the directory behind. * s3: delete the null version of a key other keys are nested under The routed delete cannot remove an entry that other keys live under, and answered a retryable 500 rather than falling back to the lock path the unversioned delete already falls back to. That path then looked the entry up under the bucket with the whole key as its name, so the demote wrote it back one directory too high and failed as not found. Fall back on any non-precondition error, and split the key before deleting it. Trailing-slash directory markers with children reach the same delete. * filer: keep the sentinel when MkFile and Mkdir report a create failure Same flattening one layer out: every mkFile caller lost the sentinel, so a CopyObject onto a key that other keys are nested under answered a retryable 500 where a PutObject of the same key answers 409. * s3: copy and rename a key that other keys are nested under Such a key is stored on the directory those keys live in, and copy and rename both refused it: the source lookup maps every directory entry to NoSuchKey, so a key a plain GET serves could not be copied or moved, and the destination side refused it as a directory conflict. The source is read through a view of the entry as the object it names. The destination is written the way a PutObject of that key writes it. A rename at either end copies the object's own data across and strips it off the source key rather than going through AtomicRenameEntry, which moves a directory by moving everything under it - the nested keys are not part of what is being renamed.
78 lines
2.7 KiB
Go
78 lines
2.7 KiB
Go
package filer
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestPromoteToPrefixObject covers a key written before the keys nested under it:
|
|
// the file becomes the directory they live in, and has to stay an object of its own.
|
|
func TestPromoteToPrefixObject(t *testing.T) {
|
|
f, store := newTestFilerWithStubStore()
|
|
ctx := context.Background()
|
|
|
|
object := &Entry{
|
|
FullPath: util.FullPath("/buckets/bkt/a/foo"),
|
|
Attr: Attr{
|
|
Mode: 0o644,
|
|
Mime: "text/plain",
|
|
TtlSec: 3600,
|
|
},
|
|
Chunks: []*filer_pb.FileChunk{{FileId: "1,01", Size: 4}},
|
|
Extended: map[string][]byte{s3_constants.SeaweedFSExpiresS3: []byte("true")},
|
|
}
|
|
require.NoError(t, f.CreateEntry(ctx, object, nil, false, false, nil, false, f.MaxFilenameLength))
|
|
|
|
nested := &Entry{FullPath: util.FullPath("/buckets/bkt/a/foo/bar"), Attr: Attr{Mode: 0o644}}
|
|
require.NoError(t, f.CreateEntry(ctx, nested, nil, false, false, nil, false, f.MaxFilenameLength))
|
|
|
|
promoted, err := store.FindEntry(ctx, object.FullPath)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, promoted)
|
|
|
|
assert.True(t, promoted.IsDirectory(), "the nested key needs a directory here")
|
|
assert.Equal(t, object.Chunks, promoted.Chunks, "the object's data stays on it")
|
|
assert.Contains(t, promoted.Extended, s3_constants.SeaweedFSPrefixObject)
|
|
// Expiring the entry deletes the directory row on its own and strands the keys
|
|
// under it, so the promotion gives up the lazy TTL.
|
|
assert.Zero(t, promoted.Attr.TtlSec)
|
|
}
|
|
|
|
// TestExpiredDirectoryIsNotDeletedOnRead pins the other half: a TTL an older build
|
|
// left on a promoted directory must not take the keys under it with it.
|
|
func TestExpiredDirectoryIsNotDeletedOnRead(t *testing.T) {
|
|
f, store := newTestFilerWithStubStore()
|
|
ctx := context.Background()
|
|
|
|
dirPath := util.FullPath("/buckets/bkt/a/foo")
|
|
expired := time.Now().Add(-2 * time.Hour)
|
|
require.NoError(t, store.InsertEntry(ctx, &Entry{
|
|
FullPath: dirPath,
|
|
Attr: Attr{
|
|
Mode: os.ModeDir | 0o755,
|
|
Crtime: expired,
|
|
Mtime: expired,
|
|
TtlSec: 60,
|
|
},
|
|
Extended: map[string][]byte{s3_constants.SeaweedFSExpiresS3: []byte("true")},
|
|
}))
|
|
nested := &Entry{FullPath: dirPath + "/bar", Attr: Attr{Mode: 0o644}}
|
|
require.NoError(t, store.InsertEntry(ctx, nested))
|
|
|
|
found, err := f.FindEntry(ctx, dirPath)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, found, "deleting it here would leave the nested key unreachable")
|
|
|
|
stillThere, err := store.FindEntry(ctx, nested.FullPath)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, stillThere)
|
|
}
|