mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
* s3tables, iceberg, lance: the catalog assigns every new location; an existing name answers only a reader A REST create without a location gets <ns>/<name>-<uuid> (#12475) and a location another record holds is refused (#12473), but a location a client names is still taken: the REST create's location field and warehouse property, S3 Tables CreateTable and CreateView with a MetadataLocation, the Lance declare's location. A free location a client picks can be one another caller holds staged write credentials for (stage markers are not claims), or files no record claims any more. Separately, CreateTable of a name that already holds a table returns that table (ARN, version token, metadata location) to any caller who may create, including one who may not read it. - A REST create or create view naming a location (field or property, stage-create or not, the bare bucket included) is refused with 400 before anything is written; the location is always placeNewEntry's: <ns>/<name>-<uuid> in the bucket, or under the operator's ICEBERG_WAREHOUSE (no longer under a client's warehouse property). - A create commit uses a stage marker only when its assign-uuid matches the staged table's UUID (PyIceberg and Java send it); any other create commit is placed at a fresh <name>-<uuid>, never at the bare name path and never at another caller's staged location. Its updates may not set another location than the one assigned (400). - S3 Tables CreateTable and CreateView naming a MetadataLocation are refused with 400 (ErrClientTableLocation) unless the call is the process's own (WithCatalogAssignedLocation: the REST create, create view and create commit at the location they placed; the Lance declare at the dataset's name path and register at an existing dataset). AWS's CreateTable takes no location either. - A Lance declare naming a location is refused with 400 (register is for existing datasets). - CreateTable of an existing name answers the table only to a caller who may GetTable it; a caller who may only create gets 409 TableAlreadyExists and nothing about it. Tests: TestAClientCreateNamesNoLocation (positive controls: a client create without a location, the catalog's own create with one), TestARESTCreateNamesNoLocation, TestACreateCommitCannotSetAnotherLocation, TestACreateCommitTakesOnlyItsOwnStage (the stager's own commit is the positive control), TestCreateExistingTableAnswersOnlyAReaderWithIt (a reader gets the table). Existing tests adapted: the s3tables fixtures and request helpers run as the catalog's own calls (assignedCtx), as do the iceberg tests that seed tables through the manager; iceberg_create_table_conflict_test.go's creates send no location and newConflictEnv points placeNewEntry at conflictLocation, so its races still collide on one location; TestCreatePathsRefuseAnotherTablesLocation expects 400 for the three create paths and 409 for the register; TestCreateTableWithoutLocationUsesItsOwnDirectory drops the bare-bucket body; lance TestIcebergTablesAreInvisible seeds its Iceberg table as the catalog; TestDeclareOfAnExistingTableKeepsItsLocation expects 400 for a declare naming the index's location; TestDeregisterAndReregisterNeedUpdateTable (#12552) expects 409 instead of 404 for the register and the declare of a caller without GetTable: the table stays deregistered and nothing is vended. Each rule is red with it undone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: a create may name a fresh location A REST CreateTable naming a location (Trino always sends one built from the namespace location, Spark LOCATION, PyIceberg location=) is accepted again when nothing is stored under it and no live stage holds it; a used or staged location answers 400. The check runs after the create's authorization and before anything is written. A bare-bucket location still gets the assigned <name>-<uuid>. CreateView always uses the assigned location: a view holds only metadata files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * lance: a declare may restate its name path as its location pylance and other namespace clients may send the location they expect; the dataset's own name path is accepted, any other location still answers 400. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: a commit cannot set another location on an existing table CommitTable and CommitTransaction applied a set-location update, so a table's metadata could name a location outside the directory its record holds. Such a commit now answers 400 and nothing is written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: the fresh-location check pages through every stage marker Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: a fresh location stays apart from stages and tables above or under it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: a create checks its location again after claiming it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables, iceberg: a live stage holds its location against every create The catalog counts each live stage-create as a root of the record it would commit to, so a native create, register, rename or move over a stage's location is refused. The fresh-location check reads the same roots, so a stage also backs out of a record that claimed an ancestor after its first check. A location held by a record or stage answers 409, as the create gate already did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: a create removes only the stages its location covers A create or commit used to drop every stage marker of its name, which freed the location of a stage whose credentials were still live. Expired markers now go with their staged metadata. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: an assigned stage location checks its claim again too Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: a stage marker lasts as long as its vended credentials Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: test a create that runs while a stage checks its claim Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: a stage holds its location against a create of the same name A live stage-create now counts under its marker rather than under the record of its name, so a same-name create over its location is refused and a stage refuses a same-name table created over its location. Only a staged commit takes the location its own stage holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: a stage holds only its location against its own record's create A live stage keeps the path of the record it would commit to away from other records' files, but a create of that same record writes it: the stage then holds only its location against it. A stage at its name path can commit while a later stage of its name, elsewhere, is live. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg: a staged commit's create gate reads its location as a create does The gate maps a metadata file's location to its table directory, so the bare location of a stage under a metadata directory resolved to the namespace and conflicted with the stage's own claim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * iceberg, lance: tests from master create through the catalog's own call Their creates name a location, which only the catalog's own calls may, and a caller who may only create gets 409 for an existing name whatever location its register names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Javier de la Torre <jatorre@carto.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(assignedCtx(), 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")
|
|
}
|