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
352 lines
12 KiB
Go
352 lines
12 KiB
Go
package broker
|
|
|
|
import (
|
|
"context"
|
|
"encoding/binary"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
|
|
"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/util/log_buffer"
|
|
)
|
|
|
|
// BufferRange represents a range of buffer offsets that have been flushed to disk
|
|
type BufferRange struct {
|
|
start int64
|
|
end int64
|
|
}
|
|
|
|
// ErrNoPartitionAssignment indicates no broker assignment found for the partition.
|
|
// This is a normal case that means there are no unflushed messages for this partition.
|
|
var ErrNoPartitionAssignment = errors.New("no broker assignment found for partition")
|
|
|
|
// GetUnflushedMessages returns messages from the broker's in-memory LogBuffer
|
|
// that haven't been flushed to disk yet, using buffer_start metadata for deduplication
|
|
// Now supports streaming responses and buffer offset filtering for better performance
|
|
// Includes broker routing to redirect requests to the correct broker hosting the topic/partition
|
|
func (b *MessageQueueBroker) GetUnflushedMessages(req *mq_pb.GetUnflushedMessagesRequest, stream mq_pb.SeaweedMessaging_GetUnflushedMessagesServer) error {
|
|
// Convert protobuf types to internal types
|
|
t := topic.FromPbTopic(req.Topic)
|
|
partition := topic.FromPbPartition(req.Partition)
|
|
|
|
// Get or generate the local partition for this topic/partition (similar to subscriber flow)
|
|
localPartition, getOrGenErr := b.GetOrGenerateLocalPartition(t, partition)
|
|
if getOrGenErr != nil {
|
|
// Fall back to the original logic for broker routing
|
|
b.accessLock.Lock()
|
|
localPartition = b.localTopicManager.GetLocalPartition(t, partition)
|
|
b.accessLock.Unlock()
|
|
} else {
|
|
}
|
|
|
|
if localPartition == nil {
|
|
// Topic/partition not found locally, attempt to find the correct broker and redirect
|
|
glog.V(1).Infof("Topic/partition %v %v not found locally, looking up broker", t, partition)
|
|
|
|
// Look up which broker hosts this topic/partition
|
|
brokerHost, err := b.findBrokerForTopicPartition(req.Topic, req.Partition)
|
|
if err != nil {
|
|
if errors.Is(err, ErrNoPartitionAssignment) {
|
|
// Normal case: no broker assignment means no unflushed messages
|
|
glog.V(2).Infof("No broker assignment for %v %v - no unflushed messages", t, partition)
|
|
return stream.Send(&mq_pb.GetUnflushedMessagesResponse{
|
|
EndOfStream: true,
|
|
})
|
|
}
|
|
return stream.Send(&mq_pb.GetUnflushedMessagesResponse{
|
|
Error: fmt.Sprintf("failed to find broker for %v %v: %v", t, partition, err),
|
|
EndOfStream: true,
|
|
})
|
|
}
|
|
|
|
if brokerHost == "" {
|
|
// This should not happen after ErrNoPartitionAssignment check, but keep for safety
|
|
glog.V(2).Infof("Empty broker host for %v %v - no unflushed messages", t, partition)
|
|
return stream.Send(&mq_pb.GetUnflushedMessagesResponse{
|
|
EndOfStream: true,
|
|
})
|
|
}
|
|
|
|
// Redirect to the correct broker
|
|
glog.V(1).Infof("Redirecting GetUnflushedMessages request for %v %v to broker %s", t, partition, brokerHost)
|
|
return b.redirectGetUnflushedMessages(brokerHost, req, stream)
|
|
}
|
|
|
|
// Build deduplication map from existing log files using buffer_start metadata
|
|
partitionDir := topic.PartitionDir(t, partition)
|
|
flushedBufferRanges, err := b.buildBufferStartDeduplicationMap(partitionDir)
|
|
if err != nil {
|
|
glog.Errorf("Failed to build deduplication map for %v %v: %v", t, partition, err)
|
|
// Continue with empty map - better to potentially duplicate than to miss data
|
|
flushedBufferRanges = make([]BufferRange, 0)
|
|
}
|
|
|
|
// Use buffer_start offset for precise deduplication
|
|
lastFlushTsNs := localPartition.LogBuffer.GetLastFlushTsNs()
|
|
startBufferOffset := req.StartBufferOffset
|
|
startTimeNs := lastFlushTsNs // Still respect last flush time for safety
|
|
|
|
// Stream messages from LogBuffer with filtering
|
|
messageCount := 0
|
|
startPosition := log_buffer.NewMessagePosition(startTimeNs, startBufferOffset)
|
|
|
|
// Use the new LoopProcessLogDataWithOffset method to avoid code duplication
|
|
_, _, err = localPartition.LogBuffer.LoopProcessLogDataWithOffset(
|
|
"GetUnflushedMessages",
|
|
startPosition,
|
|
0, // stopTsNs = 0 means process all available data
|
|
func() bool { return false }, // waitForDataFn = false means don't wait for new data
|
|
func(logEntry *filer_pb.LogEntry, offset int64) (isDone bool, err error) {
|
|
|
|
// Apply buffer offset filtering if specified
|
|
if startBufferOffset > 0 && offset < startBufferOffset {
|
|
return false, nil
|
|
}
|
|
|
|
// Check if this message is from a buffer range that's already been flushed
|
|
if b.isBufferOffsetFlushed(offset, flushedBufferRanges) {
|
|
return false, nil
|
|
}
|
|
|
|
// Stream this message
|
|
err = stream.Send(&mq_pb.GetUnflushedMessagesResponse{
|
|
Message: logEntry,
|
|
EndOfStream: false,
|
|
})
|
|
|
|
if err != nil {
|
|
glog.Errorf("Failed to stream message: %v", err)
|
|
return true, err // isDone = true to stop processing
|
|
}
|
|
|
|
messageCount++
|
|
return false, nil // Continue processing
|
|
},
|
|
)
|
|
|
|
// Handle collection errors
|
|
if err != nil && err != log_buffer.ResumeFromDiskError {
|
|
streamErr := stream.Send(&mq_pb.GetUnflushedMessagesResponse{
|
|
Error: fmt.Sprintf("failed to stream unflushed messages: %v", err),
|
|
EndOfStream: true,
|
|
})
|
|
if streamErr != nil {
|
|
glog.Errorf("Failed to send error response: %v", streamErr)
|
|
}
|
|
return err
|
|
}
|
|
|
|
// Send end-of-stream marker
|
|
err = stream.Send(&mq_pb.GetUnflushedMessagesResponse{
|
|
EndOfStream: true,
|
|
})
|
|
|
|
if err != nil {
|
|
glog.Errorf("Failed to send end-of-stream marker: %v", err)
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// buildBufferStartDeduplicationMap scans log files to build a map of buffer ranges
|
|
// that have been flushed to disk, using the buffer_start metadata
|
|
func (b *MessageQueueBroker) buildBufferStartDeduplicationMap(partitionDir string) ([]BufferRange, error) {
|
|
var flushedRanges []BufferRange
|
|
|
|
// List all files in the partition directory using filer client accessor
|
|
// Use pagination to handle directories with more than 1000 files
|
|
err := b.fca.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
|
var lastFileName string
|
|
var hasMore = true
|
|
|
|
for hasMore {
|
|
var currentBatchProcessed int
|
|
err := filer_pb.SeaweedList(context.Background(), client, partitionDir, "", func(entry *filer_pb.Entry, isLast bool) error {
|
|
currentBatchProcessed++
|
|
hasMore = !isLast // If this is the last entry of a full batch, there might be more
|
|
lastFileName = entry.Name
|
|
|
|
if entry.IsDirectory {
|
|
return nil
|
|
}
|
|
|
|
// Skip Parquet files - they don't represent buffer ranges
|
|
if strings.HasSuffix(entry.Name, ".parquet") {
|
|
return nil
|
|
}
|
|
|
|
// Skip offset files
|
|
if strings.HasSuffix(entry.Name, ".offset") {
|
|
return nil
|
|
}
|
|
|
|
// Get buffer start for this file
|
|
bufferStart, err := b.getLogBufferStartFromFile(entry)
|
|
if err != nil {
|
|
glog.V(2).Infof("Failed to get buffer start from file %s: %v", entry.Name, err)
|
|
return nil // Continue with other files
|
|
}
|
|
|
|
if bufferStart == nil {
|
|
// File has no buffer metadata - skip deduplication for this file
|
|
glog.V(2).Infof("File %s has no buffer_start metadata", entry.Name)
|
|
return nil
|
|
}
|
|
|
|
// Calculate the buffer range covered by this file
|
|
chunkCount := int64(len(entry.GetChunks()))
|
|
if chunkCount > 0 {
|
|
fileRange := BufferRange{
|
|
start: bufferStart.StartIndex,
|
|
end: bufferStart.StartIndex + chunkCount - 1,
|
|
}
|
|
flushedRanges = append(flushedRanges, fileRange)
|
|
glog.V(3).Infof("File %s covers buffer range [%d-%d]", entry.Name, fileRange.start, fileRange.end)
|
|
}
|
|
|
|
return nil
|
|
}, lastFileName, false, 1000) // Start from last processed file name for next batch
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// If we processed fewer than 1000 entries, we've reached the end
|
|
if currentBatchProcessed < 1000 {
|
|
hasMore = false
|
|
}
|
|
}
|
|
|
|
return nil
|
|
})
|
|
|
|
if err != nil {
|
|
return flushedRanges, fmt.Errorf("failed to list partition directory %s: %v", partitionDir, err)
|
|
}
|
|
|
|
return flushedRanges, nil
|
|
}
|
|
|
|
// getLogBufferStartFromFile extracts LogBufferStart metadata from a log file
|
|
func (b *MessageQueueBroker) getLogBufferStartFromFile(entry *filer_pb.Entry) (*LogBufferStart, error) {
|
|
if entry.Extended == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
// Only support binary buffer_start format
|
|
if startData, exists := entry.Extended["buffer_start"]; exists {
|
|
if len(startData) == 8 {
|
|
startIndex := int64(binary.BigEndian.Uint64(startData))
|
|
if startIndex > 0 {
|
|
return &LogBufferStart{StartIndex: startIndex}, nil
|
|
}
|
|
} else {
|
|
return nil, fmt.Errorf("invalid buffer_start format: expected 8 bytes, got %d", len(startData))
|
|
}
|
|
}
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
// isBufferOffsetFlushed checks if a buffer offset is covered by any of the flushed ranges
|
|
func (b *MessageQueueBroker) isBufferOffsetFlushed(bufferOffset int64, flushedRanges []BufferRange) bool {
|
|
for _, flushedRange := range flushedRanges {
|
|
if bufferOffset >= flushedRange.start && bufferOffset <= flushedRange.end {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// findBrokerForTopicPartition finds which broker hosts the specified topic/partition
|
|
func (b *MessageQueueBroker) findBrokerForTopicPartition(topic *schema_pb.Topic, partition *schema_pb.Partition) (string, error) {
|
|
// Use LookupTopicBrokers to find which broker hosts this topic/partition
|
|
ctx := context.Background()
|
|
lookupReq := &mq_pb.LookupTopicBrokersRequest{
|
|
Topic: topic,
|
|
}
|
|
|
|
// If we're not the lock owner (balancer), we need to redirect to the balancer first
|
|
var lookupResp *mq_pb.LookupTopicBrokersResponse
|
|
var err error
|
|
|
|
if !b.isLockOwner() {
|
|
// Redirect to balancer to get topic broker assignments
|
|
balancerAddress := pb.ServerAddress(b.lockAsBalancer.LockOwner())
|
|
err = b.withBrokerClient(false, balancerAddress, func(client mq_pb.SeaweedMessagingClient) error {
|
|
lookupResp, err = client.LookupTopicBrokers(ctx, lookupReq)
|
|
return err
|
|
})
|
|
} else {
|
|
// We are the balancer, handle the lookup directly
|
|
lookupResp, err = b.LookupTopicBrokers(ctx, lookupReq)
|
|
}
|
|
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to lookup topic brokers: %v", err)
|
|
}
|
|
|
|
// Find the broker assignment that matches our partition
|
|
for _, assignment := range lookupResp.BrokerPartitionAssignments {
|
|
if b.partitionsMatch(partition, assignment.Partition) {
|
|
if assignment.LeaderBroker != "" {
|
|
return assignment.LeaderBroker, nil
|
|
}
|
|
}
|
|
}
|
|
|
|
return "", ErrNoPartitionAssignment
|
|
}
|
|
|
|
// partitionsMatch checks if two partitions represent the same partition
|
|
func (b *MessageQueueBroker) partitionsMatch(p1, p2 *schema_pb.Partition) bool {
|
|
return p1.RingSize == p2.RingSize &&
|
|
p1.RangeStart == p2.RangeStart &&
|
|
p1.RangeStop == p2.RangeStop &&
|
|
p1.UnixTimeNs == p2.UnixTimeNs
|
|
}
|
|
|
|
// redirectGetUnflushedMessages forwards the GetUnflushedMessages request to the correct broker
|
|
func (b *MessageQueueBroker) redirectGetUnflushedMessages(brokerHost string, req *mq_pb.GetUnflushedMessagesRequest, stream mq_pb.SeaweedMessaging_GetUnflushedMessagesServer) error {
|
|
ctx := stream.Context()
|
|
|
|
// Connect to the target broker and forward the request
|
|
return b.withBrokerClient(false, pb.ServerAddress(brokerHost), func(client mq_pb.SeaweedMessagingClient) error {
|
|
// Create a new stream to the target broker
|
|
targetStream, err := client.GetUnflushedMessages(ctx, req)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create stream to broker %s: %v", brokerHost, err)
|
|
}
|
|
|
|
// Forward all responses from the target broker to our client
|
|
for {
|
|
response, err := targetStream.Recv()
|
|
if err != nil {
|
|
if errors.Is(err, io.EOF) {
|
|
// Normal end of stream
|
|
return nil
|
|
}
|
|
return fmt.Errorf("error receiving from broker %s: %v", brokerHost, err)
|
|
}
|
|
|
|
// Forward the response to our client
|
|
if sendErr := stream.Send(response); sendErr != nil {
|
|
return fmt.Errorf("error forwarding response to client: %v", sendErr)
|
|
}
|
|
|
|
// Check if this is the end of stream
|
|
if response.EndOfStream {
|
|
return nil
|
|
}
|
|
}
|
|
})
|
|
}
|