snapshot of https://github.com/seaweedfs/seaweedfs.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled

This commit is contained in:
upstream-mirror
2026-09-16 03:23:42 +05:00
commit 89f5be005d
3997 changed files with 961970 additions and 0 deletions

View File

@@ -0,0 +1,477 @@
package integration
import (
"context"
"encoding/binary"
"fmt"
"io"
"strings"
"time"
"google.golang.org/grpc"
"github.com/seaweedfs/seaweedfs/weed/filer_client"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/mq"
"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"
"github.com/seaweedfs/seaweedfs/weed/security"
"github.com/seaweedfs/seaweedfs/weed/util"
)
const (
brokerHealthCheckTimeout = 5 * time.Second
brokerHealthCheckAttempts = 3
brokerHealthCheckBackoff = 250 * time.Millisecond
)
// NewBrokerClientWithFilerAccessor creates a client with a shared filer accessor
func NewBrokerClientWithFilerAccessor(brokerAddress string, filerClientAccessor *filer_client.FilerClientAccessor) (*BrokerClient, error) {
ctx, cancel := context.WithCancel(context.Background())
// Use background context for gRPC connections to prevent them from being canceled
// when BrokerClient.Close() is called. This allows subscriber streams to continue
// operating even during client shutdown, which is important for testing scenarios.
dialCtx := context.Background()
// CRITICAL FIX: Add timeout to dial context
// gRPC dial will retry with exponential backoff. Without a timeout, it hangs indefinitely
// if the broker is unreachable. Set a reasonable timeout for initial connection attempt.
dialCtx, dialCancel := context.WithTimeout(dialCtx, 30*time.Second)
defer dialCancel()
// Connect to broker
// Load security configuration for broker connection
util.LoadSecurityConfiguration()
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.mq")
conn, err := grpc.DialContext(dialCtx, brokerAddress,
grpcDialOption,
)
if err != nil {
cancel()
return nil, fmt.Errorf("failed to connect to broker %s: %v", brokerAddress, err)
}
client := mq_pb.NewSeaweedMessagingClient(conn)
return &BrokerClient{
filerClientAccessor: filerClientAccessor,
brokerAddress: brokerAddress,
conn: conn,
client: client,
publishers: make(map[string]*BrokerPublisherSession),
subscribers: make(map[string]*BrokerSubscriberSession),
fetchRequests: make(map[string]*FetchRequest),
partitionAssignmentCache: make(map[string]*partitionAssignmentCacheEntry),
partitionAssignmentCacheTTL: 30 * time.Second, // Same as broker's cache TTL
ctx: ctx,
cancel: cancel,
}, nil
}
// Close shuts down the broker client and all streams
func (bc *BrokerClient) Close() error {
bc.cancel()
// Close all publisher streams
bc.publishersLock.Lock()
for key, session := range bc.publishers {
if session.Stream != nil {
_ = session.Stream.CloseSend()
}
delete(bc.publishers, key)
}
bc.publishersLock.Unlock()
// Close all subscriber streams
bc.subscribersLock.Lock()
for key, session := range bc.subscribers {
if session.Stream != nil {
_ = session.Stream.CloseSend()
}
if session.Cancel != nil {
session.Cancel()
}
delete(bc.subscribers, key)
}
bc.subscribersLock.Unlock()
return bc.conn.Close()
}
// HealthCheck verifies the broker connection is working
func (bc *BrokerClient) HealthCheck() error {
if bc.client == nil {
return fmt.Errorf("broker client not connected")
}
var lastErr error
for attempt := 1; attempt <= brokerHealthCheckAttempts; attempt++ {
ctx, cancel := context.WithTimeout(bc.ctx, brokerHealthCheckTimeout)
_, err := bc.client.FindBrokerLeader(ctx, &mq_pb.FindBrokerLeaderRequest{})
cancel()
if err == nil {
return nil
}
lastErr = err
if attempt == brokerHealthCheckAttempts {
break
}
select {
case <-bc.ctx.Done():
return bc.ctx.Err()
case <-time.After(time.Duration(attempt) * brokerHealthCheckBackoff):
}
}
return fmt.Errorf("broker health check failed after %d attempts: %v", brokerHealthCheckAttempts, lastErr)
}
// GetPartitionRangeInfo gets comprehensive range information from SeaweedMQ broker's native range manager
func (bc *BrokerClient) GetPartitionRangeInfo(topic string, partition int32) (*PartitionRangeInfo, error) {
if bc.client == nil {
return nil, fmt.Errorf("broker client not connected")
}
// Get the actual partition assignment from the broker instead of hardcoding
pbTopic := &schema_pb.Topic{
Namespace: "kafka",
Name: topic,
}
// Get the actual partition assignment for this Kafka partition
actualPartition, err := bc.getActualPartitionAssignment(topic, partition)
if err != nil {
return nil, fmt.Errorf("failed to get actual partition assignment: %v", err)
}
// Call the broker's gRPC method
resp, err := bc.client.GetPartitionRangeInfo(context.Background(), &mq_pb.GetPartitionRangeInfoRequest{
Topic: pbTopic,
Partition: actualPartition,
})
if err != nil {
return nil, fmt.Errorf("failed to get partition range info from broker: %v", err)
}
if resp.Error != "" {
return nil, fmt.Errorf("broker error: %s", resp.Error)
}
// Extract offset range information
var earliestOffset, latestOffset, highWaterMark int64
if resp.OffsetRange != nil {
earliestOffset = resp.OffsetRange.EarliestOffset
latestOffset = resp.OffsetRange.LatestOffset
highWaterMark = resp.OffsetRange.HighWaterMark
}
// Extract timestamp range information
var earliestTimestampNs, latestTimestampNs int64
if resp.TimestampRange != nil {
earliestTimestampNs = resp.TimestampRange.EarliestTimestampNs
latestTimestampNs = resp.TimestampRange.LatestTimestampNs
}
info := &PartitionRangeInfo{
EarliestOffset: earliestOffset,
LatestOffset: latestOffset,
HighWaterMark: highWaterMark,
EarliestTimestampNs: earliestTimestampNs,
LatestTimestampNs: latestTimestampNs,
RecordCount: resp.RecordCount,
ActiveSubscriptions: resp.ActiveSubscriptions,
}
return info, nil
}
// GetHighWaterMark gets the high water mark for a topic partition
func (bc *BrokerClient) GetHighWaterMark(topic string, partition int32) (int64, error) {
// Primary approach: Use SeaweedMQ's native range manager via gRPC
info, err := bc.GetPartitionRangeInfo(topic, partition)
if err != nil {
// Fallback to chunk metadata approach
highWaterMark, err := bc.getHighWaterMarkFromChunkMetadata(topic, partition)
if err != nil {
return 0, err
}
return highWaterMark, nil
}
return info.HighWaterMark, nil
}
// GetEarliestOffset gets the earliest offset from SeaweedMQ broker's native offset manager
func (bc *BrokerClient) GetEarliestOffset(topic string, partition int32) (int64, error) {
// Primary approach: Use SeaweedMQ's native range manager via gRPC
info, err := bc.GetPartitionRangeInfo(topic, partition)
if err != nil {
// Fallback to chunk metadata approach
earliestOffset, err := bc.getEarliestOffsetFromChunkMetadata(topic, partition)
if err != nil {
return 0, err
}
return earliestOffset, nil
}
return info.EarliestOffset, nil
}
// getOffsetRangeFromChunkMetadata reads chunk metadata to find both earliest and latest offsets
func (bc *BrokerClient) getOffsetRangeFromChunkMetadata(topic string, partition int32) (earliestOffset int64, highWaterMark int64, err error) {
if bc.filerClientAccessor == nil {
return 0, 0, fmt.Errorf("filer client not available")
}
// Get the topic path and find the latest version
topicPath := fmt.Sprintf("/topics/kafka/%s", topic)
// First, list the topic versions to find the latest
var latestVersion string
err = bc.filerClientAccessor.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
stream, err := client.ListEntries(context.Background(), &filer_pb.ListEntriesRequest{
Directory: topicPath,
})
if err != nil {
return err
}
for {
resp, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
return err
}
if resp.Entry != nil && resp.Entry.IsDirectory && strings.HasPrefix(resp.Entry.Name, "v") {
if latestVersion == "" || resp.Entry.Name > latestVersion {
latestVersion = resp.Entry.Name
}
}
}
return nil
})
if err != nil {
return 0, 0, fmt.Errorf("failed to list topic versions: %v", err)
}
if latestVersion == "" {
return 0, 0, nil
}
// Find the partition directory
versionPath := fmt.Sprintf("%s/%s", topicPath, latestVersion)
var partitionDir string
err = bc.filerClientAccessor.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
stream, err := client.ListEntries(context.Background(), &filer_pb.ListEntriesRequest{
Directory: versionPath,
})
if err != nil {
return err
}
for {
resp, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
return err
}
if resp.Entry != nil && resp.Entry.IsDirectory && strings.Contains(resp.Entry.Name, "-") {
// Parse partition range (format: NNNN-NNNN) and match requested partition
var pStart, pStop int32
if n, scanErr := fmt.Sscanf(resp.Entry.Name, "%04d-%04d", &pStart, &pStop); n == 2 && scanErr == nil {
if partition >= pStart && partition < pStop {
partitionDir = resp.Entry.Name
break
}
}
}
}
return nil
})
if err != nil {
return 0, 0, fmt.Errorf("failed to list partition directories: %v", err)
}
if partitionDir == "" {
return 0, 0, nil
}
// Scan all message files to find the highest offset_max and lowest offset_min
partitionPath := fmt.Sprintf("%s/%s", versionPath, partitionDir)
highWaterMark = 0
earliestOffset = -1 // -1 indicates no data found yet
err = bc.filerClientAccessor.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
stream, err := client.ListEntries(context.Background(), &filer_pb.ListEntriesRequest{
Directory: partitionPath,
})
if err != nil {
return err
}
for {
resp, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
return err
}
if resp.Entry != nil && !resp.Entry.IsDirectory && resp.Entry.Name != "checkpoint.offset" {
// Check for offset ranges in Extended attributes (both log files and parquet files)
if resp.Entry.Extended != nil {
// Track maximum offset for high water mark
if maxOffsetBytes, exists := resp.Entry.Extended[mq.ExtendedAttrOffsetMax]; exists && len(maxOffsetBytes) == 8 {
maxOffset := int64(binary.BigEndian.Uint64(maxOffsetBytes))
if maxOffset > highWaterMark {
highWaterMark = maxOffset
}
}
// Track minimum offset for earliest offset
if minOffsetBytes, exists := resp.Entry.Extended[mq.ExtendedAttrOffsetMin]; exists && len(minOffsetBytes) == 8 {
minOffset := int64(binary.BigEndian.Uint64(minOffsetBytes))
if earliestOffset == -1 || minOffset < earliestOffset {
earliestOffset = minOffset
}
}
}
}
}
return nil
})
if err != nil {
return 0, 0, fmt.Errorf("failed to scan message files: %v", err)
}
// High water mark is the next offset after the highest written offset
if highWaterMark > 0 {
highWaterMark++
}
// If no data found, set earliest offset to 0
if earliestOffset == -1 {
earliestOffset = 0
}
return earliestOffset, highWaterMark, nil
}
// getHighWaterMarkFromChunkMetadata is a wrapper for backward compatibility
func (bc *BrokerClient) getHighWaterMarkFromChunkMetadata(topic string, partition int32) (int64, error) {
_, highWaterMark, err := bc.getOffsetRangeFromChunkMetadata(topic, partition)
return highWaterMark, err
}
// getEarliestOffsetFromChunkMetadata gets the earliest offset from chunk metadata (fallback)
func (bc *BrokerClient) getEarliestOffsetFromChunkMetadata(topic string, partition int32) (int64, error) {
earliestOffset, _, err := bc.getOffsetRangeFromChunkMetadata(topic, partition)
return earliestOffset, err
}
// GetFilerAddress returns the first filer address used by this broker client (for backward compatibility)
func (bc *BrokerClient) GetFilerAddress() string {
if bc.filerClientAccessor != nil && bc.filerClientAccessor.GetFilers != nil {
filers := bc.filerClientAccessor.GetFilers()
if len(filers) > 0 {
return string(filers[0])
}
}
return ""
}
// Delegate methods to the shared filer client accessor
func (bc *BrokerClient) WithFilerClient(streamingMode bool, fn func(client filer_pb.SeaweedFilerClient) error) error {
return bc.filerClientAccessor.WithFilerClient(streamingMode, fn)
}
func (bc *BrokerClient) GetFilers() []pb.ServerAddress {
return bc.filerClientAccessor.GetFilers()
}
func (bc *BrokerClient) GetGrpcDialOption() grpc.DialOption {
return bc.filerClientAccessor.GetGrpcDialOption()
}
// ListTopics gets all topics from SeaweedMQ broker (includes in-memory topics)
func (bc *BrokerClient) ListTopics() ([]string, error) {
if bc.client == nil {
return nil, fmt.Errorf("broker client not connected")
}
ctx, cancel := context.WithTimeout(bc.ctx, 5*time.Second)
defer cancel()
resp, err := bc.client.ListTopics(ctx, &mq_pb.ListTopicsRequest{})
if err != nil {
return nil, fmt.Errorf("failed to list topics from broker: %v", err)
}
var topics []string
for _, topic := range resp.Topics {
// Filter for kafka namespace topics
if topic.Namespace == "kafka" {
topics = append(topics, topic.Name)
}
}
return topics, nil
}
// GetTopicConfiguration gets topic configuration including partition count from the broker
func (bc *BrokerClient) GetTopicConfiguration(topicName string) (*mq_pb.GetTopicConfigurationResponse, error) {
if bc.client == nil {
return nil, fmt.Errorf("broker client not connected")
}
ctx, cancel := context.WithTimeout(bc.ctx, 5*time.Second)
defer cancel()
resp, err := bc.client.GetTopicConfiguration(ctx, &mq_pb.GetTopicConfigurationRequest{
Topic: &schema_pb.Topic{
Namespace: "kafka",
Name: topicName,
},
})
if err != nil {
return nil, fmt.Errorf("failed to get topic configuration from broker: %v", err)
}
return resp, nil
}
// TopicExists checks if a topic exists in SeaweedMQ broker (includes in-memory topics)
func (bc *BrokerClient) TopicExists(topicName string) (bool, error) {
if bc.client == nil {
return false, fmt.Errorf("broker client not connected")
}
ctx, cancel := context.WithTimeout(bc.ctx, 5*time.Second)
defer cancel()
glog.V(2).Infof("[BrokerClient] TopicExists: Querying broker for topic %s", topicName)
resp, err := bc.client.TopicExists(ctx, &mq_pb.TopicExistsRequest{
Topic: &schema_pb.Topic{
Namespace: "kafka",
Name: topicName,
},
})
if err != nil {
glog.V(1).Infof("[BrokerClient] TopicExists: ERROR for topic %s: %v", topicName, err)
return false, fmt.Errorf("failed to check topic existence: %v", err)
}
glog.V(2).Infof("[BrokerClient] TopicExists: Topic %s exists=%v", topicName, resp.Exists)
return resp.Exists, nil
}