mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-07 20:47:46 +01:00
* s3tables: refuse a table or view location another record holds A create, register, update or rename could name a location at, under or above another catalog record's files, including the files a renamed table left under its old name. The new record then loaded that table's metadata, had credentials vended for its files, and could purge them on drop. Each of those writes now scans the bucket's records and refuses a root another record claims, and a drop of a record sharing its files is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: check a table's location before writing to it REST create and stage-create write a metadata file, and stage-create vends write credentials, before the catalog registers the table, so the create gate now also validates the location and refuses one another record holds. RegisterTable runs the same gate before it reads the metadata file, instead of reading first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: keep a dropped location another record holds DropTable and DropView purge the dropped record's location after the catalog delete. A view recorded at a table's location took that table's directory, record included. The purge now leaves a location another record still holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: authorize CreateTable before reporting the namespace A caller without CreateTable got 404 for a missing namespace, 403 for an existing one and 500 with decoder text for an unreadable one. The grant is now evaluated against the bucket first, and only a caller that passes learns the namespace is missing or unreadable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg maintenance: skip a table whose files another record shares Orphan removal and snapshot expiry delete what a table's metadata does not reference. For two records over one location that deletes the other's files, so detection leaves such tables alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: count another record's catalog entry as claimed A table keeping its files elsewhere still owns its entry directory, and a view recorded there would take that entry with it on drop. The ownership check now refuses a root at, above or under another record's entry too. Maintenance still compares files only, so a table created over a renamed table's old name does not stop that table being maintained. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: check a claimed location again once the record is written Two creates, or a create and an update moving a root, could both read the same root free and both land. A create now checks again after writing its still-marked record and backs out if another record claims the root, and an update that moved its root checks again after the write and puts the previous metadata back. Of two racing writers at least one sees the other. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: enable stage-create in the location ownership test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg maintenance: check for a shared location again before removing orphans A job can run long after its table was scheduled, or come from a detector that never checked, so remove_orphans reads the bucket's records itself and leaves the files alone when another record shares the table's location. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: check a renamed record's new root again once it is written A record without a location moves its root with its name, and was checked only before the rename wrote the destination, so a create landing on that root in between could share it. The rename now checks again with the destination written and backs out, like a create. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: put a moved record back when its location cannot be checked again An update that moved its root kept the move when the check after the write failed to list the bucket, so a racing writer that relied on that check could share the root. The move is now undone as it is when the root is taken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: hold a moved record's old root until the move lands An update moving a record's root wrote the new metadata first and put the old metadata back when the check that followed found the new root taken. The old root was free in between, so a create racing for it could pass its own check and then share it with the restored record. The update now stores the metadata it is about to write beside the current one, so the record holds both roots, checks the new root with that reservation in place, and only then switches the metadata. A move that backs out drops the reservation without touching the metadata, and an update that keeps its root clears a reservation a crashed move left behind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: test a move racing another update of the record Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: drop a move's reservation when a rename or delete takes the record A rename or a decoupled delete that took a record while an update held its move reservation left the reservation on the old name, where the move could no longer clear it, and later creates of that name were refused as taken. Both now clear it with the record's other attributes, and a failed rename does not put it back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: register a table from metadata under its own location The Spark register test registered a live table's metadata file under a second name, which now fails because both records would own the source's files. It checks that refusal instead, and registers a copy uploaded under the new table's own directory, with its location pointing there, to cover reading and writing a registered table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
362 lines
17 KiB
Go
362 lines
17 KiB
Go
package s3tables
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables/s3tablestest"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
func renameLocation(rel string) string {
|
|
return "s3://" + renameTestBucket + "/" + rel
|
|
}
|
|
|
|
// A table's files belong to one catalog record. A create, register, update or
|
|
// view naming a location at, under or above another record's files is refused,
|
|
// and so is one naming the files a renamed table left under its old name.
|
|
func TestLocationOwnedByOneRecord(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
bucketARN := mustBucketARN(t)
|
|
requireOK(t, m, fs, "CreateNamespace", &CreateNamespaceRequest{TableBucketARN: bucketARN, Namespace: []string{"ns2"}})
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{
|
|
TableBucketARN: bucketARN,
|
|
Namespace: []string{"ns"},
|
|
Name: "own",
|
|
Format: FormatIceberg,
|
|
MetadataLocation: renameLocation("ns/own/metadata/v1.metadata.json"),
|
|
})
|
|
|
|
refused := func(t *testing.T, operation string, input interface{}) {
|
|
t.Helper()
|
|
status, resp := runHandler(t, m, fs.Client, operation, input)
|
|
assert.Equal(t, http.StatusConflict, status, "%s: %+v", operation, resp)
|
|
assert.Equal(t, ErrCodeConflict, resp.Type)
|
|
assert.NotContains(t, resp.Message, "ns/t")
|
|
}
|
|
checkRefusals := func(t *testing.T) {
|
|
for _, location := range []string{
|
|
"ns/t/metadata/v3.metadata.json",
|
|
"ns/t/data/part/metadata/v1.metadata.json",
|
|
"ns/metadata/v1.metadata.json",
|
|
} {
|
|
refused(t, "CreateTable", &CreateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "alias", Format: FormatLance, MetadataLocation: renameLocation(location)})
|
|
refused(t, "RegisterTable", &RegisterTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "alias", MetadataLocation: renameLocation(location)})
|
|
refused(t, "CreateView", &CreateViewRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "alias", MetadataLocation: renameLocation(location)})
|
|
refused(t, "UpdateTable", &UpdateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "own", MetadataVersion: 2, MetadataLocation: renameLocation(location)})
|
|
}
|
|
assert.Nil(t, fs.Get(GetNamespacePath(renameTestBucket, "ns"), "alias"))
|
|
}
|
|
|
|
t.Run("live table", checkRefusals)
|
|
|
|
requireOK(t, m, fs, "RenameTable", &RenameTableRequest{
|
|
TableBucketARN: bucketARN,
|
|
SourceNamespace: []string{"ns"},
|
|
SourceName: "t",
|
|
DestNamespace: []string{"ns2"},
|
|
DestName: "t",
|
|
})
|
|
t.Run("renamed table", func(t *testing.T) {
|
|
checkRefusals(t)
|
|
refused(t, "CreateTable", &CreateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "t", Format: FormatIceberg})
|
|
})
|
|
|
|
t.Run("free locations", func(t *testing.T) {
|
|
requireOK(t, m, fs, "UpdateTable", &UpdateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "own", MetadataVersion: 2, MetadataLocation: renameLocation("ns/own/metadata/v2.metadata.json")})
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "t2", Format: FormatIceberg, MetadataLocation: renameLocation("ns/t2/metadata/v1.metadata.json")})
|
|
requireOK(t, m, fs, "RegisterTable", &RegisterTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "t3", MetadataLocation: renameLocation("ns/t3/metadata/v1.metadata.json")})
|
|
})
|
|
}
|
|
|
|
// A drop of a record that shares its files with another is refused, so the
|
|
// other record keeps them.
|
|
func TestDeleteTableKeepsSharedFiles(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
aliasMeta, err := json.Marshal(tableMetadataInternal{
|
|
Name: "alias",
|
|
Namespace: "ns",
|
|
Format: FormatIceberg,
|
|
OwnerAccountID: DefaultAccountID,
|
|
MetadataVersion: 3,
|
|
MetadataLocation: renameLocation("ns/t/metadata/v3.metadata.json"),
|
|
})
|
|
require.NoError(t, err)
|
|
fs.Put(GetNamespacePath(renameTestBucket, "ns"), "alias", map[string][]byte{
|
|
ExtendedKeyMetadata: aliasMeta,
|
|
ExtendedKeyEntryType: []byte(EntryTypeTable),
|
|
})
|
|
|
|
for _, name := range []string{"alias", "t"} {
|
|
status, resp := runHandler(t, m, fs.Client, "DeleteTable", deleteTableRequest(t, name))
|
|
assert.Equal(t, http.StatusConflict, status, "%s: %+v", name, resp)
|
|
}
|
|
tablePath := GetTablePath(renameTestBucket, "ns", "t")
|
|
assert.NotNil(t, fs.Get(GetNamespacePath(renameTestBucket, "ns"), "t"))
|
|
assert.NotNil(t, fs.Get(path.Join(tablePath, "metadata"), "v3.metadata.json"))
|
|
}
|
|
|
|
// rootRaceClient lands a rival record over the same root the moment a write
|
|
// reaches the record at dir/name, the way a second create that read the root
|
|
// free before this record existed publishes its own.
|
|
type rootRaceClient struct {
|
|
filer_pb.SeaweedFilerClient
|
|
f *s3tablestest.MemFiler
|
|
dir string
|
|
name string
|
|
location string
|
|
planted bool
|
|
then func()
|
|
}
|
|
|
|
func (c *rootRaceClient) plant() {
|
|
if c.planted {
|
|
return
|
|
}
|
|
c.planted = true
|
|
if c.then != nil {
|
|
defer c.then()
|
|
}
|
|
rival, _ := json.Marshal(tableMetadataInternal{Name: "rival", Namespace: "ns", Format: FormatIceberg, MetadataLocation: c.location})
|
|
c.f.Put(c.dir, "rival", map[string][]byte{
|
|
ExtendedKeyMetadata: rival,
|
|
ExtendedKeyEntryType: []byte(EntryTypeTable),
|
|
ExtendedKeyDeleting: []byte(createClaim),
|
|
})
|
|
}
|
|
|
|
func (c *rootRaceClient) UpdateEntry(ctx context.Context, req *filer_pb.UpdateEntryRequest, opts ...grpc.CallOption) (*filer_pb.UpdateEntryResponse, error) {
|
|
resp, err := c.SeaweedFilerClient.UpdateEntry(ctx, req, opts...)
|
|
if err == nil && req.Directory == c.dir && req.Entry.Name == c.name {
|
|
c.plant()
|
|
}
|
|
return resp, err
|
|
}
|
|
|
|
// listFailClient fails every listing once a write reaches the record at
|
|
// dir/name, so the check that follows the write cannot run.
|
|
type listFailClient struct {
|
|
filer_pb.SeaweedFilerClient
|
|
dir string
|
|
name string
|
|
failing bool
|
|
}
|
|
|
|
func (c *listFailClient) UpdateEntry(ctx context.Context, req *filer_pb.UpdateEntryRequest, opts ...grpc.CallOption) (*filer_pb.UpdateEntryResponse, error) {
|
|
resp, err := c.SeaweedFilerClient.UpdateEntry(ctx, req, opts...)
|
|
if err == nil && req.Directory == c.dir && req.Entry.Name == c.name {
|
|
c.failing = true
|
|
}
|
|
return resp, err
|
|
}
|
|
|
|
func (c *listFailClient) ListEntries(ctx context.Context, in *filer_pb.ListEntriesRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[filer_pb.ListEntriesResponse], error) {
|
|
if c.failing {
|
|
return nil, errors.New("listing unavailable")
|
|
}
|
|
return c.SeaweedFilerClient.ListEntries(ctx, in, opts...)
|
|
}
|
|
|
|
// Two writers that both read a root free each check it again once their record
|
|
// is written, so the one that sees the other backs out instead of both landing.
|
|
func TestLocationRaceBacksOut(t *testing.T) {
|
|
nsPath := GetNamespacePath(renameTestBucket, "ns")
|
|
location := renameLocation("ns/shared/metadata/v1.metadata.json")
|
|
|
|
t.Run("create", func(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
client := &rootRaceClient{SeaweedFilerClient: fs.Client, f: fs, dir: nsPath, name: "mine", location: location}
|
|
status, resp := runHandler(t, m, client, "CreateTable", &CreateTableRequest{
|
|
TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "mine", Format: FormatIceberg, MetadataLocation: location,
|
|
})
|
|
assert.Equal(t, http.StatusConflict, status, "%+v", resp)
|
|
require.True(t, client.planted)
|
|
if entry := fs.Get(nsPath, "mine"); entry != nil {
|
|
assert.NotContains(t, entry.Extended, ExtendedKeyMetadata)
|
|
}
|
|
})
|
|
|
|
t.Run("update", func(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
before := fs.Get(nsPath, "t").Extended[ExtendedKeyMetadata]
|
|
client := &rootRaceClient{SeaweedFilerClient: fs.Client, f: fs, dir: nsPath, name: "t", location: location}
|
|
status, resp := runHandler(t, m, client, "UpdateTable", &UpdateTableRequest{
|
|
TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "t", MetadataVersion: 4, MetadataLocation: location,
|
|
})
|
|
assert.Equal(t, http.StatusConflict, status, "%+v", resp)
|
|
require.True(t, client.planted)
|
|
assert.Equal(t, string(before), string(fs.Get(nsPath, "t").Extended[ExtendedKeyMetadata]))
|
|
assert.NotContains(t, fs.Get(nsPath, "t").Extended, ExtendedKeyMoving)
|
|
})
|
|
|
|
// A rival reading the old root while the move is checked still finds it
|
|
// held, so a move that backs out never hands back a root someone took.
|
|
for _, operation := range []string{"UpdateTable", "UpdateView"} {
|
|
t.Run(operation+" keeps its old root while moving", func(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
oldLocation := renameLocation("ns/old/metadata/v1.metadata.json")
|
|
var update interface{}
|
|
if operation == "UpdateTable" {
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "a", Format: FormatIceberg, MetadataLocation: oldLocation})
|
|
update = &UpdateTableRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "a", MetadataVersion: 2, MetadataLocation: location}
|
|
} else {
|
|
requireOK(t, m, fs, "CreateView", &CreateViewRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "a", MetadataLocation: oldLocation})
|
|
update = &UpdateViewRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "a", MetadataVersion: 2, MetadataLocation: location}
|
|
}
|
|
before := fs.Get(nsPath, "a").Extended[ExtendedKeyMetadata]
|
|
var oldRootErr error
|
|
client := &rootRaceClient{SeaweedFilerClient: fs.Client, f: fs, dir: nsPath, name: "a", location: location}
|
|
client.then = func() {
|
|
oldRootErr = checkLocationUnclaimed(context.Background(), fs.Client, renameTestBucket, path.Join(nsPath, "b"), oldLocation)
|
|
}
|
|
status, resp := runHandler(t, m, client, operation, update)
|
|
assert.Equal(t, http.StatusConflict, status, "%+v", resp)
|
|
require.True(t, client.planted)
|
|
assert.ErrorIs(t, oldRootErr, ErrLocationInUse)
|
|
assert.Equal(t, string(before), string(fs.Get(nsPath, "a").Extended[ExtendedKeyMetadata]))
|
|
assert.NotContains(t, fs.Get(nsPath, "a").Extended, ExtendedKeyMoving)
|
|
})
|
|
}
|
|
|
|
// Another update of the record landing while a move is checked cannot
|
|
// leave the record on the root a racing create took.
|
|
for _, other := range []string{"ns/shared/metadata/v2.metadata.json", "ns/old/metadata/v2.metadata.json"} {
|
|
t.Run("update moving under an update to "+other, func(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "a", Format: FormatIceberg, MetadataLocation: renameLocation("ns/old/metadata/v1.metadata.json")})
|
|
client := &rootRaceClient{SeaweedFilerClient: fs.Client, f: fs, dir: nsPath, name: "a", location: location}
|
|
client.then = func() {
|
|
runHandler(t, m, fs.Client, "UpdateTable", &UpdateTableRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "a", MetadataVersion: 3, MetadataLocation: renameLocation(other)})
|
|
}
|
|
status, resp := runHandler(t, m, client, "UpdateTable", &UpdateTableRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "a", MetadataVersion: 2, MetadataLocation: location})
|
|
assert.Equal(t, http.StatusConflict, status, "%+v", resp)
|
|
require.True(t, client.planted)
|
|
assert.False(t, RootClaimed(mustRoots(t, fs), path.Join(nsPath, "rival"), path.Join(nsPath, "shared")))
|
|
assert.NotContains(t, fs.Get(nsPath, "a").Extended, ExtendedKeyMoving)
|
|
})
|
|
}
|
|
|
|
t.Run("update with a failed check", func(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
before := fs.Get(nsPath, "t").Extended[ExtendedKeyMetadata]
|
|
client := &listFailClient{SeaweedFilerClient: fs.Client, dir: nsPath, name: "t"}
|
|
status, resp := runHandler(t, m, client, "UpdateTable", &UpdateTableRequest{
|
|
TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "t", MetadataVersion: 4, MetadataLocation: location,
|
|
})
|
|
assert.NotEqual(t, http.StatusOK, status, "%+v", resp)
|
|
require.True(t, client.failing)
|
|
assert.Equal(t, string(before), string(fs.Get(nsPath, "t").Extended[ExtendedKeyMetadata]))
|
|
assert.NotContains(t, fs.Get(nsPath, "t").Extended, ExtendedKeyMoving)
|
|
})
|
|
|
|
t.Run("rename", func(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "c", Format: FormatIceberg})
|
|
client := &rootRaceClient{SeaweedFilerClient: fs.Client, f: fs, dir: nsPath, name: "dest", location: renameLocation("ns/dest/metadata/v1.metadata.json")}
|
|
status, resp := runHandler(t, m, client, "RenameTable", &RenameTableRequest{
|
|
TableBucketARN: mustBucketARN(t), SourceNamespace: []string{"ns"}, SourceName: "c", DestNamespace: []string{"ns"}, DestName: "dest",
|
|
})
|
|
assert.Equal(t, http.StatusConflict, status, "%+v", resp)
|
|
require.True(t, client.planted)
|
|
assert.Contains(t, fs.Get(nsPath, "c").Extended, ExtendedKeyMetadata)
|
|
if entry := fs.Get(nsPath, "dest"); entry != nil {
|
|
assert.NotContains(t, entry.Extended, ExtendedKeyMetadata)
|
|
}
|
|
})
|
|
}
|
|
|
|
// A move reserves its new root on the record, so a second move of the record
|
|
// waits for it, and an update that keeps the root clears a reservation a
|
|
// crashed move left behind.
|
|
func TestMoveReservationLeftBehind(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
nsPath := GetNamespacePath(renameTestBucket, "ns")
|
|
bucketARN := mustBucketARN(t)
|
|
entry := fs.Get(nsPath, "t")
|
|
leftover, _ := json.Marshal(tableMetadataInternal{Name: "t", Namespace: "ns", MetadataLocation: renameLocation("ns/elsewhere/metadata/v4.metadata.json")})
|
|
entry.Extended[ExtendedKeyMoving] = leftover
|
|
fs.Put(nsPath, "t", entry.Extended)
|
|
|
|
refused := renameLocation("ns/moved/metadata/v1.metadata.json")
|
|
assert.True(t, RootClaimed(mustRoots(t, fs), path.Join(nsPath, "other"), path.Join(nsPath, "elsewhere")))
|
|
status, resp := runHandler(t, m, fs.Client, "UpdateTable", &UpdateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "t", MetadataVersion: 4, MetadataLocation: refused})
|
|
assert.Equal(t, http.StatusConflict, status, "%+v", resp)
|
|
|
|
requireOK(t, m, fs, "UpdateTable", &UpdateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "t", MetadataVersion: 4, MetadataLocation: renameLocation("ns/t/metadata/v4.metadata.json")})
|
|
assert.NotContains(t, fs.Get(nsPath, "t").Extended, ExtendedKeyMoving)
|
|
assert.False(t, RootClaimed(mustRoots(t, fs), path.Join(nsPath, "other"), path.Join(nsPath, "elsewhere")))
|
|
|
|
requireOK(t, m, fs, "UpdateTable", &UpdateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "t", MetadataVersion: 5, MetadataLocation: refused})
|
|
assert.NotContains(t, fs.Get(nsPath, "t").Extended, ExtendedKeyMoving)
|
|
}
|
|
|
|
func mustRoots(t *testing.T, fs *s3tablestest.MemFiler) map[string][]string {
|
|
t.Helper()
|
|
roots, err := CatalogRecordRoots(context.Background(), fs.Client, renameTestBucket)
|
|
require.NoError(t, err)
|
|
return roots
|
|
}
|
|
|
|
// A table that keeps its files elsewhere still owns its catalog entry: a view
|
|
// recorded at that entry would take it with the view's files on drop.
|
|
func TestLocationRefusesAnotherRecordsEntry(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
bucketARN := mustBucketARN(t)
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{
|
|
TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "a", Format: FormatIceberg,
|
|
MetadataLocation: renameLocation("ns/storage/metadata/v1.metadata.json"),
|
|
})
|
|
status, resp := runHandler(t, m, fs.Client, "CreateView", &CreateViewRequest{
|
|
TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "v", MetadataLocation: renameLocation("ns/a/metadata/v1.metadata.json"),
|
|
})
|
|
assert.Equal(t, http.StatusConflict, status, "%+v", resp)
|
|
}
|
|
|
|
// A record taken away by a rename or a delete while a move holds its
|
|
// reservation leaves the old name free: the move can no longer clear the
|
|
// reservation once the record is gone.
|
|
func TestRecordGoneDropsItsMoveReservation(t *testing.T) {
|
|
nsPath := GetNamespacePath(renameTestBucket, "ns")
|
|
reserve := func(t *testing.T, fs *s3tablestest.MemFiler, name string) {
|
|
t.Helper()
|
|
moving, _ := json.Marshal(tableMetadataInternal{Name: name, Namespace: "ns", Format: FormatIceberg, MetadataLocation: renameLocation("ns/target/metadata/v9.metadata.json")})
|
|
fs.Get(nsPath, name).Extended[ExtendedKeyMoving] = moving
|
|
}
|
|
reuse := func(t *testing.T, m *Manager, fs *s3tablestest.MemFiler, name string) {
|
|
t.Helper()
|
|
assert.NotContains(t, fs.Get(nsPath, name).Extended, ExtendedKeyMoving)
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{
|
|
TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: name, Format: FormatIceberg,
|
|
MetadataLocation: renameLocation("ns/fresh-" + name + "/metadata/v1.metadata.json"),
|
|
})
|
|
}
|
|
|
|
t.Run("rename", func(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
reserve(t, fs, "t")
|
|
requireOK(t, m, fs, "RenameTable", &RenameTableRequest{
|
|
TableBucketARN: mustBucketARN(t), SourceNamespace: []string{"ns"}, SourceName: "t", DestNamespace: []string{"ns"}, DestName: "u",
|
|
})
|
|
assert.NotContains(t, fs.Get(nsPath, "u").Extended, ExtendedKeyMoving)
|
|
reuse(t, m, fs, "t")
|
|
})
|
|
|
|
t.Run("delete", func(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{
|
|
TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "d", Format: FormatIceberg,
|
|
MetadataLocation: renameLocation("ns/d-files/metadata/v1.metadata.json"),
|
|
})
|
|
reserve(t, fs, "d")
|
|
requireOK(t, m, fs, "DeleteTable", &DeleteTableRequest{TableBucketARN: mustBucketARN(t), Namespace: []string{"ns"}, Name: "d"})
|
|
reuse(t, m, fs, "d")
|
|
})
|
|
}
|