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

Framed transport for Kafka message bus #329

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

sibiryakov
Copy link
Member

Allows to transfer messages larger than Kafka maximum message size.

# Conflicts:
#	frontera/contrib/messagebus/kafkabus.py
@jpbalarini
Copy link

Hi @sibiryakov, is there any reason this was not merged yet? I'm dealing with a case where this should fix my problem.

Thanks!

Comment on lines +11 to +12
def random_bytes():
return pack("L", randint(0, MAXSIZE))

Choose a reason for hiding this comment

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

You have an error here. Look at six sources

if PY3:
    string_types = str,
    integer_types = int,
    class_types = type,
    text_type = str
    binary_type = bytes

    MAXSIZE = sys.maxsize
else:
    string_types = basestring,
    integer_types = (int, long)
    class_types = (type, types.ClassType)
    text_type = unicode
    binary_type = str

    if sys.platform.startswith("java"):
        # Jython always uses 32 bits.
        MAXSIZE = int((1 << 31) - 1)
    else:
        # It's possible to have sizeof(long) != sizeof(Py_ssize_t).
        class X(object):

            def __len__(self):
                return 1 << 31
        try:
            len(X())
        except OverflowError:
            # 32-bit
            MAXSIZE = int((1 << 31) - 1)
        else:
            # 64-bit
            MAXSIZE = int((1 << 63) - 1)
        del X

sys.maxsize is 64 bit in Python 3 (9223372036854775807). As you can see from six, MAXSIZE can be 64 bit both for Python 2 and 3. According to documentation (Python 2 and 3), packing symbol L is used to pack 32 bit uint. You should change it to Q which is used to pack 64 bit uint.

Suggested change
def random_bytes():
return pack("L", randint(0, MAXSIZE))
def random_bytes():
return pack('Q', randint(0, MAXSIZE))

Choose a reason for hiding this comment

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

Another option is to change MAXSIZE variable to literal 4_294_967_295.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants