mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-24 06:50:40 +02:00
Changed remaining debug log messages with bracket prefixes from
glog.Infof() to glog.V(3).Infof() to prevent them from showing
in production logs by default.
Changes (8 messages across 3 files):
- glog.Infof("[") -> glog.V(3).Infof("[")
Files updated:
- weed/mq/broker/broker_grpc_fetch.go (4 messages)
- [FetchMessage] CALLED! debug marker
- [FetchMessage] request details
- [FetchMessage] LogBuffer read start
- [FetchMessage] LogBuffer read completion
- weed/mq/kafka/integration/broker_client_fetch.go (3 messages)
- [FETCH-STATELESS-CLIENT] received messages
- [FETCH-STATELESS-CLIENT] converted records (with data)
- [FETCH-STATELESS-CLIENT] converted records (empty)
- weed/mq/kafka/integration/broker_client_publish.go (1 message)
- [GATEWAY RECV] _schemas topic debug
Now ALL debug messages with bracket prefixes require -v=3 or higher:
- Default (-v=0): Clean production logs ✅
- -v=3: All debug messages visible
- -v=4: All verbose debug messages visible
Result: Production logs are now clean with default settings!
179 lines
6.0 KiB
Go
179 lines
6.0 KiB
Go
package integration
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
|
|
)
|
|
|
|
// FetchMessagesStateless fetches messages using the Kafka-style stateless FetchMessage RPC
|
|
// This is the long-term solution that eliminates all Subscribe loop complexity
|
|
//
|
|
// Benefits over SubscribeMessage:
|
|
// 1. No broker-side session state
|
|
// 2. No shared Subscribe loops
|
|
// 3. No stream corruption from concurrent seeks
|
|
// 4. Simple request/response pattern
|
|
// 5. Natural support for concurrent reads
|
|
//
|
|
// This is how Kafka works - completely stateless per-fetch
|
|
func (bc *BrokerClient) FetchMessagesStateless(ctx context.Context, topic string, partition int32, startOffset int64, maxRecords int, consumerGroup string, consumerID string) ([]*SeaweedRecord, error) {
|
|
glog.V(4).Infof("[FETCH-STATELESS] Fetching from %s-%d at offset %d, maxRecords=%d",
|
|
topic, partition, startOffset, maxRecords)
|
|
|
|
// Get actual partition assignment from broker
|
|
actualPartition, err := bc.getActualPartitionAssignment(topic, partition)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to get partition assignment: %v", err)
|
|
}
|
|
|
|
// Create FetchMessage request
|
|
req := &mq_pb.FetchMessageRequest{
|
|
Topic: &schema_pb.Topic{
|
|
Namespace: "kafka", // Kafka gateway always uses "kafka" namespace
|
|
Name: topic,
|
|
},
|
|
Partition: actualPartition,
|
|
StartOffset: startOffset,
|
|
MaxMessages: int32(maxRecords),
|
|
MaxBytes: 4 * 1024 * 1024, // 4MB default
|
|
MaxWaitMs: 100, // 100ms wait for data (long poll)
|
|
MinBytes: 0, // Return immediately if any data available
|
|
ConsumerGroup: consumerGroup,
|
|
ConsumerId: consumerID,
|
|
}
|
|
|
|
// Get timeout from context (set by Kafka fetch request)
|
|
// This respects the client's MaxWaitTime
|
|
// Note: We use a default of 100ms above, but if context has shorter timeout, use that
|
|
|
|
// Call FetchMessage RPC (simple request/response)
|
|
resp, err := bc.client.FetchMessage(ctx, req)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("FetchMessage RPC failed: %v", err)
|
|
}
|
|
|
|
// Check for errors in response
|
|
if resp.Error != "" {
|
|
// Check if this is an "offset out of range" error
|
|
if resp.ErrorCode == 2 && resp.LogStartOffset > 0 && startOffset < resp.LogStartOffset {
|
|
// Offset too old - broker suggests starting from LogStartOffset
|
|
glog.V(3).Infof("[FETCH-STATELESS-CLIENT] Requested offset %d too old, adjusting to log start %d",
|
|
startOffset, resp.LogStartOffset)
|
|
|
|
// Retry with adjusted offset
|
|
req.StartOffset = resp.LogStartOffset
|
|
resp, err = bc.client.FetchMessage(ctx, req)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("FetchMessage RPC failed on retry: %v", err)
|
|
}
|
|
if resp.Error != "" {
|
|
return nil, fmt.Errorf("broker error on retry: %s (code=%d)", resp.Error, resp.ErrorCode)
|
|
}
|
|
// Continue with adjusted offset response
|
|
startOffset = resp.LogStartOffset
|
|
} else {
|
|
return nil, fmt.Errorf("broker error: %s (code=%d)", resp.Error, resp.ErrorCode)
|
|
}
|
|
}
|
|
|
|
glog.V(3).Infof("[FETCH-STATELESS-CLIENT] Received %d messages from broker, nextOffset=%d, hwm=%d",
|
|
len(resp.Messages), resp.NextOffset, resp.HighWaterMark)
|
|
|
|
// Convert protobuf messages to SeaweedRecord
|
|
records := make([]*SeaweedRecord, 0, len(resp.Messages))
|
|
for i, msg := range resp.Messages {
|
|
record := &SeaweedRecord{
|
|
Key: msg.Key,
|
|
Value: msg.Value,
|
|
Timestamp: msg.TsNs,
|
|
Offset: startOffset + int64(i), // Sequential offset assignment
|
|
}
|
|
records = append(records, record)
|
|
}
|
|
|
|
if len(records) > 0 {
|
|
glog.V(3).Infof("[FETCH-STATELESS-CLIENT] Converted to %d SeaweedRecords, first offset=%d, last offset=%d",
|
|
len(records), records[0].Offset, records[len(records)-1].Offset)
|
|
} else {
|
|
glog.V(3).Infof("[FETCH-STATELESS-CLIENT] Converted to 0 SeaweedRecords")
|
|
}
|
|
|
|
glog.V(4).Infof("[FETCH-STATELESS] Fetched %d records, nextOffset=%d, highWaterMark=%d, endOfPartition=%v",
|
|
len(records), resp.NextOffset, resp.HighWaterMark, resp.EndOfPartition)
|
|
|
|
return records, nil
|
|
}
|
|
|
|
// GetPartitionHighWaterMark returns the highest offset available in a partition
|
|
// This is useful for Kafka clients to track consumer lag
|
|
func (bc *BrokerClient) GetPartitionHighWaterMark(ctx context.Context, topic string, partition int32) (int64, error) {
|
|
// Use FetchMessage with 0 maxRecords to just get metadata
|
|
actualPartition, err := bc.getActualPartitionAssignment(topic, partition)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("failed to get partition assignment: %v", err)
|
|
}
|
|
|
|
req := &mq_pb.FetchMessageRequest{
|
|
Topic: &schema_pb.Topic{
|
|
Namespace: "kafka",
|
|
Name: topic,
|
|
},
|
|
Partition: actualPartition,
|
|
StartOffset: 0,
|
|
MaxMessages: 0, // Just get metadata
|
|
MaxBytes: 0,
|
|
MaxWaitMs: 0, // Return immediately
|
|
ConsumerGroup: "kafka-metadata",
|
|
ConsumerId: "hwm-check",
|
|
}
|
|
|
|
resp, err := bc.client.FetchMessage(ctx, req)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("FetchMessage RPC failed: %v", err)
|
|
}
|
|
|
|
if resp.Error != "" {
|
|
return 0, fmt.Errorf("broker error: %s", resp.Error)
|
|
}
|
|
|
|
return resp.HighWaterMark, nil
|
|
}
|
|
|
|
// GetPartitionLogStartOffset returns the earliest offset available in a partition
|
|
// This is useful for Kafka clients to know the valid offset range
|
|
func (bc *BrokerClient) GetPartitionLogStartOffset(ctx context.Context, topic string, partition int32) (int64, error) {
|
|
actualPartition, err := bc.getActualPartitionAssignment(topic, partition)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("failed to get partition assignment: %v", err)
|
|
}
|
|
|
|
req := &mq_pb.FetchMessageRequest{
|
|
Topic: &schema_pb.Topic{
|
|
Namespace: "kafka",
|
|
Name: topic,
|
|
},
|
|
Partition: actualPartition,
|
|
StartOffset: 0,
|
|
MaxMessages: 0,
|
|
MaxBytes: 0,
|
|
MaxWaitMs: 0,
|
|
ConsumerGroup: "kafka-metadata",
|
|
ConsumerId: "lso-check",
|
|
}
|
|
|
|
resp, err := bc.client.FetchMessage(ctx, req)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("FetchMessage RPC failed: %v", err)
|
|
}
|
|
|
|
if resp.Error != "" {
|
|
return 0, fmt.Errorf("broker error: %s", resp.Error)
|
|
}
|
|
|
|
return resp.LogStartOffset, nil
|
|
}
|