mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-08 21:08:27 +01:00
* s3tables: give a table created without a location its own directory An Iceberg table created without a location kept its files under its name path, so a rename left them where the next table of that name would land. Such a table now gets s3://<bucket>/<namespace>/<name>-<uuid>, stored as the record's warehouseLocation and returned by GetTable; its first commit writes there without moving the root. Records without one keep resolving to their name path, so existing tables need no rewrite. Lance datasets stay at their name path, where Lance clients and the vector engine look for them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: create tables and views in a directory of their own A table or view created without a location took its name path, or a unique one only when that path was already taken. It now always gets <name>-<uuid>, so a later rename never leaves its files under a name another table can take. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: load and commit a table at its warehouse location A table created through S3 Tables without a location has no metadata until its first commit; loading or committing it now uses the directory recorded for it, and only a record without one falls back to its name path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: fail a stage-create whose marker is not saved The marker is how the commit finds the location the stage-create handed out. Without it the commit fell back to the name path while the client's files sat under the returned location. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: expect tables created without a location in their own directory Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: rename a table that keeps its files elsewhere before reusing its name Enterprise keeps the storage marker on a renamed table's files, so the name of a table whose files sit under its name path stays taken there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: remove the table directory when a create backs out Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: answer a create that lost the race with the registered table Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: answer a view create that lost the race with the registered view Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: fail a staged commit whose name another create registered Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: remove the directory of a create whose name another table took Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: keep the metadata of a staged commit whose name is taken Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: write the lakekeeper table's data under its warehouse location Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: commit a staged table at the location of its own stage Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: never continue another stage when a commit's own marker is gone Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: test filer honors exclusive creates and token-guarded deletes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
146 lines
6.9 KiB
Go
146 lines
6.9 KiB
Go
package s3tables
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"path"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"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"
|
|
)
|
|
|
|
// A table created without a location keeps its files in a directory of its
|
|
// own, so a rename leaves nothing under the old name and the name can be used
|
|
// again without either table reaching the other's files.
|
|
func TestCreateTableWithoutLocationGetsItsOwnDirectory(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
bucketARN := mustBucketARN(t)
|
|
nsPath := GetNamespacePath(renameTestBucket, "ns")
|
|
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "w", Format: FormatIceberg})
|
|
var table GetTableResponse
|
|
getTable(t, m, fs, bucketARN, "w", &table)
|
|
assert.Empty(t, table.MetadataLocation)
|
|
assert.True(t, strings.HasPrefix(table.WarehouseLocation, renameLocation("ns/w-")), table.WarehouseLocation)
|
|
|
|
firstRoot := recordRoot(t, fs, nsPath, "w")
|
|
assert.Equal(t, path.Join(TablesPath, strings.TrimPrefix(table.WarehouseLocation, "s3://")), firstRoot)
|
|
require.NotNil(t, fs.Get(firstRoot, "data"))
|
|
fs.PutFile(path.Join(firstRoot, "data"), "part-0.parquet", time.Now())
|
|
assert.Nil(t, fs.Get(path.Join(nsPath, "w"), "data"), "the catalog entry holds no files")
|
|
|
|
requireOK(t, m, fs, "RenameTable", &RenameTableRequest{TableBucketARN: bucketARN, SourceNamespace: []string{"ns"}, SourceName: "w", DestNamespace: []string{"ns"}, DestName: "moved"})
|
|
assert.Equal(t, firstRoot, recordRoot(t, fs, nsPath, "moved"), "a rename keeps the directory")
|
|
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "w", Format: FormatIceberg})
|
|
secondRoot := recordRoot(t, fs, nsPath, "w")
|
|
assert.NotEqual(t, firstRoot, secondRoot)
|
|
assert.False(t, PathsOverlap(firstRoot, secondRoot))
|
|
|
|
requireOK(t, m, fs, "DeleteTable", &DeleteTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "w"})
|
|
assert.NotNil(t, fs.Get(path.Join(firstRoot, "data"), "part-0.parquet"), "deleting the new table leaves the renamed one's files")
|
|
requireOK(t, m, fs, "DeleteTable", &DeleteTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "moved"})
|
|
assert.Nil(t, fs.Get(path.Dir(firstRoot), path.Base(firstRoot)), "deleting the renamed table purges its directory")
|
|
}
|
|
|
|
// A Lance dataset stays at its name path, where Lance clients and the vector
|
|
// engine look for it.
|
|
func TestCreateLanceTableWithoutLocationKeepsItsPath(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
bucketARN := mustBucketARN(t)
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "l", Format: FormatLance})
|
|
var table GetTableResponse
|
|
getTable(t, m, fs, bucketARN, "l", &table)
|
|
assert.Empty(t, table.MetadataLocation)
|
|
assert.Empty(t, table.WarehouseLocation)
|
|
assert.Equal(t, GetTablePath(renameTestBucket, "ns", "l"), recordRoot(t, fs, GetNamespacePath(renameTestBucket, "ns"), "l"))
|
|
}
|
|
|
|
// Records written before tables got their own directory carry no warehouse
|
|
// location and keep resolving to their name path, so nothing has to be
|
|
// rewritten when a gateway is upgraded.
|
|
func TestRecordWithoutWarehouseLocationKeepsItsPath(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
bucketARN := mustBucketARN(t)
|
|
nsPath := GetNamespacePath(renameTestBucket, "ns")
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "old", Format: FormatIceberg})
|
|
dropWarehouseLocation(t, fs, nsPath, "old")
|
|
assert.Equal(t, path.Join(nsPath, "old"), recordRoot(t, fs, nsPath, "old"))
|
|
assert.Equal(t, path.Join(nsPath, "t"), recordRoot(t, fs, nsPath, "t"), "a metadata location still decides the root")
|
|
|
|
status, resp := runHandler(t, m, fs.Client, "CreateTable", &CreateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "alias", Format: FormatIceberg, MetadataLocation: renameLocation("ns/old/metadata/v1.metadata.json")})
|
|
assert.Equal(t, http.StatusConflict, status, "%+v", resp)
|
|
}
|
|
|
|
// The first commit of a table writes its metadata into the assigned directory,
|
|
// which is the root the record already holds, so it scans no other record.
|
|
func TestFirstCommitIntoWarehouseLocationKeepsTheRoot(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
bucketARN := mustBucketARN(t)
|
|
nsPath := GetNamespacePath(renameTestBucket, "ns")
|
|
requireOK(t, m, fs, "CreateTable", &CreateTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "w", Format: FormatIceberg})
|
|
var table GetTableResponse
|
|
getTable(t, m, fs, bucketARN, "w", &table)
|
|
root := recordRoot(t, fs, nsPath, "w")
|
|
|
|
status, resp := runHandler(t, m, &noListClient{SeaweedFilerClient: fs.Client}, "UpdateTable", &UpdateTableRequest{
|
|
TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "w", MetadataVersion: 1,
|
|
MetadataLocation: table.WarehouseLocation + "/metadata/v1.metadata.json",
|
|
})
|
|
require.Equal(t, http.StatusOK, status, "%+v", resp)
|
|
assert.Equal(t, root, recordRoot(t, fs, nsPath, "w"))
|
|
assert.NotContains(t, fs.Get(nsPath, "w").Extended, ExtendedKeyMoving)
|
|
}
|
|
|
|
// A create that backs out after making the table's directory removes it, so
|
|
// failed creates leave nothing behind under the namespace.
|
|
func TestBackedOutCreateRemovesItsDirectory(t *testing.T) {
|
|
fs, m := startEmptyBucket(t)
|
|
requireOK(t, m, fs, "CreateNamespace", createNamespaceNsRequest(t))
|
|
bucketPath := GetTableBucketPath(renameTestBucket)
|
|
nsPath := GetNamespacePath(renameTestBucket, "ns")
|
|
recreated := recreatedNamespace(t, "ns")
|
|
swapped := false
|
|
fs.OnLookup = func(dir, name string) {
|
|
switch {
|
|
case dir == nsPath && name == "t" && !swapped:
|
|
swapped = true
|
|
fs.Put(bucketPath, "ns", recreated)
|
|
case path.Dir(dir) == nsPath && name == "data":
|
|
// The filer makes the parents of an entry it creates.
|
|
fs.Put(nsPath, path.Base(dir), nil)
|
|
}
|
|
}
|
|
|
|
code, resp := runHandler(t, m, fs.Client, "CreateTable", createTableRequest(t, "ns", "t"))
|
|
require.Equal(t, http.StatusNotFound, code, "%+v", resp)
|
|
fs.OnLookup = nil
|
|
|
|
var left []string
|
|
require.NoError(t, eachDirEntry(context.Background(), fs.Client, nsPath, func(entry *filer_pb.Entry) bool {
|
|
left = append(left, entry.Name)
|
|
return true
|
|
}))
|
|
assert.Empty(t, left)
|
|
}
|
|
|
|
func getTable(t *testing.T, m *Manager, fs *s3tablestest.MemFiler, bucketARN, name string, out *GetTableResponse) {
|
|
t.Helper()
|
|
require.NoError(t, m.Execute(context.Background(), NewManagerClient(fs.Client), "GetTable", &GetTableRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: name}, out, ""))
|
|
}
|
|
|
|
type noListClient struct {
|
|
filer_pb.SeaweedFilerClient
|
|
}
|
|
|
|
func (c *noListClient) ListEntries(context.Context, *filer_pb.ListEntriesRequest, ...grpc.CallOption) (grpc.ServerStreamingClient[filer_pb.ListEntriesResponse], error) {
|
|
return nil, errors.New("listing unavailable")
|
|
}
|