Skip to content

Commit ecc77e6

Browse files
mnito88manpreet
authored andcommitted
Force lz4 to disable Kafka-unsupported block linking when encoding (dpkp#1476)
1 parent ea7187d commit ecc77e6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

kafka/codec.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818

1919
try:
2020
import lz4.frame as lz4
21+
22+
def _lz4_compress(payload, **kwargs):
23+
# Kafka does not support LZ4 dependent blocks
24+
try:
25+
# For lz4>=0.12.0
26+
kwargs.pop('block_linked', None)
27+
return lz4.compress(payload, block_linked=False, **kwargs)
28+
except TypeError:
29+
# For earlier versions of lz4
30+
kwargs.pop('block_mode', None)
31+
return lz4.compress(payload, block_mode=1, **kwargs)
32+
2133
except ImportError:
2234
lz4 = None
2335

@@ -202,7 +214,7 @@ def snappy_decode(payload):
202214

203215

204216
if lz4:
205-
lz4_encode = lz4.compress # pylint: disable-msg=no-member
217+
lz4_encode = _lz4_compress # pylint: disable-msg=no-member
206218
elif lz4f:
207219
lz4_encode = lz4f.compressFrame # pylint: disable-msg=no-member
208220
elif lz4framed:

0 commit comments

Comments
 (0)