mirror of https://github.com/apache/kafka.git
StreamProducer may timeout in sendOffsetsToTransaction() or commitTransaction() call. To distinguish both cases, we should make both calls in individual try-catch blocks. Reviewers: Bill Bejeck<bbejeck@apache.org>
This commit is contained in:
parent
64aebb5621
commit
c8f83592b2
|
@ -247,6 +247,22 @@ public class StreamsProducer {
|
|||
maybeBeginTransaction();
|
||||
try {
|
||||
producer.sendOffsetsToTransaction(offsets, consumerGroupMetadata);
|
||||
} catch (final ProducerFencedException | InvalidProducerEpochException | CommitFailedException | InvalidPidMappingException error) {
|
||||
throw new TaskMigratedException(
|
||||
formatException("Producer got fenced trying to add offsets to a transaction"),
|
||||
error
|
||||
);
|
||||
} catch (final TimeoutException timeoutException) {
|
||||
// re-throw to trigger `task.timeout.ms`
|
||||
throw timeoutException;
|
||||
} catch (final KafkaException error) {
|
||||
throw new StreamsException(
|
||||
formatException("Error encountered trying to add offsets to a transaction"),
|
||||
error
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
producer.commitTransaction();
|
||||
transactionInFlight = false;
|
||||
} catch (final ProducerFencedException | InvalidProducerEpochException | CommitFailedException | InvalidPidMappingException error) {
|
||||
|
|
|
@ -684,7 +684,7 @@ public class StreamsProducerTest {
|
|||
assertThat(thrown.getCause(), is(eosMockProducer.sendOffsetsToTransactionException));
|
||||
assertThat(
|
||||
thrown.getMessage(),
|
||||
is("Producer got fenced trying to commit a transaction [test];" +
|
||||
is("Producer got fenced trying to add offsets to a transaction [test];" +
|
||||
" it means all tasks belonging to this thread should be migrated.")
|
||||
);
|
||||
}
|
||||
|
@ -703,7 +703,7 @@ public class StreamsProducerTest {
|
|||
assertThat(thrown.getCause(), is(eosMockProducer.sendOffsetsToTransactionException));
|
||||
assertThat(
|
||||
thrown.getMessage(),
|
||||
is("Error encountered trying to commit a transaction [test]")
|
||||
is("Error encountered trying to add offsets to a transaction [test]")
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue