mq broker: fail over the table catalog's internal errors

The adapter between the table catalog and the filer accessor passed
every S3TablesError back as a successful filer call. An InternalError is
what the catalog answers when its own read of the filer fails, so a
broken filer was recorded healthy and no other filer was asked. Only
the catalog's refusals pass through now; an internal error goes back to
the accessor, which marks the filer failed and tries the next one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-01 16:01:55 -08:00
1 parent af9c09612c
commit b202045ca6
2 files changed
+48 -4

No files matched your search

+3 -3
View File
@@ -20,10 +20,10 @@ import (
"google.golang.org/grpc/status"
)
// topicTableFilers hands the table catalog the broker's filers. An answer the
// topicTableFilers hands the table catalog the broker's filers. A refusal 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.
// answer the same. An internal error is the filer failing, and fails over.
type topicTableFilers struct {
fca *filer_client.FilerClientAccessor
}
@@ -33,7 +33,7 @@ func (f topicTableFilers) WithFilerClient(streamingMode bool, fn func(filer_pb.S
if err := f.fca.WithFilerClient(streamingMode, func(client filer_pb.SeaweedFilerClient) error {
answer = fn(client)
var tableErr *s3tables.S3TablesError
if errors.As(answer, &tableErr) {
if errors.As(answer, &tableErr) && tableErr.Type != s3tables.ErrCodeInternalError {
return nil
}
return answer
+45 -1
View File
@@ -3,21 +3,26 @@ package broker
import (
"context"
"encoding/json"
"net"
"strings"
"testing"
"time"
"github.com/apache/iceberg-go"
"github.com/apache/iceberg-go/table"
"github.com/seaweedfs/seaweedfs/weed/filer_client"
"github.com/seaweedfs/seaweedfs/weed/mq/schema"
"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/s3api/s3tables/s3tablestest"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)
@@ -34,6 +39,7 @@ type testTables struct {
*icebergcatalog.Server
admin *s3tables.Manager
client *s3tables.ManagerClient
filer *s3tablestest.MemFiler
}
// withTableBucket gives b a catalog over an in-memory filer holding table
@@ -41,7 +47,7 @@ type testTables struct {
func withTableBucket(t *testing.T, b *MessageQueueBroker) *testTables {
t.Helper()
filer := s3tablestest.Start(t)
tables := &testTables{admin: s3tables.NewManager(), client: s3tables.NewManagerClient(filer.Client)}
tables := &testTables{admin: s3tables.NewManager(), client: s3tables.NewManagerClient(filer.Client), filer: filer}
tables.admin.SetTrusted(true)
if err := tables.admin.Execute(t.Context(), tables.client, "CreateTableBucket", &s3tables.CreateTableBucketRequest{Name: testTableBucket, Format: s3tables.FormatIceberg}, nil, ""); err != nil {
t.Fatal(err)
@@ -405,3 +411,41 @@ func TestTopicCannotLeaveATableItsPolicyHides(t *testing.T) {
t.Fatalf("stored %v", f.topicConf(t).Table)
}
}
func serveFiler(t *testing.T, server filer_pb.SeaweedFilerServer) pb.ServerAddress {
t.Helper()
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
grpcServer := grpc.NewServer()
filer_pb.RegisterSeaweedFilerServer(grpcServer, server)
go grpcServer.Serve(listener)
t.Cleanup(grpcServer.Stop)
return pb.NewServerAddressWithGrpcPort(listener.Addr().String(), listener.Addr().(*net.TCPAddr).Port)
}
// A filer whose reads fail makes the catalog answer InternalError; that is the
// filer failing, so the load goes on to a filer that works.
func TestTopicTableFilersFailOverAnInternalError(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)
fca := &filer_client.FilerClientAccessor{
GetGrpcDialOption: func() grpc.DialOption { return grpc.WithTransportCredentials(insecure.NewCredentials()) },
GetFilers: func() []pb.ServerAddress { return []pb.ServerAddress{broken, healthy} },
}
catalog := icebergcatalog.NewServer(topicTableFilers{fca}, nil)
// the accessor shuffles its filers, so the broken one comes first in some of these
for i := 0; i < 20; i++ {
if _, _, err := catalog.LoadTable(t.Context(), testTableBucket, []string{testTableNamespace}, "events", ""); err != nil {
t.Fatalf("load %d: %v", i, err)
}
}
if _, _, err := catalog.LoadTable(t.Context(), testTableBucket, []string{testTableNamespace}, "missing", ""); !isNoSuchTable(err) {
t.Fatalf("load of a missing table: %v, want NoSuchTable", err)
}
}