-
Notifications
You must be signed in to change notification settings - Fork 339
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
Fix compressed offset bug #506
Changes from 5 commits
0c3315b
574fbed
dcd299f
dd96dda
ceeeb4d
c0c178f
2119d4e
02ad21c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,10 +58,14 @@ def decompress | |
message_set_decoder = Decoder.from_string(data) | ||
message_set = MessageSet.decode(message_set_decoder) | ||
|
||
max_relative_offset = message_set.messages.last.offset | ||
return message_set if max_relative_offset == offset | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This definitely needs a comment explaining why that's the case :) |
||
|
||
# The contained messages need to have their offset corrected. | ||
base_offset = offset - max_relative_offset | ||
messages = message_set.messages.each_with_index.map do |message, i| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i no longer needed |
||
Message.new( | ||
offset: offset + i, | ||
offset: message.offset + base_offset, | ||
value: message.value, | ||
key: message.key, | ||
create_time: message.create_time, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,29 +2,6 @@ | |
describe ".compress" do | ||
let(:instrumenter) { Kafka::Instrumenter.new(client_id: "test") } | ||
|
||
it "encodes and decodes compressed messages" do | ||
compressor = Kafka::Compressor.new(codec_name: :snappy, threshold: 1, instrumenter: instrumenter) | ||
|
||
message1 = Kafka::Protocol::Message.new(value: "hello1") | ||
message2 = Kafka::Protocol::Message.new(value: "hello2") | ||
|
||
message_set = Kafka::Protocol::MessageSet.new(messages: [message1, message2]) | ||
compressed_message_set = compressor.compress(message_set) | ||
|
||
data = Kafka::Protocol::Encoder.encode_with(compressed_message_set) | ||
decoder = Kafka::Protocol::Decoder.from_string(data) | ||
decoded_message = Kafka::Protocol::Message.decode(decoder) | ||
decoded_message_set = decoded_message.decompress | ||
messages = decoded_message_set.messages | ||
|
||
expect(messages.map(&:value)).to eq ["hello1", "hello2"] | ||
|
||
# When decoding a compressed message, the offsets are calculated relative to that | ||
# of the container message. The broker will set the offset in normal operation, | ||
# but at the client-side we set it to -1. | ||
expect(messages.map(&:offset)).to eq [-1, 0] | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We moved tests to message_set_spec, and we beleived this case was already covered in the other three tests we provided. This test does has -1 as wrapper message offset, and both messages are -1, -1 as well. Hence our code will accept this as "correct from broker side" and return In the end we just thought the other test cases was more realistic. Should we add this back? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK – no, that's fine, just needed to follow along. |
||
|
||
it "only compresses the messages if there are at least the configured threshold" do | ||
compressor = Kafka::Compressor.new(codec_name: :snappy, threshold: 3, instrumenter: instrumenter) | ||
|
||
|
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.
Can you document that
offset
is just used to simulate the broker behavior?