mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-05 19:47:47 +01:00
mq(kafka): debug Metadata v1 format compatibility with kafka-go ReadPartitions
- Added detailed hex dump comparison between v0 and v1 responses - Identified v1 adds rack field (2 bytes) and is_internal field (1 byte) = 3 bytes total - kafka-go still fails with 'multiple Read calls return no data or error' - Our Metadata v1 format appears correct per protocol spec but incompatible with kafka-go
This commit is contained in:
1 parent
ef609eebd2
commit
5cc05d8ba7
5 files changed
+470
-9
No files matched your search
@@ -0,0 +1,95 @@
|
||||
package kafka
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/segmentio/kafka-go"
|
||||
"github.com/seaweedfs/seaweedfs/weed/mq/kafka/gateway"
|
||||
)
|
||||
|
||||
// TestConnectionDebug debugs the exact connection behavior between kafka-go and our gateway
|
||||
func TestConnectionDebug(t *testing.T) {
|
||||
// Start gateway server
|
||||
gatewayServer := gateway.NewServer(gateway.Options{
|
||||
Listen: ":0", // random port
|
||||
})
|
||||
|
||||
go func() {
|
||||
if err := gatewayServer.Start(); err != nil {
|
||||
t.Errorf("Gateway server error: %v", err)
|
||||
}
|
||||
}()
|
||||
defer gatewayServer.Close()
|
||||
|
||||
// Wait for server to start
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Get the actual listening address
|
||||
host, port := gatewayServer.GetListenerAddr()
|
||||
brokerAddr := fmt.Sprintf("%s:%d", host, port)
|
||||
t.Logf("Gateway running on %s", brokerAddr)
|
||||
|
||||
// Get handler and configure it
|
||||
handler := gatewayServer.GetHandler()
|
||||
handler.SetBrokerAddress(host, port)
|
||||
|
||||
// Add test topic
|
||||
topicName := "conn-debug-topic"
|
||||
handler.AddTopicForTesting(topicName, 1)
|
||||
|
||||
// Test 1: Manual connection that works
|
||||
t.Log("=== Test 1: Manual TCP connection ===")
|
||||
conn, err := net.Dial("tcp", brokerAddr)
|
||||
if err != nil {
|
||||
t.Fatalf("Manual connection failed: %v", err)
|
||||
}
|
||||
|
||||
// Send a simple request and read response
|
||||
// This should work based on our previous debug test
|
||||
conn.Close()
|
||||
t.Log("Manual connection works fine")
|
||||
|
||||
// Test 2: kafka-go Dialer connection
|
||||
t.Log("=== Test 2: kafka-go Dialer connection ===")
|
||||
dialer := &kafka.Dialer{
|
||||
Timeout: 5 * time.Second,
|
||||
}
|
||||
|
||||
kafkaConn, err := dialer.Dial("tcp", brokerAddr)
|
||||
if err != nil {
|
||||
t.Fatalf("kafka-go connection failed: %v", err)
|
||||
}
|
||||
defer kafkaConn.Close()
|
||||
|
||||
t.Log("kafka-go connection established")
|
||||
|
||||
// Test 3: Try to read partitions with detailed error handling
|
||||
t.Log("=== Test 3: kafka-go ReadPartitions with error details ===")
|
||||
|
||||
// Set a deadline to avoid hanging
|
||||
kafkaConn.SetDeadline(time.Now().Add(10 * time.Second))
|
||||
|
||||
partitions, err := kafkaConn.ReadPartitions(topicName)
|
||||
if err != nil {
|
||||
t.Logf("ReadPartitions failed with error: %v", err)
|
||||
t.Logf("Error type: %T", err)
|
||||
|
||||
// Try to get more details about the error
|
||||
if netErr, ok := err.(net.Error); ok {
|
||||
t.Logf("Network error - Timeout: %v, Temporary: %v", netErr.Timeout(), netErr.Temporary())
|
||||
}
|
||||
|
||||
// The error might give us clues about what's wrong
|
||||
return
|
||||
}
|
||||
|
||||
t.Logf("ReadPartitions succeeded! Found %d partitions", len(partitions))
|
||||
for i, partition := range partitions {
|
||||
t.Logf("Partition %d: Topic=%s, ID=%d, Leader=%v", i, partition.Topic, partition.ID, partition.Leader)
|
||||
}
|
||||
|
||||
t.Log("✅ Connection debug test completed!")
|
||||
}
|
||||
Reference in new issue
Block a user