-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ProduceResponse v1 and v2 encoding #970
Support ProduceResponse v1 and v2 encoding #970
Conversation
produce_response.go
Outdated
if !prb.Timestamp.Before(time.Unix(0, 0)) { | ||
timestamp = prb.Timestamp.UnixNano() / int64(time.Millisecond) | ||
} else if !prb.Timestamp.IsZero() { | ||
return PacketDecodingError{fmt.Sprintf("invalid timestamp (%v)", prb.Timestamp)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PacketEncodingError
?
produce_response.go
Outdated
} | ||
sort.Ints(partitionNumbers) | ||
for _, p := range partitionNumbers { | ||
prb := partitions[int32(p)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arguably this whole block should get moved to ProduceResponseBlock.encode
?
Not entirely sold on the sorting, but since these encode methods are basically test-only I guess it's fine.
This... was not changed in this PR? |
Thanks for the quick review @eapache.
Not supper happy with that either so I'm going to remove the sorting and update the test to use a single topic and a single partition so that order does not matter (that's how unit tests are done for
No it was not, I guess by adding the unit test for it (decoding and encoding I got confused). |
- add ProduceResponseBlock.encode(packetEncoder, int16) - encode ProduceResponseBlock Timestamp field when version >= 2 - add unit tests for ProduceResponse decoding (version 1 and 2) - add unit tests for ProduceResponse encoding
c1bc8e1
to
ca457b7
Compare
I decided to rebase the changes as they are quite simple now and the commit message has been updated accordingly. Let me know what you think, the only drawback IMHO is that the coverage for the unit tests has decreased (not checking multiple topics/partitions or validating the -1 timestamp case anymore). |
Looks good, thanks! |
I have been running into an issue when using v1.13.0 of Sarama for unit testing a producer with the
MockBroker
abstraction.When using an
AsyncProducer
withconfig.version
>=V0_9_0_0
decoding produce responses from aMockBroker
fails with:insufficient data to decode packet, more bytes expected
.Example to reproduce error
Example of application that fails when sending a
V0_10_0_0
ProduceRequest
as it expects the same version in theProduceResponse
:Logs
The application fails with:
Code change
ProduceResponse
ThrottleTime
when version >= 1ProduceResponseBlock
Timestamp
when version >= 2ProduceResponse
decoding (version 1 and 2)ProduceResponse
encoding