diff --git a/weed/mq/broker/broker_topic_table.go b/weed/mq/broker/broker_topic_table.go index 866643131b..1eb9bf7920 100644 --- a/weed/mq/broker/broker_topic_table.go +++ b/weed/mq/broker/broker_topic_table.go @@ -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) } diff --git a/weed/mq/broker/broker_topic_table_test.go b/weed/mq/broker/broker_topic_table_test.go index 286d98cfaa..e24bac20c8 100644 --- a/weed/mq/broker/broker_topic_table_test.go +++ b/weed/mq/broker/broker_topic_table_test.go @@ -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) {