You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "sebastienviale (via GitHub)" <gi...@apache.org> on 2024/06/12 07:09:54 UTC
[PR] Kafka 16448 punctuate processing exceptions [kafka]
sebastienviale opened a new pull request, #16300:
URL: https://github.com/apache/kafka/pull/16300
This PR is part of [KAFKA-16448](https://issues.apache.org/jira/browse/KAFKA-16448) which aims to bring a ProcessingExceptionHandler to Kafka Streams in order to deal with exceptions that occur during processing.
This PR actually catches processing exceptions from punctuate.
Jira: https://issues.apache.org/jira/browse/KAFKA-16448.
Contributors
@Dabz
@sebastienviale
@loicgreffier
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1698085150
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -917,8 +922,34 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
maybeMeasureLatency(() -> node.punctuate(timestamp, punctuator), time, punctuateLatencySensor);
} catch (final StreamsException e) {
throw e;
- } catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ } catch (final Exception e) {
Review Comment:
@mjsax For this reason: https://github.com/apache/kafka/pull/16300#discussion_r1687844510
`Exception` is caught in `ProcessorNode#process`, `RecordCollectorImpl#send` and `RecordDeserializer#deserialize` so the last discussion mentionned to stick to `Exception` here to be consistent.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on PR #16300:
URL: https://github.com/apache/kafka/pull/16300#issuecomment-2262893683
> Was there anything else that was changed and should be called out?
The number of processing exception handlers that are instantiated: 1 / Stream Task. This was not initially mentioned in KIP-1033. It is has been updated.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1697965185
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -917,8 +922,34 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
maybeMeasureLatency(() -> node.punctuate(timestamp, punctuator), time, punctuateLatencySensor);
} catch (final StreamsException e) {
throw e;
- } catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ } catch (final Exception e) {
+ final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(
+ null,
+ recordContext.topic(),
+ recordContext.partition(),
+ recordContext.offset(),
+ recordContext.headers(),
+ null,
+ null
+ );
+
+ final ProcessingExceptionHandler.ProcessingHandlerResponse response;
+
+ try {
+ response = processingExceptionHandler.handle(errorHandlerContext, null, e);
+ } catch (final Exception fatalUserException) {
Review Comment:
Same here. Why not `RuntimeException` -- given that no checked exception is declared for the `handler(...)` method, it's not possible to get a `Exception` here.
Same seems to apply to `ProcessorNode` code which has the same try-catch block.
Let me do a small PR myself to address it :)
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1698091936
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -917,8 +922,34 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
maybeMeasureLatency(() -> node.punctuate(timestamp, punctuator), time, punctuateLatencySensor);
} catch (final StreamsException e) {
throw e;
- } catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ } catch (final Exception e) {
+ final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(
+ null,
+ recordContext.topic(),
+ recordContext.partition(),
+ recordContext.offset(),
+ recordContext.headers(),
+ null,
+ null
+ );
+
+ final ProcessingExceptionHandler.ProcessingHandlerResponse response;
+
+ try {
+ response = processingExceptionHandler.handle(errorHandlerContext, null, e);
+ } catch (final Exception fatalUserException) {
Review Comment:
@mjsax Same answer: https://github.com/apache/kafka/pull/16300#discussion_r1698085150. `ProcessorNode#process` and `StreamTask#punctuate` stick with `RecordCollectorImpl` and `RecordDeserializer`.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1699146260
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
Thanks. LGTM.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "cadonna (via GitHub)" <gi...@apache.org>.
cadonna commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1689927771
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamTaskTest.java:
##########
@@ -2647,6 +2657,62 @@ public void shouldNotCheckpointAfterRestorationWhenExactlyOnceEnabled() {
verify(recordCollector, never()).offsets();
}
+ @Test
+ public void shouldNotThrowStreamsExceptionWhenProcessingExceptionHandlerRepliesWithContinue() {
+ when(stateManager.taskId()).thenReturn(taskId);
+ when(stateManager.taskType()).thenReturn(TaskType.ACTIVE);
+ task = createStatelessTask(createConfig(AT_LEAST_ONCE, "100",
+ LogAndFailExceptionHandler.class.getName(), LogAndContinueProcessingExceptionHandler.class.getName()));
+
+ assertDoesNotThrow(() ->
+ task.punctuate(processorStreamTime, 1, PunctuationType.STREAM_TIME, timestamp -> {
+ throw new KafkaException("KABOOM!");
+ })
+ );
+ }
+
+ @Test
+ public void shouldThrowStreamsExceptionWhenProcessingExceptionHandlerRepliesWithFail() {
+ when(stateManager.taskId()).thenReturn(taskId);
+ when(stateManager.taskType()).thenReturn(TaskType.ACTIVE);
+ task = createStatelessTask(createConfig(AT_LEAST_ONCE, "100",
+ LogAndFailExceptionHandler.class.getName(), LogAndFailProcessingExceptionHandler.class.getName()));
+
+ final StreamsException streamsException = assertThrows(StreamsException.class,
+ () -> task.punctuate(processorStreamTime, 1, PunctuationType.STREAM_TIME, timestamp -> {
+ throw new KafkaException("KABOOM!");
+ }));
+
+ assertTrue(streamsException.getCause() instanceof KafkaException);
+ assertEquals("KABOOM!", streamsException.getCause().getMessage());
+ }
+
+ @Test
+ public void shouldThrowStreamsExceptionWhenProcessingExceptionHandlerThrowsAnException() {
+ when(stateManager.taskId()).thenReturn(taskId);
+ when(stateManager.taskType()).thenReturn(TaskType.ACTIVE);
+ task = createStatelessTask(createConfig(AT_LEAST_ONCE, "100",
+ LogAndFailExceptionHandler.class.getName(), ProcessingExceptionHandlerMock.class.getName()));
+
+ final StreamsException streamsException = assertThrows(StreamsException.class,
+ () -> task.punctuate(processorStreamTime, 1, PunctuationType.STREAM_TIME, timestamp -> {
+ throw new KafkaException("KABOOM!");
+ }));
+
+ final String msg = streamsException.getMessage();
+ assertTrue(msg.equals("Fatal user code error in processing error callback"));
+ }
+
+ public static class ProcessingExceptionHandlerMock implements ProcessingExceptionHandler {
+ @Override
+ public ProcessingExceptionHandler.ProcessingHandlerResponse handle(final ErrorHandlerContext context, final Record<?, ?> record, final Exception exception) {
+ throw new RuntimeException("KABOOM!");
+ }
Review Comment:
There is a checkstyle issue. This should solve the issue.
```suggestion
public ProcessingExceptionHandler.ProcessingHandlerResponse handle(final ErrorHandlerContext context, final Record<?, ?> record, final Exception exception) {
throw new RuntimeException("KABOOM!");
}
```
You can verify checkstyle issues locally with:
```
./gradlew streams:checkstyleMain streams:checkstyleTest streams:spotbugsMain streams:spotbugsTest
```
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "cadonna (via GitHub)" <gi...@apache.org>.
cadonna commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1687844510
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
throw e;
} catch (final RuntimeException e) {
Review Comment:
Sorry, I have to re-iterate on this. I now realized that for all other handlers we catch `Exception` and not `RuntimeException`. To be consistent let's catch `Exception` here and in the `ProcessorNode`.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686578244
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
Well, in the `ProcessorNode` we do not handle `TaskCorruptedException` or `TaskMigratedException` which extends `StreamsException` for example.
Unless I'm wrong these exceptions cannot be caught in the `punctuate`, right? (I don't want to end up in a situation where we do not handle `TaskCorruptedException` in the `process()`, but we do in the `punctuate()`)
👉 Considering `TaskCorruptedException`/`TaskMigratedException` cannot reach `punctuate()`, we updated the PR to handle all `StreamsException` in the `punctuate`.
--
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] Kafka-16448: punctuate processing exceptions [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on PR #16300:
URL: https://github.com/apache/kafka/pull/16300#issuecomment-2241810066
@cadonna This PR contains the handling of processing exceptions in `StreamTask#punctuate`:
- `StreamsException` are not handled right now. We could include them in the catch block and rethrow them as is
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "sebastienviale (via GitHub)" <gi...@apache.org>.
sebastienviale commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1689690526
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamTaskTest.java:
##########
@@ -2647,6 +2657,62 @@ public void shouldNotCheckpointAfterRestorationWhenExactlyOnceEnabled() {
verify(recordCollector, never()).offsets();
}
+ @Test
+ public void shouldNotThrowStreamsExceptionWhenProcessingExceptionHandlerRepliesWithContinue() {
+ when(stateManager.taskId()).thenReturn(taskId);
+ when(stateManager.taskType()).thenReturn(TaskType.ACTIVE);
+ task = createStatelessTask(createConfig(AT_LEAST_ONCE, "100",
+ LogAndFailExceptionHandler.class.getName(), LogAndContinueProcessingExceptionHandler.class.getName()));
+
+ assertDoesNotThrow(() ->
+ task.punctuate(processorStreamTime, 1, PunctuationType.STREAM_TIME, timestamp -> {
+ throw new KafkaException("KABOOM!");
+ })
+ );
+ }
+
+ @Test
+ public void shouldThrowStreamsExceptionWhenProcessingExceptionHandlerRepliesWithFail() {
+ when(stateManager.taskId()).thenReturn(taskId);
+ when(stateManager.taskType()).thenReturn(TaskType.ACTIVE);
+ task = createStatelessTask(createConfig(AT_LEAST_ONCE, "100",
+ LogAndFailExceptionHandler.class.getName(), LogAndFailProcessingExceptionHandler.class.getName()));
+
+ final StreamsException streamsException = assertThrows(StreamsException.class,
+ () -> task.punctuate(processorStreamTime, 1, PunctuationType.STREAM_TIME, timestamp -> {
+ throw new KafkaException("KABOOM!");
+ }));
+
+ assertTrue(streamsException.getCause() instanceof KafkaException);
+ assertEquals("KABOOM!", streamsException.getCause().getMessage());
+ }
+
+ @Test
+ public void shouldThrowStreamsExceptionWhenProcessingExceptionHandlerThrowsAnException() {
+ when(stateManager.taskId()).thenReturn(taskId);
+ when(stateManager.taskType()).thenReturn(TaskType.ACTIVE);
+ task = createStatelessTask(createConfig(AT_LEAST_ONCE, "100",
+ LogAndFailExceptionHandler.class.getName(), ProcessingExceptionHandlerMock.class.getName()));
+
+ final StreamsException streamsException = assertThrows(StreamsException.class,
+ () -> task.punctuate(processorStreamTime, 1, PunctuationType.STREAM_TIME, timestamp -> {
+ throw new KafkaException("KABOOM!");
+ }));
+
+ final String msg = streamsException.getMessage();
+ assertTrue(msg.equals("Fatal user code error in processing error callback"));
+ }
+
+ public static class ProcessingExceptionHandlerMock implements ProcessingExceptionHandler {
+ @Override
+ public ProcessingExceptionHandler.ProcessingHandlerResponse handle(final ErrorHandlerContext context, final Record<?, ?> record, final Exception exception) {
+ throw new RuntimeException("KABOOM!");
+ }
Review Comment:
done
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "cadonna (via GitHub)" <gi...@apache.org>.
cadonna commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686395355
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
throw e;
} catch (final RuntimeException e) {
Review Comment:
For `process()`, Streams catches a `Exception` and here it is a `RuntimeException`. As far as I understand the difference is that `RuntimeException` only catches unchecked exceptions whereas `Exception` catches unchecked and checked exception. Since Streams does not throw any checked exceptions from either `process()` or `punctuate` it is fine to use in both places `RuntimeException`.
Could you change this also for `process()` in this PR?
##########
checkstyle/suppressions.xml:
##########
@@ -193,7 +193,7 @@
<!-- Streams -->
<suppress checks="ClassFanOutComplexity"
- files="(KafkaStreams|KStreamImpl|KTableImpl|InternalTopologyBuilder|StreamsPartitionAssignor|StreamThread|IQv2StoreIntegrationTest|KStreamImplTest|RocksDBStore).java"/>
+ files="(KafkaStreams|KStreamImpl|KTableImpl|InternalTopologyBuilder|StreamsPartitionAssignor|StreamThread|IQv2StoreIntegrationTest|KStreamImplTest|RocksDBStore|StreamTask).java"/>
Review Comment:
That is a pity 😞 ! But I do not see a quick fix to avoid the change.
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
throw e;
} catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(recordContext.topic(),
+ recordContext.partition(), recordContext.offset(), recordContext.headers(), null, null, node.name(), id);
Review Comment:
nit:
```suggestion
final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(
recordContext.topic(),
recordContext.partition(),
recordContext.offset(),
recordContext.headers(),
null,
null,
node.name(),
id
);
```
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
throw e;
} catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(recordContext.topic(),
+ recordContext.partition(), recordContext.offset(), recordContext.headers(), null, null, node.name(), id);
+
+ final ProcessingExceptionHandler.ProcessingHandlerResponse response = processingExceptionHandler
+ .handle(errorHandlerContext, null, e);
+
+ if (response == ProcessingExceptionHandler.ProcessingHandlerResponse.FAIL) {
+ throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
Review Comment:
Could you add a error log here?
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
Now we have a weird situation where you can throw a `StreamsException` from `process()` and Streams will handle it in the processing handler but when you throw a `StreamsException` from `punctuate()` Streams will not handle it.
##########
streams/src/test/java/org/apache/kafka/streams/integration/ProcessingExceptionHandlerIntegrationTest.java:
##########
@@ -78,6 +82,7 @@ public void shouldFailWhenProcessingExceptionOccurs() {
.map(KeyValue::new)
.mapValues(value -> value)
.process(runtimeErrorProcessorSupplierMock())
+ .process(runtimeErrorPunctuateProcessorSupplierMock())
Review Comment:
You should not test punctuate with the `TopologyTestDriver`. Method `punctuate` is called outside of the topology in the poll loop. Using the `TopologyTestDriver`, you basically call `task.maybePunctuateSystemTime();` in `driver.advanceWallClockTime()` which is a helper test infra method. This is not really testing the integration of `ProcessingExceptionHandler` with `punctuate()` in the Streams runtime.
Testing the integration of `ProcessingExceptionHandler` in `process()` with the `TopologyTestDriver` makes a little bit more sense because you can test the case when a downstream processor throws and it should not affect an upstream processor, but that case you do not have with `punctuate()`. However, also for `process()` a real intergration test would be better.
So given the tight schedule, my proposal is to revert the changes regarding `punctuate()` in this file and only have unit tests. Then, you can add a real integration test in a separate PR when we merged all the rest first.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "cadonna (via GitHub)" <gi...@apache.org>.
cadonna commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686527967
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
Oh, I haven't seen your comment. Sorry!
Your proposal does not change anything, right? We will still have the situtation that if a user throws a `StreamsException` from `punctuate()` it will not be handled. But in `process()` it will be handled.
I think, we have the following options:
1. We live with this asymmetry between `punctuate()` and `process()`.
2. We do not handle `StreamsException` in `process()`.
3. We do handle `StreamsException` in `punctuate()`.
What do you exactly mean with
> might end up with handling exceptions that are not desirable
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "cadonna (via GitHub)" <gi...@apache.org>.
cadonna commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686568276
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/ProcessorNode.java:
##########
@@ -203,7 +203,7 @@ public void process(final Record<KIn, VIn> record) {
} catch (final FailedProcessingException | TaskCorruptedException | TaskMigratedException e) {
// Rethrow exceptions that should not be handled here
throw e;
- } catch (final Exception e) {
+ } catch (final RuntimeException e) {
Review Comment:
Great! Thanks!
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686596266
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -913,10 +918,30 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
try {
maybeMeasureLatency(() -> node.punctuate(timestamp, punctuator), time, punctuateLatencySensor);
- } catch (final StreamsException e) {
- throw e;
} catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(
+ recordContext.topic(),
+ recordContext.partition(),
+ recordContext.offset(),
+ recordContext.headers(),
+ null,
+ null,
+ node.name(),
+ id
+ );
+ final ProcessingExceptionHandler.ProcessingHandlerResponse response = processingExceptionHandler
+ .handle(errorHandlerContext, null, e);
+
+ if (response == ProcessingExceptionHandler.ProcessingHandlerResponse.FAIL) {
+ log.error("Processing exception handler is set to fail upon" +
+ " a processing error. If you would rather have the streaming pipeline" +
+ " continue after a processing error, please set the " +
+ PROCESSING_EXCEPTION_HANDLER_CLASS_CONFIG + " appropriately.");
+
+ throw e instanceof StreamsException ? (StreamsException) e : new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
Review Comment:
Fixed
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1697703902
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
@mjsax NVM, in the following case:
```java
builder
.stream(...)
.process(...) // punctuate() calls context.forward() here
.map((key, value) -> throw new RuntimeException());
```
RuntimeException is being caught and handled in the `ProcessorNode#process`, then thrown as a `FailedProcessingException` and caught in the `StreamTask#punctuate`.
In `punctuate`, So I think we should:
- catch `FailedProcessingException` coming from nodes, unwrap it and throw a new StreamsException ➡️ It avoids passing the exception through the processing exception handler twice.
- catch `TaskCorruptedException | TaskMigratedException` and throw it as is ➡️ We do not want to handle them / wrap them to anything else.
- catch `Exception`, apply the processing exception handler and throw StreamsException ➡️ We handle anything else is not coming from a processor node.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on PR #16300:
URL: https://github.com/apache/kafka/pull/16300#issuecomment-2261649144
Merged to `trunk` and cherry-picked to `3.9` branch.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1698085150
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -917,8 +922,34 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
maybeMeasureLatency(() -> node.punctuate(timestamp, punctuator), time, punctuateLatencySensor);
} catch (final StreamsException e) {
throw e;
- } catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ } catch (final Exception e) {
Review Comment:
@mjsax For this reason: https://github.com/apache/kafka/pull/16300#discussion_r1687844510
`Exception` is caught in `ProcessorNode#process`, `RecordCollectorImpl#handleException` and `RecordDeserializer#deserialize` so the last discussion mentionned to stick to `Exception` here to be consistent.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686580703
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
throw e;
} catch (final RuntimeException e) {
Review Comment:
Done
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on PR #16300:
URL: https://github.com/apache/kafka/pull/16300#issuecomment-2261553816
> I'm updating the KIP to remove references to sourceRawKey/sourceRawValue. To be moved to KIP-1034.
Great. This would have been my next question. Also, after you updated the wiki page, please send a follow-up email to the VOTE thread of the KIP, and call out the changes made. It's not just `sourceRawKey/sourceRawValue`, but also this PR, right? The KIP does not say anything about punctuations? And the KIP should also talk about the case, when the handler crashed and throws an exception. -- Was there anything else that was changed and should be called out?
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "sebastienviale (via GitHub)" <gi...@apache.org>.
sebastienviale commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1688027094
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
throw e;
} catch (final RuntimeException e) {
Review Comment:
done
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1696286131
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
Ignore me comment above -- I was looking at an outdate `trunk`... my bad. Seem the code is already doing the correct thing now.
But this PR still needs an update, to follow the same patterns in `punctuate()` as we have for `process()`.
> Considering TaskCorruptedException/TaskMigratedException cannot reach punctuate(), we updated the PR to handle all StreamsException in the punctuate.
As you sure about this? In the end, `punctuate()` can call `context.forward()` and can also reach `RecordCollectorImpl#send()` which might throw these exception?
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1697964483
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -917,8 +922,34 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
maybeMeasureLatency(() -> node.punctuate(timestamp, punctuator), time, punctuateLatencySensor);
} catch (final StreamsException e) {
throw e;
- } catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ } catch (final Exception e) {
Review Comment:
Why do we catch `Exception` here, but not `RuntimeException`? If no checked exception is declared, it seem not to be "correct"?
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on PR #16300:
URL: https://github.com/apache/kafka/pull/16300#issuecomment-2261534283
@mjsax This PR was the last one! If any additional updates are needed, let us know
I'm updating the KIP to remove references to `sourceRawKey`/`sourceRawValue`. To be moved to KIP-1034.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686582263
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
throw e;
} catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(recordContext.topic(),
+ recordContext.partition(), recordContext.offset(), recordContext.headers(), null, null, node.name(), id);
+
+ final ProcessingExceptionHandler.ProcessingHandlerResponse response = processingExceptionHandler
+ .handle(errorHandlerContext, null, e);
+
+ if (response == ProcessingExceptionHandler.ProcessingHandlerResponse.FAIL) {
+ throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
Review Comment:
Done. `process()` and `punctuate` will log the same error
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686470956
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
Correct, as mentioned in my previous comment we can handle all `RuntimeException` and `if (exception instanceof StreamsException)` already, then we can `throw e` as is.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686582263
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
throw e;
} catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(recordContext.topic(),
+ recordContext.partition(), recordContext.offset(), recordContext.headers(), null, null, node.name(), id);
+
+ final ProcessingExceptionHandler.ProcessingHandlerResponse response = processingExceptionHandler
+ .handle(errorHandlerContext, null, e);
+
+ if (response == ProcessingExceptionHandler.ProcessingHandlerResponse.FAIL) {
+ throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
Review Comment:
Done. `proccess()` and `punctuate` will log the same error
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1696256477
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
Just catching up. For `process()` we currently don't handle `ClassCastException` as well as `FailedProcessingException | TaskCorruptedException | TaskMigratedException`.
However, only rethrow `ClassCastException` wrapped as `StreamsException()` and thus might catch up "upstream" -- wondering if this is intended?
I also just looked into the call-trace and it seems we actually also have dedicate
```
} catch (final StreamsException exception) {
record = null;
throw exception;
} catch (final RuntimeException e) {
```
inside `StreamTask#process` but we only handle `FailedProcessingException` in the second catch for the `RuntimeException`. Is this by design? Atm `FailedProcessingException extends KafkaException` so it still works, but as pointed out on an already merged PR, I think it should actually extend `StreamsException` (https://github.com/apache/kafka/pull/16093/files#r1687232849) what implies we would need some changes.
In general, `StreamsException` is actually not design to be thrown by users (not to be catch by users), but it can still bubble up from `process()` -- So I think it does make sense to catch and pass into the handler for both cases `process()` and `punctuate()`.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1697004851
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
@mjsax
If `punctuate()` calls `context.forward()` and an exception occurs in a processor I'm having doubts if the exception will either:
- Go up to the `try-catch` block we added around `punctuate()`
- Go up to the `try-catch` block we added around `ProcessorNode#process`
`Try-catch` block on `punctuate()` was initially added to handle exceptions that can occurs in punctuator:
```java
context.schedule(Duration.ofMinutes(1), PunctuationType.WALL_CLOCK_TIME,
timestamp -> {
throw new RuntimeException("Punctuate error");
});
```
Doing further tests on this 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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1697961672
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
Yes, SGTM.
It must be a mix of what we do in `ProcessingNode#process()` and `StreamTask#process()`.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1698085150
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -917,8 +922,34 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
maybeMeasureLatency(() -> node.punctuate(timestamp, punctuator), time, punctuateLatencySensor);
} catch (final StreamsException e) {
throw e;
- } catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ } catch (final Exception e) {
Review Comment:
@mjsax For this reason: https://github.com/apache/kafka/pull/16300#discussion_r1687844510
`Exception` is caught in `ProcessorNode#process`, `RecordCollectorImpl#handleException` and `RecordDeserializer#deserialize` so we keep `Exception` here to be consistent
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1698975359
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -917,8 +922,34 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
maybeMeasureLatency(() -> node.punctuate(timestamp, punctuator), time, punctuateLatencySensor);
} catch (final StreamsException e) {
throw e;
- } catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ } catch (final Exception e) {
Review Comment:
Thanks. I disagree to @cadonna conclusion -- we should rather catch `RuntimeException` everywhere (consistency yes, but the other way around).
I'll cover this on the other PR I did open.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "cadonna (via GitHub)" <gi...@apache.org>.
cadonna commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1689672493
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamTaskTest.java:
##########
@@ -2647,6 +2657,62 @@ public void shouldNotCheckpointAfterRestorationWhenExactlyOnceEnabled() {
verify(recordCollector, never()).offsets();
}
+ @Test
+ public void shouldNotThrowStreamsExceptionWhenProcessingExceptionHandlerRepliesWithContinue() {
+ when(stateManager.taskId()).thenReturn(taskId);
+ when(stateManager.taskType()).thenReturn(TaskType.ACTIVE);
+ task = createStatelessTask(createConfig(AT_LEAST_ONCE, "100",
+ LogAndFailExceptionHandler.class.getName(), LogAndContinueProcessingExceptionHandler.class.getName()));
+
+ assertDoesNotThrow(() ->
+ task.punctuate(processorStreamTime, 1, PunctuationType.STREAM_TIME, timestamp -> {
+ throw new KafkaException("KABOOM!");
+ })
+ );
+ }
+
+ @Test
+ public void shouldThrowStreamsExceptionWhenProcessingExceptionHandlerRepliesWithFail() {
+ when(stateManager.taskId()).thenReturn(taskId);
+ when(stateManager.taskType()).thenReturn(TaskType.ACTIVE);
+ task = createStatelessTask(createConfig(AT_LEAST_ONCE, "100",
+ LogAndFailExceptionHandler.class.getName(), LogAndFailProcessingExceptionHandler.class.getName()));
+
+ final StreamsException streamsException = assertThrows(StreamsException.class,
+ () -> task.punctuate(processorStreamTime, 1, PunctuationType.STREAM_TIME, timestamp -> {
+ throw new KafkaException("KABOOM!");
+ }));
+
+ assertTrue(streamsException.getCause() instanceof KafkaException);
+ assertEquals("KABOOM!", streamsException.getCause().getMessage());
+ }
+
+ @Test
+ public void shouldThrowStreamsExceptionWhenProcessingExceptionHandlerThrowsAnException() {
+ when(stateManager.taskId()).thenReturn(taskId);
+ when(stateManager.taskType()).thenReturn(TaskType.ACTIVE);
+ task = createStatelessTask(createConfig(AT_LEAST_ONCE, "100",
+ LogAndFailExceptionHandler.class.getName(), ProcessingExceptionHandlerMock.class.getName()));
+
+ final StreamsException streamsException = assertThrows(StreamsException.class,
+ () -> task.punctuate(processorStreamTime, 1, PunctuationType.STREAM_TIME, timestamp -> {
+ throw new KafkaException("KABOOM!");
+ }));
+
+ final String msg = streamsException.getMessage();
+ assertTrue(msg.equals("Fatal user code error in processing error callback"));
+ }
+
+ public static class ProcessingExceptionHandlerMock implements ProcessingExceptionHandler {
+ @Override
+ public ProcessingExceptionHandler.ProcessingHandlerResponse handle(final ErrorHandlerContext context, final Record<?, ?> record, final Exception exception) {
+ throw new RuntimeException("KABOOM!");
+ }
Review Comment:
nit:
```suggestion
@Override
public ProcessingExceptionHandler.ProcessingHandlerResponse handle(final ErrorHandlerContext context, final Record<?, ?> record, final Exception exception) {
throw new RuntimeException("KABOOM!");
}
```
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "cadonna (via GitHub)" <gi...@apache.org>.
cadonna commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686587201
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -913,10 +918,30 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
try {
maybeMeasureLatency(() -> node.punctuate(timestamp, punctuator), time, punctuateLatencySensor);
- } catch (final StreamsException e) {
- throw e;
} catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(
+ recordContext.topic(),
+ recordContext.partition(),
+ recordContext.offset(),
+ recordContext.headers(),
+ null,
+ null,
+ node.name(),
+ id
+ );
+ final ProcessingExceptionHandler.ProcessingHandlerResponse response = processingExceptionHandler
+ .handle(errorHandlerContext, null, e);
+
+ if (response == ProcessingExceptionHandler.ProcessingHandlerResponse.FAIL) {
+ log.error("Processing exception handler is set to fail upon" +
+ " a processing error. If you would rather have the streaming pipeline" +
+ " continue after a processing error, please set the " +
+ PROCESSING_EXCEPTION_HANDLER_CLASS_CONFIG + " appropriately.");
+
+ throw e instanceof StreamsException ? (StreamsException) e : new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
Review Comment:
nit:
```suggestion
throw e instanceof StreamsException ? e : new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
```
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686578244
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
Well, in the `ProcessorNode` we do not handle `TaskCorruptedException` or `TaskMigratedException` which extends `StreamsException` for example.
Unless I'm wrong these exceptions cannot be caught in the `punctuate`, right? (I don't want to end up in a situation where we do not handle `TaskCorruptedException` in the `process()`, but we do in the `punctuate()`)
👉 We updated the PR to handle `StreamsException` in the `punctuate`
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1686562243
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
throw e;
} catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(recordContext.topic(),
+ recordContext.partition(), recordContext.offset(), recordContext.headers(), null, null, node.name(), id);
Review Comment:
Done
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1697965185
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -917,8 +922,34 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
maybeMeasureLatency(() -> node.punctuate(timestamp, punctuator), time, punctuateLatencySensor);
} catch (final StreamsException e) {
throw e;
- } catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ } catch (final Exception e) {
+ final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(
+ null,
+ recordContext.topic(),
+ recordContext.partition(),
+ recordContext.offset(),
+ recordContext.headers(),
+ null,
+ null
+ );
+
+ final ProcessingExceptionHandler.ProcessingHandlerResponse response;
+
+ try {
+ response = processingExceptionHandler.handle(errorHandlerContext, null, e);
+ } catch (final Exception fatalUserException) {
Review Comment:
Same here. Why not `RuntimeException` -- given that no checked exception is declared for the `handler(...)` method, it's not possible to get a `Exception` here.
Same seems to apply to `ProcessorNode` code which has the same try-catch block.
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1697965185
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -917,8 +922,34 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
maybeMeasureLatency(() -> node.punctuate(timestamp, punctuator), time, punctuateLatencySensor);
} catch (final StreamsException e) {
throw e;
- } catch (final RuntimeException e) {
- throw new StreamsException(String.format("%sException caught while punctuating processor '%s'", logPrefix, node.name()), e);
+ } catch (final Exception e) {
+ final ErrorHandlerContext errorHandlerContext = new DefaultErrorHandlerContext(
+ null,
+ recordContext.topic(),
+ recordContext.partition(),
+ recordContext.offset(),
+ recordContext.headers(),
+ null,
+ null
+ );
+
+ final ProcessingExceptionHandler.ProcessingHandlerResponse response;
+
+ try {
+ response = processingExceptionHandler.handle(errorHandlerContext, null, e);
+ } catch (final Exception fatalUserException) {
Review Comment:
Same here. Why not `RuntimeException` -- given that no checked exception is declared for the `handler(...)` method, it's not possible to get a `Exception` 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.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "loicgreffier (via GitHub)" <gi...@apache.org>.
loicgreffier commented on code in PR #16300:
URL: https://github.com/apache/kafka/pull/16300#discussion_r1698245322
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java:
##########
@@ -916,7 +920,17 @@ public void punctuate(final ProcessorNode<?, ?, ?, ?> node,
} catch (final StreamsException e) {
Review Comment:
@mjsax I've updated the PR
--
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] KAFKA-16448: Handle processing exceptions in punctuate [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax merged PR #16300:
URL: https://github.com/apache/kafka/pull/16300
--
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