You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "ableegoldman (via GitHub)" <gi...@apache.org> on 2024/11/06 08:11:05 UTC
[PR] MINOR: fix time discrepancy between TestInputTopic and TopologyTestDriver that creates it [kafka]
ableegoldman opened a new pull request, #17702:
URL: https://github.com/apache/kafka/pull/17702
Fixes an issue with the TTD in the specific case where users don't specify an initial time for the driver and also don't specify a start timestamp for the TestInputTopic, then pipe input records without timestamps. This combination results in a slight mismatch in the expected timestamps for the piped records, which can be noticeable when writing tests with very small time deltas.
The problem is that, while both the TTD and the TestInputTopic will be initialized to the "current time" when not otherwise specified, it's possible for some milliseconds to have passed between the creation of the TTD and the creation of the TestInputTopic. This can result in a TestInputTopic getting a start timestamp that's several ms larger than the driver's time, and ultimately causing the piped input records to have timestamps slightly in the future relative to the driver.
In practice even those who hit this issue might not notice it if they aren't manipulating time in their tests, or are advancing time by enough to negate the several-milliseconds of difference. However we noticed a test fail due to this because we were testing a ttl-based processor and had advanced the driver time by only 1 millisecond past the ttl. The piped record should have been expired, but because it's timestamp was a few milliseconds longer than the driver's start time, this test ended up failing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: fix time discrepancy between TestInputTopic and TopologyTestDriver that creates it [kafka]
Posted by "lucasbru (via GitHub)" <gi...@apache.org>.
lucasbru commented on code in PR #17702:
URL: https://github.com/apache/kafka/pull/17702#discussion_r1830647793
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java:
##########
@@ -738,7 +737,14 @@ private Queue<ProducerRecord<byte[], byte[]>> getRecordsQueue(final String topic
public final <K, V> TestInputTopic<K, V> createInputTopic(final String topicName,
Review Comment:
You are right, you'd need a KIP for removing it. I'm fine with merging this fix without removing the `final`.
For removing the `final` -- it does make sense to restrict the surface area for extending the public interface. I'm not sure why we'd need to override those. But this is something for the KIP discussion anyways, if you want to write one
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: fix time discrepancy between TestInputTopic and TopologyTestDriver that creates it [kafka]
Posted by "lucasbru (via GitHub)" <gi...@apache.org>.
lucasbru commented on code in PR #17702:
URL: https://github.com/apache/kafka/pull/17702#discussion_r1830642543
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java:
##########
@@ -1352,19 +1358,4 @@ public Position getPosition() {
}
}
- private static class TestDriverProducer extends StreamsProducer {
Review Comment:
Interesting... seems fine to me
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: fix time discrepancy between TestInputTopic and TopologyTestDriver that creates it [kafka]
Posted by "bbejeck (via GitHub)" <gi...@apache.org>.
bbejeck commented on code in PR #17702:
URL: https://github.com/apache/kafka/pull/17702#discussion_r1831512988
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java:
##########
@@ -738,7 +737,14 @@ private Queue<ProducerRecord<byte[], byte[]>> getRecordsQueue(final String topic
public final <K, V> TestInputTopic<K, V> createInputTopic(final String topicName,
final Serializer<K> keySerializer,
final Serializer<V> valueSerializer) {
- return new TestInputTopic<>(this, topicName, keySerializer, valueSerializer, Instant.now(), Duration.ZERO);
+ return new TestInputTopic<>(
+ this,
+ topicName,
+ keySerializer,
+ valueSerializer,
+ Instant.ofEpochMilli(mockWallClockTime.milliseconds()),
Review Comment:
Yeah, I agree this doesn't need a KIP, plus there's an overload where users can provide their own time if needed. Although, you make a great point about synchronizing the time with the driver.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: fix time discrepancy between TestInputTopic and TopologyTestDriver that creates it [kafka]
Posted by "ableegoldman (via GitHub)" <gi...@apache.org>.
ableegoldman commented on code in PR #17702:
URL: https://github.com/apache/kafka/pull/17702#discussion_r1830559435
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsProducer.java:
##########
@@ -240,7 +240,7 @@ private static boolean isRecoverable(final KafkaException uncaughtException) {
* @throws IllegalStateException if EOS is disabled
* @throws TaskMigratedException
*/
- protected void commitTransaction(final Map<TopicPartition, OffsetAndMetadata> offsets,
+ public void commitTransaction(final Map<TopicPartition, OffsetAndMetadata> offsets,
Review Comment:
unrelated to the main fix, just doing some cleanup of the TTD on the side. I don't see why we can't just make this method public since it's an internal class anyways -- which was the exact reasoning I saw on the PR which originally changed it from private to protected anyway. But I can leave this part out if there are any concerns
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: fix time discrepancy between TestInputTopic and TopologyTestDriver that creates it [kafka]
Posted by "ableegoldman (via GitHub)" <gi...@apache.org>.
ableegoldman merged PR #17702:
URL: https://github.com/apache/kafka/pull/17702
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: fix time discrepancy between TestInputTopic and TopologyTestDriver that creates it [kafka]
Posted by "lucasbru (via GitHub)" <gi...@apache.org>.
lucasbru commented on code in PR #17702:
URL: https://github.com/apache/kafka/pull/17702#discussion_r1830641540
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java:
##########
@@ -738,7 +737,14 @@ private Queue<ProducerRecord<byte[], byte[]>> getRecordsQueue(final String topic
public final <K, V> TestInputTopic<K, V> createInputTopic(final String topicName,
final Serializer<K> keySerializer,
final Serializer<V> valueSerializer) {
- return new TestInputTopic<>(this, topicName, keySerializer, valueSerializer, Instant.now(), Duration.ZERO);
+ return new TestInputTopic<>(
+ this,
+ topicName,
+ keySerializer,
+ valueSerializer,
+ Instant.ofEpochMilli(mockWallClockTime.milliseconds()),
Review Comment:
I don't think it needs a KIP
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: fix time discrepancy between TestInputTopic and TopologyTestDriver that creates it [kafka]
Posted by "ableegoldman (via GitHub)" <gi...@apache.org>.
ableegoldman commented on code in PR #17702:
URL: https://github.com/apache/kafka/pull/17702#discussion_r1830567644
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java:
##########
@@ -738,7 +737,14 @@ private Queue<ProducerRecord<byte[], byte[]>> getRecordsQueue(final String topic
public final <K, V> TestInputTopic<K, V> createInputTopic(final String topicName,
Review Comment:
Also wondering why all these methods are final -- I could have addressed this issue in our code without this PR if I could just override these methods. Are we concerned about users doing this..? And why?
I figure this change actually would need a KIP so I left it out, but I'd like to remove the `final` from these unless someone knows a good reason for doing this
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: fix time discrepancy between TestInputTopic and TopologyTestDriver that creates it [kafka]
Posted by "ableegoldman (via GitHub)" <gi...@apache.org>.
ableegoldman commented on code in PR #17702:
URL: https://github.com/apache/kafka/pull/17702#discussion_r1830562898
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java:
##########
@@ -738,7 +737,14 @@ private Queue<ProducerRecord<byte[], byte[]>> getRecordsQueue(final String topic
public final <K, V> TestInputTopic<K, V> createInputTopic(final String topicName,
final Serializer<K> keySerializer,
final Serializer<V> valueSerializer) {
- return new TestInputTopic<>(this, topicName, keySerializer, valueSerializer, Instant.now(), Duration.ZERO);
+ return new TestInputTopic<>(
+ this,
+ topicName,
+ keySerializer,
+ valueSerializer,
+ Instant.ofEpochMilli(mockWallClockTime.milliseconds()),
Review Comment:
This is the main fix: instead of initializing to the current time, we should initialize to the driver's current time. I feel like this makes more sense anyway...we mock time in the driver so why should the TestInputTopic use a view of time based on actual wallclock time rather than the driver's time?
And would this need a KIP?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] MINOR: fix time discrepancy between TestInputTopic and TopologyTestDriver that creates it [kafka]
Posted by "ableegoldman (via GitHub)" <gi...@apache.org>.
ableegoldman commented on code in PR #17702:
URL: https://github.com/apache/kafka/pull/17702#discussion_r1830560659
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java:
##########
@@ -1352,19 +1358,4 @@ public Position getPosition() {
}
}
- private static class TestDriverProducer extends StreamsProducer {
Review Comment:
This class isn't doing anything, right? I'm unclear on its purpose and figured I might as well clean it up from the TTD -- but again, happy to undo this change since it's not needed for the main fix
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java:
##########
@@ -1352,19 +1358,4 @@ public Position getPosition() {
}
}
- private static class TestDriverProducer extends StreamsProducer {
Review Comment:
This class isn't doing anything, right? I'm unclear on its purpose and figured I might as well clean it up from the TTD -- but again, happy to undo this change since it's not needed for the main fix
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org