Git Product home page Git Product logo

Comments (6)

achille-roussel avatar achille-roussel commented on May 14, 2024

Do you mind giving a bit more info about the version of Kafka you're running? Also if you have some code to reproduce the issue in isolation that would be a good start for me to dig into the issue.

from kafka-go.

newhook avatar newhook commented on May 14, 2024

We're running kafka 2.11-1. The code I was testing with is as follows. Note that the data is snappy encoded. We originally inserted the data into kafka using kafkacat.

kafkacat -P -b kafka-1 -t server-invalid -z snappy

package main

import (
	"bytes"
	"context"
	"encoding/binary"
	"fmt"

	"github.com/golang/snappy"
	kafka "github.com/kafka-go"
)

var xerialHeader = []byte{130, 83, 78, 65, 80, 80, 89, 0}

// Decode decodes snappy data whether it is traditional unframed
// or includes the xerial framing format.
func Decode(src []byte) ([]byte, error) {
	if !bytes.Equal(src[:8], xerialHeader) {
		return snappy.Decode(nil, src)
	}

	var (
		pos   = uint32(16)
		max   = uint32(len(src))
		dst   = make([]byte, 0, len(src))
		chunk []byte
		err   error
	)
	for pos < max {
		size := binary.BigEndian.Uint32(src[pos : pos+4])
		pos += 4

		chunk, err = snappy.Decode(chunk, src[pos:pos+size])
		if err != nil {
			return nil, err
		}
		pos += size
		dst = append(dst, chunk...)
	}
	return dst, nil
}

func main() {
	r := kafka.NewReader(kafka.ReaderConfig{
		Brokers:   []string{"kafka-1:9092"},
		Topic:     "server-invalid",
		Partition: 0,
		MinBytes:  10e3, // 10KB
		MaxBytes:  10e6, // 10MB
	})
	r.SetOffset(46356099)

	for {
		m, err := r.ReadMessage(context.Background())
		if err != nil {
			fmt.Println(err)
			break
		}
		data, err := Decode(m.Value)
		if err != nil {
			fmt.Println(err)
			break
		}
		for i, c := range data {
			fmt.Printf("%x ", c)
		}
		fmt.Printf("\n")
		fmt.Printf("message at offset %d: %s = %s\n", m.Offset, string(m.Key), string(data))
		break
	}

	r.Close()
}

from kafka-go.

Pryz avatar Pryz commented on May 14, 2024

Hey @newhook , are you still experiencing this issue ?

2.11-1 is probably the version of Scala used by Kafka but not the version of Kafka itself. The version of Kafka will be something like : 0.10.2.2, 0.11.0.1, 1.1.0 etc etc.

Note that kafka-go will handle compression once #106 is merged.

from kafka-go.

joepurdy avatar joepurdy commented on May 14, 2024

Hey @Pryz, I work with @newhook and took another look at this issue this morning to see if we can still reproduce.

We're currently running kafka 1.0.1 w/ Scala 2.11

I ran the same code from before using the latest version of the kafka-go to reproduce the issue with leading characters:

joe@WASP-12b ~/src/github.com/segmentio/kafka-go $ git rev-parse --verify HEAD                                                                                                                       
48c37f796910d8154479aaa04ade5843ae4f55d0

joe@WASP-12b ~/src/github.com/segmentio/kafka-go $ git rev-parse --verify origin/master                                                                                                              
48c37f796910d8154479aaa04ade5843ae4f55d0

joe@WASP-12b ~/src/github.com/customerio/x/kafka-test $ ./kafka-test > "output.log"

And the output still includes leading characters:

0 0 0 0 33 9c 1a 93 0 2 a8 3f 27 cf 51 a7 0 0 ff ff ff ff 0 2 a8 31
...
message at offset 865868659:  = 3���?'�Q������1{"level":"info",

The code I ran with ./kafka-test is the same as what was provided before on this issue.

I'll be taking a closer look to see if there's anything unusual with how we're encoding the kafka messages originally and inserting with kafkacat, however right now we're still able to reproduce the issue when using kafka-go.

from kafka-go.

Pryz avatar Pryz commented on May 14, 2024

Hey @joepurdy, I'm hitting the same issue.

The problem is that Kafka uses the idea of MessageSet to be able to compress and uncompress payload more efficiently. A set is basically a message which wraps other messages so that Kafka can compress an entire batch of messages.

Note that RecordBatch is replacing MessageSet since Kafka 0.11 but the idea is the same.

We haven't implemented any of those in kafka-go yet and this is why you are having those leading characters (which are basically some message attributes).

from kafka-go.

stevevls avatar stevevls commented on May 14, 2024

This should be fixed by #135. Please re-open if you think it's still an issue.

from kafka-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.