Skip to content

Changes for aligning code with offset fetch and commit APIs (Kafka 0.8.1) #90

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions kafka/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ def get_or_init_offset_callback(resp):
# (offset,) = self.client.send_offset_fetch_request(group, [req],
# callback=get_or_init_offset_callback,
# fail_on_error=False)
#
# #Increment the offset with 1 so that message corresponding to last
# #committed offset doesn't get replayed
# if offset != 0:
# offset +=1
#
# self.offsets[partition] = offset

for partition in partitions:
Expand Down Expand Up @@ -399,6 +405,18 @@ def __iter_partition__(self, partition, offset):
except ConsumerNoMoreData, e:
log.debug("Iteration was ended by %r", e)

# Uncomment for 0.8.1
#
# Decrement the value of offset for the partition from where
# no messages have been consumed. We initially incremented the offset value
# before making fetch request so that message corresponding to the
# last committed offset doesn't get replayed.
# This step ensures that correct value of offset per partition get
# committed if user decides to make an explicit call to commit method.
#
#if self.offsets[partition] == offset and offset != 0:
# self.offsets[partition] -= 1

if next_offset is None:
break
else:
Expand Down
6 changes: 2 additions & 4 deletions kafka/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class KafkaProtocol(object):
FETCH_KEY = 1
OFFSET_KEY = 2
METADATA_KEY = 3
OFFSET_COMMIT_KEY = 6
OFFSET_FETCH_KEY = 7
OFFSET_COMMIT_KEY = 8
OFFSET_FETCH_KEY = 9

ATTRIBUTE_CODEC_MASK = 0x03
CODEC_NONE = 0x00
Expand Down Expand Up @@ -439,7 +439,6 @@ def decode_offset_commit_response(cls, data):
data: bytes to decode
"""
((correlation_id,), cur) = relative_unpack('>i', data, 0)
(client_id, cur) = read_short_string(data, cur)
((num_topics,), cur) = relative_unpack('>i', data, cur)

for i in xrange(num_topics):
Expand Down Expand Up @@ -490,7 +489,6 @@ def decode_offset_fetch_response(cls, data):
"""

((correlation_id,), cur) = relative_unpack('>i', data, 0)
(client_id, cur) = read_short_string(data, cur)
((num_topics,), cur) = relative_unpack('>i', data, cur)

for i in range(num_topics):
Expand Down