mq broker: a table hidden by its policy still holds the topic's history

GetTable answers NoSuchTable both for a table that is gone and for one a
policy denies the caller, so a topic whose table carried snapshots under
a policy denying GetTable could detach as if the table had been
dropped. When the catalog says the table is missing, the broker now
looks for its record in the filer with the new s3tables.TableRegistered,
which finds what GetTable finds before policy, and refuses to leave a
table that is registered but unreadable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-01 16:01:00 -08:00
1 parent e028229694
commit af9c09612c
5 files changed
+85 -2

No files matched your search

+4 -2
View File
@@ -81,8 +81,9 @@ type MessageQueueBroker struct {
// orders read-modify-writes of topic.conf, all of which run on the balancer
topicConfLock topicConfMutex
fca *filer_client.FilerClientAccessor
// the Iceberg catalog of the table buckets topic tables live in
// the Iceberg catalog of the table buckets topic tables live in, and the filers it reads
topicTables *icebergcatalog.Server
tableFilers icebergcatalog.FilerClient
// Unified topic cache for both existence and configuration
// Caches topic config (positive: conf != nil) and non-existence (negative: conf == nil)
// Eliminates 60% CPU overhead from repeated filer reads and JSON unmarshaling
@@ -134,7 +135,8 @@ func NewMessageBroker(option *MessageQueueBrokerOption, grpcDialOption grpc.Dial
},
}
mqBroker.fca = fca
mqBroker.topicTables = icebergcatalog.NewServer(topicTableFilers{fca}, nil)
mqBroker.tableFilers = topicTableFilers{fca}
mqBroker.topicTables = icebergcatalog.NewServer(mqBroker.tableFilers, nil)
subCoordinator.FilerClientAccessor = fca
mqBroker.MasterClient.SetOnPeerUpdateFn(mqBroker.OnBrokerUpdate)
+11
View File
@@ -129,6 +129,17 @@ func (b *MessageQueueBroker) releaseTopicTable(ctx context.Context, t topic.Topi
_, metadata, err := b.topicTables.LoadTable(ctx, bucket, []string{tt.Namespace}, tt.Name, "")
var tableErr *s3tables.S3TablesError
if errors.As(err, &tableErr) && (tableErr.Type == s3tables.ErrCodeNoSuchTable || tableErr.Type == s3tables.ErrCodeNoSuchNamespace || tableErr.Type == s3tables.ErrCodeNoSuchBucket) {
// a policy denying GetTable also answers NoSuchTable, so absence is confirmed past it
var registered bool
if lookupErr := b.tableFilers.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) (err error) {
registered, err = s3tables.TableRegistered(ctx, client, bucket, tt.Namespace, tt.Name)
return err
}); lookupErr != nil {
return status.Errorf(codes.FailedPrecondition, "check table %s.%s in table bucket %s before leaving it: %v", tt.Namespace, tt.Name, bucket, lookupErr)
}
if registered {
return status.Errorf(codes.FailedPrecondition, "table %s.%s in table bucket %s exists but its policy keeps the broker from reading it, so topic %s cannot leave it", tt.Namespace, tt.Name, bucket, t)
}
return nil
}
if err != nil {
+29
View File
@@ -51,6 +51,7 @@ func withTableBucket(t *testing.T, b *MessageQueueBroker) *testTables {
}
tables.Server = icebergcatalog.NewServer(tables.client, nil)
b.topicTables = tables.Server
b.tableFilers = tables.client
return tables
}
@@ -376,3 +377,31 @@ func TestTopicTableFilersPassTheCatalogsAnswer(t *testing.T) {
t.Fatalf("got %v, want the filer failure", err)
}
}
// A table whose policy hides it from the broker still holds the topic's
// history, so the topic does not leave it.
func TestTopicCannotLeaveATableItsPolicyHides(t *testing.T) {
f, b := newBalancer(t, "127.0.0.1:18888")
tables := withTableBucket(t, b)
events := testTopicTable(t, "events")
if _, err := configureTopic(t, b, &mq_pb.ConfigureTopicRequest{MessageRecordType: testRecordType, Table: events}); err != nil {
t.Fatal(err)
}
tables.appendSnapshot(t, "events")
deny := `{"Version":"2012-10-17","Statement":[{"Effect":"Deny","Principal":"*","Action":"s3tables:*","Resource":"*"}]}`
if err := tables.admin.Execute(t.Context(), tables.client, "PutTablePolicy", &s3tables.PutTablePolicyRequest{
TableBucketARN: testTableBucketARN(t), Namespace: []string{testTableNamespace}, Name: "events", ResourcePolicy: deny,
}, nil, ""); err != nil {
t.Fatal(err)
}
if _, _, err := tables.LoadTable(t.Context(), testTableBucket, []string{testTableNamespace}, "events", ""); !isNoSuchTable(err) {
t.Fatalf("load under a denying policy: %v, want it hidden as NoSuchTable", err)
}
if _, err := configureTopic(t, b, &mq_pb.ConfigureTopicRequest{MessageRecordType: testRecordType, Table: &mq_pb.TopicTable{}}); status.Code(err) != codes.FailedPrecondition {
t.Fatalf("got %v, want FailedPrecondition", err)
}
if !proto.Equal(f.topicConf(t).Table, events) {
t.Fatalf("stored %v", f.topicConf(t).Table)
}
}
+14
View File
@@ -1396,6 +1396,20 @@ func (h *S3TablesHandler) readTableMetadata(ctx context.Context, client filer_pb
// entry-type check already treat kind mismatches, and so is a record its
// create has not finished writing. A directory without the record is no table
// either, and reports the same absence.
// TableRegistered reports whether a table is registered under the name, as
// GetTable finds it but before any policy hides it from the caller.
func TableRegistered(ctx context.Context, client filer_pb.SeaweedFilerClient, bucketName, namespace, tableName string) (bool, error) {
dir, name := splitPath(GetTablePath(bucketName, namespace, tableName))
resp, err := filer_pb.LookupEntry(ctx, client, &filer_pb.LookupDirectoryEntryRequest{Directory: dir, Name: name})
if err == nil {
_, err = tableMetadata(resp.Entry)
}
if errors.Is(err, filer_pb.ErrNotFound) {
return false, nil
}
return err == nil, err
}
func tableMetadata(entry *filer_pb.Entry) ([]byte, error) {
if EntryType(entry.Extended) == EntryTypeView || isUnfinishedCreate(entry.Extended) {
return nil, filer_pb.ErrNotFound
@@ -0,0 +1,27 @@
package s3tables
import (
"testing"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables/s3tablestest"
)
// TableRegistered finds what GetTable would find before policy is applied.
func TestTableRegistered(t *testing.T) {
fs := s3tablestest.Start(t)
dir := GetNamespacePath("hist", "ns")
fs.Put(dir, "table", map[string][]byte{ExtendedKeyMetadata: []byte("{}")})
fs.Put(dir, "view", map[string][]byte{ExtendedKeyMetadata: []byte("{}"), ExtendedKeyEntryType: []byte(EntryTypeView)})
fs.Put(dir, "creating", map[string][]byte{ExtendedKeyMetadata: []byte("{}"), ExtendedKeyDeleting: []byte(createClaim)})
fs.Put(dir, "plain", nil)
for name, want := range map[string]bool{"table": true, "view": false, "creating": false, "plain": false, "missing": false} {
got, err := TableRegistered(t.Context(), fs.Client, "hist", "ns", name)
if err != nil || got != want {
t.Errorf("%s: registered=%v err=%v, want %v", name, got, err, want)
}
}
if got, err := TableRegistered(t.Context(), fs.Client, "nobucket", "ns", "table"); err != nil || got {
t.Errorf("missing bucket: registered=%v err=%v", got, err)
}
}