Skip to content
Merged
Changes from 1 commit
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
13 changes: 2 additions & 11 deletions core/src/main/scala/kafka/tools/StreamsResetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,17 +491,8 @@ private void resetByDuration(final Consumer<byte[], byte[]> client,
final Duration duration) {
final Instant now = Instant.now();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we remove those local variables? For example:

        resetToDatetime(client, inputTopicPartitions, Instant.now().minus(duration).toEpochMilli());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your information. I have updated this problem.

final long timestamp = now.minus(duration).toEpochMilli();

final Map<TopicPartition, Long> topicPartitionsAndTimes = new HashMap<>(inputTopicPartitions.size());
for (final TopicPartition topicPartition : inputTopicPartitions) {
topicPartitionsAndTimes.put(topicPartition, timestamp);
}

final Map<TopicPartition, OffsetAndTimestamp> topicPartitionsAndOffset = client.offsetsForTimes(topicPartitionsAndTimes);

for (final TopicPartition topicPartition : inputTopicPartitions) {
client.seek(topicPartition, topicPartitionsAndOffset.get(topicPartition).offset());
}

resetToDatetime(client, inputTopicPartitions, timestamp);
}

private void resetToDatetime(final Consumer<byte[], byte[]> client,
Expand Down