Skip to content

Commit

Permalink
Restrict inner offset assignment to versions 0.10+
Browse files Browse the repository at this point in the history
  • Loading branch information
emfree committed Dec 20, 2017
1 parent a12e79b commit f0d0b0f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions produce_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,16 @@ func (ps *produceSet) buildRequest() *ProduceRequest {
// and sent as the payload of a single fake "message" with the appropriate codec
// set and no key. When the server sees a message with a compression codec, it
// decompresses the payload and treats the result as its message set.
for i, msg := range set.recordsToSend.msgSet.Messages {
// Assign relative offsets to the inner messages. This lets
// the broker avoid recompressing the message set.
msg.Offset = int64(i)

if ps.parent.conf.Version.IsAtLeast(V0_10_0_0) {
// If our version is 0.10 or later, assign relative offsets
// to the inner messages. This lets the broker avoid
// recompressing the message set.
// (See https://cwiki.apache.org/confluence/display/KAFKA/KIP-31+-+Move+to+relative+offsets+in+compressed+message+sets
// for details on relative offsets.)
for i, msg := range set.recordsToSend.msgSet.Messages {
msg.Offset = int64(i)
}
}
payload, err := encode(set.recordsToSend.msgSet, ps.parent.conf.MetricRegistry)
if err != nil {
Expand Down

0 comments on commit f0d0b0f

Please sign in to comment.