From e028229694859b2868f6cae7a2a42ff8d8947c87 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 1 Dec 2026 15:10:27 -0800 Subject: [PATCH] mq broker: pass the table catalog's answers through the filer accessor The filer accessor treats any error as a failed filer: it records the failure, asks the next filer and wraps the last error with %v. A catalog answer such as NoSuchTable then reached ConfigureTopic as an opaque string, so a missing table was reported instead of created. The catalog now goes through an adapter that returns the catalog's own answers unwrapped and leaves failover to real filer failures. Co-Authored-By: Claude Opus 5.5 --- weed/mq/broker/broker_server.go | 2 +- weed/mq/broker/broker_topic_table.go | 25 +++++++++++++++++++++++ weed/mq/broker/broker_topic_table_test.go | 20 ++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/weed/mq/broker/broker_server.go b/weed/mq/broker/broker_server.go index d98e676f2a..894a288c81 100644 --- a/weed/mq/broker/broker_server.go +++ b/weed/mq/broker/broker_server.go @@ -134,7 +134,7 @@ func NewMessageBroker(option *MessageQueueBrokerOption, grpcDialOption grpc.Dial }, } mqBroker.fca = fca - mqBroker.topicTables = icebergcatalog.NewServer(fca, nil) + mqBroker.topicTables = icebergcatalog.NewServer(topicTableFilers{fca}, nil) subCoordinator.FilerClientAccessor = fca mqBroker.MasterClient.SetOnPeerUpdateFn(mqBroker.OnBrokerUpdate) diff --git a/weed/mq/broker/broker_topic_table.go b/weed/mq/broker/broker_topic_table.go index 1e2d33f127..b968ce22c4 100644 --- a/weed/mq/broker/broker_topic_table.go +++ b/weed/mq/broker/broker_topic_table.go @@ -7,9 +7,11 @@ import ( "github.com/apache/iceberg-go" "github.com/apache/iceberg-go/table" + "github.com/seaweedfs/seaweedfs/weed/filer_client" "github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/mq/topic" "github.com/seaweedfs/seaweedfs/weed/mq/topictable" + "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb" "github.com/seaweedfs/seaweedfs/weed/pb/schema_pb" icebergcatalog "github.com/seaweedfs/seaweedfs/weed/s3api/iceberg" @@ -18,6 +20,29 @@ import ( "google.golang.org/grpc/status" ) +// topicTableFilers hands the table catalog the broker's filers. An answer the +// catalog gave is returned as is: the accessor would wrap it out of reach of +// errors.As, mark the filer failed, and ask every other filer, which would +// answer the same. +type topicTableFilers struct { + fca *filer_client.FilerClientAccessor +} + +func (f topicTableFilers) WithFilerClient(streamingMode bool, fn func(filer_pb.SeaweedFilerClient) error) error { + var answer error + if err := f.fca.WithFilerClient(streamingMode, func(client filer_pb.SeaweedFilerClient) error { + answer = fn(client) + var tableErr *s3tables.S3TablesError + if errors.As(answer, &tableErr) { + return nil + } + return answer + }); err != nil { + return err + } + return answer +} + // requestedTopicTable is the table a configure leaves the topic with: an unset // request keeps stored, an empty table bucket ARN detaches it. func requestedTopicTable(requested, stored *mq_pb.TopicTable) *mq_pb.TopicTable { diff --git a/weed/mq/broker/broker_topic_table_test.go b/weed/mq/broker/broker_topic_table_test.go index baa1a5811e..068c6b8724 100644 --- a/weed/mq/broker/broker_topic_table_test.go +++ b/weed/mq/broker/broker_topic_table_test.go @@ -11,6 +11,7 @@ import ( "github.com/apache/iceberg-go/table" "github.com/seaweedfs/seaweedfs/weed/mq/schema" "github.com/seaweedfs/seaweedfs/weed/mq/topictable" + "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb" "github.com/seaweedfs/seaweedfs/weed/pb/schema_pb" icebergcatalog "github.com/seaweedfs/seaweedfs/weed/s3api/iceberg" @@ -356,3 +357,22 @@ func TestTopicLeavesAnEmptyTable(t *testing.T) { 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) { + _, b := newFencingFiler(t) + filers := topicTableFilers{b.fca} + calls := 0 + err := filers.WithFilerClient(false, func(filer_pb.SeaweedFilerClient) error { + calls++ + return &s3tables.S3TablesError{Type: s3tables.ErrCodeNoSuchTable, Message: "table events not found"} + }) + if !isNoSuchTable(err) || calls != 1 { + t.Fatalf("got %v after %d calls, want the catalog's NoSuchTable from one", err, calls) + } + unreachable := status.Error(codes.Unavailable, "filer down") + if err := filers.WithFilerClient(false, func(filer_pb.SeaweedFilerClient) error { return unreachable }); err == nil || isNoSuchTable(err) { + t.Fatalf("got %v, want the filer failure", err) + } +}