mq broker: a topic leaves a table that no longer names it

A table dropped and replaced under the same name by one that does not
carry the topic's property holds none of the topic's history, so its
snapshots no longer keep the topic from detaching, switching tables, or
following a schema change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-01 17:59:30 -08:00
1 parent de383b67fa
commit ddeb10a89b
2 files changed
+30 -1

No files matched your search

+5 -1
View File
@@ -147,7 +147,8 @@ func (b *MessageQueueBroker) ensureTopicTable(ctx context.Context, t topic.Topic
// releaseTopicTable lets topic t leave its table tt, for no table or another
// one, only while tt holds no snapshot: its history would be stranded with no
// topic to read or trim it. A table its owner has dropped holds nothing.
// topic to read or trim it. A table its owner has dropped, or replaced with
// one that does not name t, holds nothing of t's.
func (b *MessageQueueBroker) releaseTopicTable(ctx context.Context, t topic.Topic, tt *mq_pb.TopicTable) error {
bucket, err := s3tables.ParseBucketNameFromARN(tt.TableBucketArn)
if err != nil {
@@ -175,6 +176,9 @@ func (b *MessageQueueBroker) releaseTopicTable(ctx context.Context, t topic.Topi
if err != nil {
return status.Errorf(codes.FailedPrecondition, "check table %s.%s in table bucket %s before leaving it: %v", tt.Namespace, tt.Name, bucket, err)
}
if metadata.Properties()[topictable.TopicProperty] != topictable.TopicPropertyValue(t) {
return nil
}
if n := len(metadata.Snapshots()); n > 0 {
return status.Errorf(codes.FailedPrecondition, "table %s.%s in table bucket %s holds topic %s's history in %d snapshots, so the topic cannot leave it", tt.Namespace, tt.Name, bucket, t, n)
}
+25
View File
@@ -365,6 +365,31 @@ func TestTopicLeavesAnEmptyTable(t *testing.T) {
}
}
// A table dropped and replaced by one that does not name the topic holds none
// of the topic's history, so the topic may leave it.
func TestTopicLeavesATableReplacedUnderItsName(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)
}
if err := tables.admin.Execute(t.Context(), tables.client, "DeleteTable", &s3tables.DeleteTableRequest{
TableBucketARN: testTableBucketARN(t), Namespace: []string{testTableNamespace}, Name: "events",
}, nil, ""); err != nil {
t.Fatal(err)
}
createForeignTable(t, tables, "events", testRecordType, nil)
tables.appendSnapshot(t, "events")
if _, err := configureTopic(t, b, &mq_pb.ConfigureTopicRequest{MessageRecordType: testRecordType, Table: &mq_pb.TopicTable{}}); err != nil {
t.Fatal(err)
}
if stored := f.topicConf(t).Table; stored != nil {
t.Fatalf("detached topic still names %v", stored)
}
}
// The catalog sees its own answers through the broker's filers unwrapped,
// while a failure to reach a filer still fails the call.
func TestTopicTableFilersPassTheCatalogsAnswer(t *testing.T) {