diff --git a/weed/mq/broker/broker_topic_table_test.go b/weed/mq/broker/broker_topic_table_test.go index 09d575afc0..0a0058fd6f 100644 --- a/weed/mq/broker/broker_topic_table_test.go +++ b/weed/mq/broker/broker_topic_table_test.go @@ -204,7 +204,7 @@ func TestConfigureTopicCreatesItsTable(t *testing.T) { if !strings.HasPrefix(location, "s3://"+testTableBucket+"/"+testTableNamespace+"/events-") { t.Fatalf("table at %s", location) } - if owner := metadata.Properties()[topictable.TopicProperty]; owner != fenceTestTopic.String() { + if owner := metadata.Properties()[topictable.TopicProperty]; owner != topictable.TopicPropertyValue(fenceTestTopic) { t.Fatalf("%s is %q", topictable.TopicProperty, owner) } want, err := topictable.Schema(testRecordType) @@ -240,7 +240,7 @@ func TestConfigureTopicCreatesItsTable(t *testing.T) { func TestConfigureTopicAdoptsItsOwnTable(t *testing.T) { f, b := newBalancer(t, "127.0.0.1:18888") catalog := withTableBucket(t, b) - createForeignTable(t, catalog, "events", testRecordType, iceberg.Properties{topictable.TopicProperty: fenceTestTopic.String()}) + createForeignTable(t, catalog, "events", testRecordType, iceberg.Properties{topictable.TopicProperty: topictable.TopicPropertyValue(fenceTestTopic)}) location, _ := loadTestTable(t, catalog, "events") if _, err := configureTopic(t, b, &mq_pb.ConfigureTopicRequest{MessageRecordType: testRecordType, Table: testTopicTable(t, "events")}); err != nil { @@ -260,8 +260,8 @@ func TestConfigureTopicRefusesAForeignTable(t *testing.T) { f, b := newBalancer(t, "127.0.0.1:18888") catalog := withTableBucket(t, b) createForeignTable(t, catalog, "plain", testRecordType, nil) - createForeignTable(t, catalog, "other", testRecordType, iceberg.Properties{topictable.TopicProperty: "test.other"}) - createForeignTable(t, catalog, "narrow", schema.RecordTypeBegin().WithField("id", schema.TypeInt32).RecordTypeEnd(), iceberg.Properties{topictable.TopicProperty: fenceTestTopic.String()}) + createForeignTable(t, catalog, "other", testRecordType, iceberg.Properties{topictable.TopicProperty: "test/other"}) + createForeignTable(t, catalog, "narrow", schema.RecordTypeBegin().WithField("id", schema.TypeInt32).RecordTypeEnd(), iceberg.Properties{topictable.TopicProperty: topictable.TopicPropertyValue(fenceTestTopic)}) for _, name := range []string{"plain", "other", "narrow"} { _, err := configureTopic(t, b, &mq_pb.ConfigureTopicRequest{MessageRecordType: testRecordType, Table: testTopicTable(t, name)}) @@ -353,7 +353,7 @@ func TestTopicLeavesAnEmptyTable(t *testing.T) { } loadTestTable(t, tables, "other") // the table left behind stays, still naming the topic - if _, old := loadTestTable(t, tables, "events"); old.Properties()[topictable.TopicProperty] != fenceTestTopic.String() { + if _, old := loadTestTable(t, tables, "events"); old.Properties()[topictable.TopicProperty] != topictable.TopicPropertyValue(fenceTestTopic) { t.Fatalf("left table properties %v", old.Properties()) } diff --git a/weed/mq/topictable/layout.go b/weed/mq/topictable/layout.go index 91ff12e165..bb0758fd87 100644 --- a/weed/mq/topictable/layout.go +++ b/weed/mq/topictable/layout.go @@ -14,7 +14,7 @@ import ( ) // TopicProperty is the table property naming the topic that owns the table, -// as .. +// as /. const TopicProperty = "seaweedfs.mq.topic" // System columns, ahead of the record's own. @@ -37,9 +37,10 @@ const ( DecimalScale = 18 ) -// TopicPropertyValue is TopicProperty's value for t. +// TopicPropertyValue is TopicProperty's value for t: its directory under +// /topics, so two topics share a value only when they share a topic.conf. func TopicPropertyValue(t topic.Topic) string { - return t.String() + return t.Namespace + "/" + t.Name } // Schema maps a topic's record type to the table's columns: the system diff --git a/weed/mq/topictable/layout_test.go b/weed/mq/topictable/layout_test.go index 3eb08960b9..c1189eca7c 100644 --- a/weed/mq/topictable/layout_test.go +++ b/weed/mq/topictable/layout_test.go @@ -255,3 +255,13 @@ func TestCheckSchema(t *testing.T) { t.Fatalf("dropped optional field: %v", err) } } + +// Topics whose names only split differently own different tables. +func TestTopicPropertyValueIsUnambiguous(t *testing.T) { + if a, b := TopicPropertyValue(topic.NewTopic("a.b", "c")), TopicPropertyValue(topic.NewTopic("a", "b.c")); a == b { + t.Fatalf("a.b/c and a/b.c both own tables marked %q", a) + } + if got := TopicPropertyValue(topic.NewTopic("ns", "t")); got != "ns/t" { + t.Fatalf("got %q, want the topic's path under /topics", got) + } +}