You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2020/07/23 13:59:31 UTC
[GitHub] [kafka] soarez opened a new pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
soarez opened a new pull request #9064:
URL: https://github.com/apache/kafka/pull/9064
Kafka Streams topologies must be defined in a deterministic order, otherwise users can run into confusing NPE.
This patch adds a more descriptive exception and documentation clarifying the deterministic requirement.
https://issues.apache.org/jira/browse/KAFKA-10205
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
mjsax commented on pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#issuecomment-701585694
Thanks for the PR @soarez! Merged to `trunk`.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] soarez edited a comment on pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
soarez edited a comment on pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#issuecomment-663252849
Thanks for review @mjsax. I've changed the base branch to `trunk` and believe I have addressed all your feedback so far. Please take another look.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on a change in pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
mjsax commented on a change in pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#discussion_r459581717
##########
File path: streams/src/main/java/org/apache/kafka/streams/StreamsBuilder.java
##########
@@ -49,6 +49,9 @@
/**
* {@code StreamsBuilder} provide the high-level Kafka Streams DSL to specify a Kafka Streams topology.
*
+ * It is a requirement that the processing logic (Topology) be defined in a deterministic way.
Review comment:
Nit: insert `<p>` tag to actually get the new paragraph rendered.
Nit: `Topology -> `{@link Topology}`
It's not really clear what "deterministic" means. We should elaborate more.
##########
File path: streams/src/main/java/org/apache/kafka/streams/StreamsBuilder.java
##########
@@ -49,6 +49,9 @@
/**
* {@code StreamsBuilder} provide the high-level Kafka Streams DSL to specify a Kafka Streams topology.
*
+ * It is a requirement that the processing logic (Topology) be defined in a deterministic way.
+ * If different instances build different runtime code logic the resulting behavior may be unexpected.
Review comment:
"different" for sure, but this implies that one might have an operator the other does not. The observed issue is, that even if both contain the same operator, they might be added in different order (and thus be named differently) to the `Topology`, thus we should stretch that order matters.
##########
File path: streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamTaskTest.java
##########
@@ -1984,6 +1985,24 @@ public void shouldThrowWakeupExceptionOnInitializeOffsetsWhenWakeupException() {
task.initializeStateStores();
}
+ @Test(expected = TopologyException.class)
Review comment:
We should not use this annotation but rather use `assertThrows` (we still have some code that does not use `assertThrows` but we try to lazily migrate our tests, as it provides a better test pattern).
##########
File path: streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java
##########
@@ -181,8 +182,16 @@ public StreamTask(final TaskId id,
final TimestampExtractor defaultTimestampExtractor = config.defaultTimestampExtractor();
final DeserializationExceptionHandler defaultDeserializationExceptionHandler = config.defaultDeserializationExceptionHandler();
+ final Set<String> sourceTopics = topology.sourceTopics();
for (final TopicPartition partition : partitions) {
- final SourceNode source = topology.source(partition.topic());
+ final String topicName = partition.topic();
+ if (!sourceTopics.contains(topicName)) {
+ throw new TopologyException(
+ "Topic not found " + topicName + ". Is the Streams Topology built in a deterministic way?"
Review comment:
`Topic not found` sounds like as-if the topic was not found in the cluster -- however, what actually happened is that we received a record but the record's topic is unknown in the sub-topology.
Similar to above, "deterministic" is not really easy to understand. I would also not phrase it as a question, but as a statement:
```
... This may happen if different KafkaStreams instances of the same application execute different Topologies. Note that Topologies are only identical if all operators are added in the same order.
```
Or similar.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] soarez commented on pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
soarez commented on pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#issuecomment-675135083
Ping @mjsax - a reminder to review 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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] soarez edited a comment on pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
soarez edited a comment on pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#issuecomment-683421515
@mjsax rebased and fixed the error, now `./gradlew :streams:unitTest` seems to run without errors over here.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
mjsax commented on pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#issuecomment-663113463
Btw: The PR should be against `trunk`.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] soarez commented on pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
soarez commented on pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#issuecomment-669622553
Thanks for the review @mjsax. I've addressed your feedback. Please take another look.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] soarez commented on pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
soarez commented on pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#issuecomment-663252849
Thanks for review @mjsax. I've changed the merge base to `trunk` and believe I have addressed all your feedback so far. Please take another look.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
mjsax commented on pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#issuecomment-681153031
Compile error:
```
/home/jenkins/jenkins-slave/workspace/kafka-pr-jdk11-scala2.13/streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamTaskTest.java:1989: error: constructor StreamsMetricsImpl in class StreamsMetricsImpl cannot be applied to given types;
20:24:26 final StreamsMetricsImpl metrics = new StreamsMetricsImpl(this.metrics, "test", StreamsConfig.METRICS_LATEST);
20:24:26 ^
20:24:26 required: Metrics,String,String,Time
20:24:26 found: Metrics,String,String
20:24:26 reason: actual and formal argument lists differ in length
20:24:27 1 error
```
Seems you need to rebase?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] soarez commented on pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
soarez commented on pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#issuecomment-683421515
@mjsax rebased and fix the error, now `./gradlew :streams:unitTest` seems to run without errors over here.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on a change in pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
mjsax commented on a change in pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#discussion_r464752987
##########
File path: streams/src/main/java/org/apache/kafka/streams/StreamsBuilder.java
##########
@@ -50,6 +50,14 @@
/**
* {@code StreamsBuilder} provide the high-level Kafka Streams DSL to specify a Kafka Streams topology.
*
+ * <p>
+ * It is a requirement that the processing logic ({@link Topology}) be defined in a deterministic way,
+ * as in, the order in which all operators are added must be predictable and the same across all application
+ * instances.
+ * Topologies are only identical if all operators are added in the same order.
+ * If different KafkaStream instances of the same application build different topologies the result may be
Review comment:
{@link KafkaStreams}
##########
File path: streams/src/main/java/org/apache/kafka/streams/StreamsBuilder.java
##########
@@ -50,6 +50,14 @@
/**
* {@code StreamsBuilder} provide the high-level Kafka Streams DSL to specify a Kafka Streams topology.
*
+ * <p>
+ * It is a requirement that the processing logic ({@link Topology}) be defined in a deterministic way,
+ * as in, the order in which all operators are added must be predictable and the same across all application
+ * instances.
+ * Topologies are only identical if all operators are added in the same order.
+ * If different KafkaStream instances of the same application build different topologies the result may be
+ * incompatible runtimes and unexpected results.
Review comment:
`incompatible runtimes and unexpected results` -> `incompatible runtime code and unexpected results or errors.`
##########
File path: streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamTaskTest.java
##########
@@ -1916,6 +1917,40 @@ public void shouldAlwaysSuspendRunningTasks() {
assertThat(task.state(), equalTo(SUSPENDED));
}
+ @Test
+ public void szTest() {
+ final InternalProcessorContext context = new ProcessorContextImpl(
+ taskId,
+ createConfig(false, "100"),
+ stateManager,
+ streamsMetrics,
+ null
+ );
+ final StreamsMetricsImpl metrics = new StreamsMetricsImpl(this.metrics, "test", StreamsConfig.METRICS_LATEST);
+ EasyMock.expect(stateManager.changelogPartitions()).andReturn(Collections.emptySet());
+ EasyMock.replay(stateManager);
+
+ // The processor topology is missing the topics
+ final ProcessorTopology topology = withSources(asList(), mkMap());
+
+ assertThrows(TopologyException.class, () ->
Review comment:
nit: formatting: (we should also get the exception an verify the error message)
```
final TopologyException exception = assertThrows(
TopologyException.class,
() -> new StreamTask(
...
)
);
assertThat(exception.getMessage(), equalTo("..."));
```
##########
File path: streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamTaskTest.java
##########
@@ -1916,6 +1917,40 @@ public void shouldAlwaysSuspendRunningTasks() {
assertThat(task.state(), equalTo(SUSPENDED));
}
+ @Test
+ public void szTest() {
Review comment:
`szTest` is a terrible test name: `shouldThrowTopologyExceptionIfTaskCreatedForUnknownTopic`
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax merged pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
mjsax merged pull request #9064:
URL: https://github.com/apache/kafka/pull/9064
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] mjsax commented on pull request #9064: KAFKA-10205: Documentation and handling of non deterministic Topologies
Posted by GitBox <gi...@apache.org>.
mjsax commented on pull request #9064:
URL: https://github.com/apache/kafka/pull/9064#issuecomment-678450380
Retest this please.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org