Browse Source

fix remaining tests

pull/7231/head
chrislu 2 months ago
parent
commit
6eafc87413
  1. 16
      weed/mq/kafka/protocol/consumer_coordination.go
  2. 13
      weed/mq/kafka/protocol/fetch.go

16
weed/mq/kafka/protocol/consumer_coordination.go

@ -13,9 +13,9 @@ import (
// HeartbeatRequest represents a Heartbeat request from a Kafka client
type HeartbeatRequest struct {
GroupID string
GenerationID int32
MemberID string
GroupID string
GenerationID int32
MemberID string
GroupInstanceID string // Optional static membership ID
}
@ -30,10 +30,10 @@ type HeartbeatResponse struct {
// LeaveGroupRequest represents a LeaveGroup request from a Kafka client
type LeaveGroupRequest struct {
GroupID string
MemberID string
GroupInstanceID string // Optional static membership ID
Members []LeaveGroupMember // For newer versions, can leave multiple members
GroupID string
MemberID string
GroupInstanceID string // Optional static membership ID
Members []LeaveGroupMember // For newer versions, can leave multiple members
}
// LeaveGroupMember represents a member leaving the group (for batch departures)
@ -278,7 +278,7 @@ func (h *Handler) parseLeaveGroupRequest(data []byte) (*LeaveGroupRequest, error
return &LeaveGroupRequest{
GroupID: groupID,
MemberID: memberID,
GroupInstanceID: "", // Simplified - would parse from remaining data
GroupInstanceID: "", // Simplified - would parse from remaining data
Members: []LeaveGroupMember{}, // Would parse members array for batch operations
}, nil
}

13
weed/mq/kafka/protocol/fetch.go

@ -344,8 +344,9 @@ func (h *Handler) constructRecordBatchFromLedger(ledger interface{}, fetchOffset
batch = append(batch, 0, 0, 0, 0) // partition leader epoch (4 bytes)
batch = append(batch, 2) // magic byte (version 2) (1 byte)
// CRC placeholder (4 bytes) - for testing, use 0
batch = append(batch, 0, 0, 0, 0) // CRC32
// CRC placeholder (4 bytes) - will be calculated at the end
crcPos := len(batch)
batch = append(batch, 0, 0, 0, 0) // CRC32 placeholder
// Batch attributes (2 bytes) - no compression, no transactional
batch = append(batch, 0, 0) // attributes
@ -449,6 +450,14 @@ func (h *Handler) constructRecordBatchFromLedger(ledger interface{}, fetchOffset
batchLength := uint32(len(batch) - batchLengthPos - 4)
binary.BigEndian.PutUint32(batch[batchLengthPos:batchLengthPos+4], batchLength)
// Calculate CRC32 for the batch
// CRC is calculated over: attributes + last_offset_delta + first_timestamp + max_timestamp + producer_id + producer_epoch + base_sequence + records_count + records
// This starts after the CRC field (which comes after magic byte)
crcStartPos := crcPos + 4 // start after the CRC field
crcData := batch[crcStartPos:]
crc := crc32.ChecksumIEEE(crcData)
binary.BigEndian.PutUint32(batch[crcPos:crcPos+4], crc)
return batch
}

Loading…
Cancel
Save