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

Offset batch: remove intermediary structure #870

Merged
merged 2 commits into from
Aug 23, 2019

Conversation

ennru
Copy link
Member

@ennru ennru commented Aug 23, 2019

Purpose

Convert the Map[GroupTopicPartition, OffsetAndMetadata] directly into a Map[TopicPartition, OffsetAndMetadata] to be sent to the consumer actor.

Changes

  • Move the location where the offset + 1 is applied
  • Change toString back to just show the offsets

Background Context

Before sending offsets in KafkaAsyncConsumerCommitterRef the map was first transformed to a Seq[PartitionOffsetMetadata] (unpacking the OffsetWithMetaData) and than back to a Map[TopicPartition, OffsetAndMetadata] in the commit method.
By mapping directly less intermediary objects are created. The OffsetAndMetadata can be kept, but the offset + 1 needed to be applied when building the batch in CommittableOffsetBatchImpl instead. The public offsets method compensates for that.

Copy link
Contributor

@2m 2m left a comment

Choose a reason for hiding this comment

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

Transformation change LGTM. A question regarding offset changes.

@@ -180,7 +180,7 @@ private[kafka] final class CommittableOffsetBatchImpl(
}

val newOffsets =
offsetsAndMetadata.updated(key, new OffsetAndMetadata(committableOffset.partitionOffset.offset, metadata))
offsetsAndMetadata.updated(key, new OffsetAndMetadata(committableOffset.partitionOffset.offset + 1L, metadata))
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not see immediately, why the change in offset increment and decrement above.

Copy link
Member Author

Choose a reason for hiding this comment

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

The OffsetAndMetadata is now passed through as-is. Before it was constructed, decomposed and constructed again with the + 1.

private def commit(offsets: immutable.Seq[PartitionOffsetMetadata]): Future[Done] = {
val offsetsMap: Map[TopicPartition, OffsetAndMetadata] = offsets.map { offset =>
new TopicPartition(offset.key.topic, offset.key.partition) ->
new OffsetAndMetadata(offset.offset + 1, offset.metadata)
Copy link
Member Author

Choose a reason for hiding this comment

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

Here was the + 1 before.

@ennru ennru merged commit 05ecc0c into akka:master Aug 23, 2019
@ennru ennru deleted the map-more-directly branch August 23, 2019 15:03
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.

None yet

2 participants