@@ -372,11 +372,6 @@ def _append(self, drained, part, max_records):
372
372
tp , next_offset )
373
373
374
374
for record in part_records :
375
- # Fetched compressed messages may include additional records
376
- if record .offset < fetch_offset :
377
- log .debug ("Skipping message offset: %s (expecting %s)" ,
378
- record .offset , fetch_offset )
379
- continue
380
375
drained [tp ].append (record )
381
376
382
377
self ._subscriptions .assignment [tp ].position = next_offset
@@ -843,10 +838,15 @@ def __init__(self, fetch_offset, tp, messages):
843
838
# When fetching an offset that is in the middle of a
844
839
# compressed batch, we will get all messages in the batch.
845
840
# But we want to start 'take' at the fetch_offset
841
+ # (or the next highest offset in case the message was compacted)
846
842
for i , msg in enumerate (messages ):
847
- if msg .offset == fetch_offset :
843
+ if msg .offset < fetch_offset :
844
+ log .debug ("Skipping message offset: %s (expecting %s)" ,
845
+ msg .offset , fetch_offset )
846
+ else :
848
847
self .message_idx = i
849
848
break
849
+
850
850
else :
851
851
self .message_idx = 0
852
852
self .messages = None
@@ -868,8 +868,9 @@ def take(self, n=None):
868
868
next_idx = self .message_idx + n
869
869
res = self .messages [self .message_idx :next_idx ]
870
870
self .message_idx = next_idx
871
- if len (self ) > 0 :
872
- self .fetch_offset = self .messages [self .message_idx ].offset
871
+ # fetch_offset should be incremented by 1 to parallel the
872
+ # subscription position (also incremented by 1)
873
+ self .fetch_offset = max (self .fetch_offset , res [- 1 ].offset + 1 )
873
874
return res
874
875
875
876
0 commit comments