mq: name a table's owning topic by its path under /topics

The seaweedfs.mq.topic property was <namespace>.<topic>, and topic names
may hold dots, so a.b/c and a/b.c wrote the same value and either could
adopt the other's table. The value is now <namespace>/<topic>, the
topic's directory under /topics: two topics that write the same value
already share one topic.conf, so they are the same topic.

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:18:13 -08:00
1 parent b202045ca6
commit f0557105f1
3 files changed
+19 -8

No files matched your search

+5 -5
View File
@@ -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())
}
+4 -3
View File
@@ -14,7 +14,7 @@ import (
)
// TopicProperty is the table property naming the topic that owns the table,
// as <namespace>.<topic>.
// as <namespace>/<topic>.
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
+10
View File
@@ -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)
}
}