mq broker: let the table catalog fail over to every discovered filer

The broker's filer accessor lists only the current filer, so the
failover the catalog adapter relies on had nowhere to go: an internal
error from the current filer failed the catalog call even with another
healthy filer discovered. The catalog now gets an accessor of its own
over every filer the broker has discovered, the current one first, read
under the lock that guards them. The broker's shared accessor stays on
the current filer, so topic.conf, offsets and the subscriber coordinator
keep reading one filer as before.

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:50:04 -08:00
1 parent 667084ee77
commit de383b67fa
3 files changed
+53 -1

No files matched your search

+1 -1
View File
@@ -135,7 +135,7 @@ func NewMessageBroker(option *MessageQueueBrokerOption, grpcDialOption grpc.Dial
},
}
mqBroker.fca = fca
mqBroker.tableFilers = topicTableFilers{fca}
mqBroker.tableFilers = mqBroker.newTopicTableFilers()
mqBroker.topicTables = icebergcatalog.NewServer(mqBroker.tableFilers, nil)
subCoordinator.FilerClientAccessor = fca
+30
View File
@@ -3,6 +3,7 @@ package broker
import (
"context"
"errors"
"slices"
"strings"
"github.com/apache/iceberg-go"
@@ -11,11 +12,13 @@ import (
"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"
"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"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables"
"github.com/seaweedfs/seaweedfs/weed/security"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
@@ -28,6 +31,33 @@ type topicTableFilers struct {
fca *filer_client.FilerClientAccessor
}
// newTopicTableFilers gives the catalog every discovered filer to fail over
// to; the broker's own accessor stays on the current filer.
func (b *MessageQueueBroker) newTopicTableFilers() topicTableFilers {
return topicTableFilers{&filer_client.FilerClientAccessor{
GetGrpcDialOption: b.GetGrpcDialOption,
TokenSource: security.FilerAdminToken,
GetFilers: b.discoveredFilers,
}}
}
// discoveredFilers is every filer the broker knows, the current one first.
func (b *MessageQueueBroker) discoveredFilers() []pb.ServerAddress {
b.filersLock.RLock()
defer b.filersLock.RUnlock()
var others []pb.ServerAddress
for filer := range b.filers {
if filer != b.currentFiler {
others = append(others, filer)
}
}
slices.Sort(others)
if b.currentFiler == "" {
return others
}
return append([]pb.ServerAddress{b.currentFiler}, others...)
}
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 {
+22
View File
@@ -449,3 +449,25 @@ func TestTopicTableFilersFailOverAnInternalError(t *testing.T) {
t.Fatalf("load of a missing table: %v, want NoSuchTable", err)
}
}
// The broker's current filer failing inside the catalog sends the call to
// another filer the broker has discovered.
func TestTopicTablesFailOverToADiscoveredFiler(t *testing.T) {
_, b := newBalancer(t, "127.0.0.1:18888")
tables := withTableBucket(t, b)
createForeignTable(t, tables, "events", testRecordType, nil)
broken := serveFiler(t, &filer_pb.UnimplementedSeaweedFilerServer{})
healthy := serveFiler(t, tables.filer)
b.currentFiler = broken
b.filers = map[pb.ServerAddress]struct{}{broken: {}, healthy: {}}
if got := b.discoveredFilers(); len(got) != 2 || got[0] != broken {
t.Fatalf("discovered %v, want the current filer first", got)
}
catalog := icebergcatalog.NewServer(b.newTopicTableFilers(), nil)
for i := 0; i < 5; i++ {
if _, _, err := catalog.LoadTable(t.Context(), testTableBucket, []string{testTableNamespace}, "events", ""); err != nil {
t.Fatalf("load %d: %v", i, err)
}
}
}