Skip to content
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

rollover correlation id. addresses #344 #345

Closed
wants to merge 1 commit 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
7 changes: 4 additions & 3 deletions kafka/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import collections
import copy
import functools
import itertools
import logging
import time
import kafka.common

from ctypes import c_uint32
from kafka.common import (TopicAndPartition, BrokerMetadata,
ConnectionError, FailedPayloadsError,
KafkaTimeoutError, KafkaUnavailableError,
Expand All @@ -23,7 +23,7 @@
class KafkaClient(object):

CLIENT_ID = b"kafka-python"
ID_GEN = itertools.count()
ID_GEN = 0

# NOTE: The timeout given to the client should always be greater than the
# one passed to SimpleConsumer.get_message(), otherwise you can get a
Expand Down Expand Up @@ -101,7 +101,8 @@ def _next_id(self):
"""
Generate a new correlation id
"""
return next(KafkaClient.ID_GEN)
KafkaClient.ID_GEN = c_uint32(KafkaClient.ID_GEN + 1).value
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be simpler to just add a modulo here? (% 2**31)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah I think that's much simpler.

return KafkaClient.ID_GEN

def _send_broker_unaware_request(self, payloads, encoder_fn, decoder_fn):
"""
Expand Down
2 changes: 1 addition & 1 deletion kafka/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _encode_message_header(cls, client_id, correlation_id, request_key):
"""
Encode the common request envelope
"""
return struct.pack('>hhih%ds' % len(client_id),
return struct.pack('>hhIh%ds' % len(client_id),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the kafka protocol defines this field as a signed int32. i think it's better to stick with that.

request_key, # ApiKey
0, # ApiVersion
correlation_id, # CorrelationId
Expand Down