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

Fix newest sort slowness and wrong record number #1371

Merged
Merged
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
12 changes: 10 additions & 2 deletions src/main/java/org/akhq/repositories/RecordRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ private List<Record> consumeNewest(Topic topic, Options options) {
filterMessageLength(current);
list.add(current);
}

// End of the partition, we can stop here
if (record.offset() == topicPartitionOffset.getEnd()) {
emptyPoll = 1;
break;
}
}
}
while (emptyPoll < 1);
Expand Down Expand Up @@ -394,8 +400,10 @@ private Optional<OffsetBound> getFirstOffsetForSortOldest(KafkaConsumer<byte[],
private Optional<EndOffsetBound> getOffsetForSortNewest(KafkaConsumer<byte[], byte[]> consumer, Partition partition, Options options, int pollSizePerPartition) {
return getFirstOffset(consumer, partition, options)
.map(first -> {
long last = partition.getLastOffset();
// Take end offset - 1 to get the last record offset
long last = partition.getLastOffset() - 1;

// If there is an after parameter in the request use this one
if (pollSizePerPartition > 0 && options.after.containsKey(partition.getId())) {
last = options.after.get(partition.getId()) - 1;
}
Expand All @@ -404,7 +412,7 @@ private Optional<EndOffsetBound> getOffsetForSortNewest(KafkaConsumer<byte[], by
consumer.close();
return null;
} else if (!(last - pollSizePerPartition < first)) {
first = last - pollSizePerPartition;
first = last - pollSizePerPartition + 1;
}

return EndOffsetBound.builder()
Expand Down