use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class StateManagerUtilTest method testCloseStateManagerThrowsExceptionWhenClean.
@Test
public void testCloseStateManagerThrowsExceptionWhenClean() {
expect(stateManager.taskId()).andReturn(taskId);
expect(stateDirectory.lock(taskId)).andReturn(true);
stateManager.close();
expectLastCall().andThrow(new ProcessorStateException("state manager failed to close"));
// The unlock logic should still be executed.
stateDirectory.unlock(taskId);
ctrl.checkOrder(true);
ctrl.replay();
final ProcessorStateException thrown = assertThrows(ProcessorStateException.class, () -> StateManagerUtil.closeStateManager(logger, "logPrefix:", true, false, stateManager, stateDirectory, TaskType.ACTIVE));
// Thrown stateMgr exception will not be wrapped.
assertEquals("state manager failed to close", thrown.getMessage());
ctrl.verify();
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class StateManagerUtilTest method testCloseStateManagerThrowsExceptionWhenDirty.
@Test
public void testCloseStateManagerThrowsExceptionWhenDirty() {
expect(stateManager.taskId()).andReturn(taskId);
expect(stateDirectory.lock(taskId)).andReturn(true);
stateManager.close();
expectLastCall().andThrow(new ProcessorStateException("state manager failed to close"));
stateDirectory.unlock(taskId);
ctrl.checkOrder(true);
ctrl.replay();
assertThrows(ProcessorStateException.class, () -> StateManagerUtil.closeStateManager(logger, "logPrefix:", false, false, stateManager, stateDirectory, TaskType.ACTIVE));
ctrl.verify();
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class StreamTaskTest method shouldThrowOnCloseCleanFlushError.
@Test
public void shouldThrowOnCloseCleanFlushError() {
final long offset = 543L;
EasyMock.expect(recordCollector.offsets()).andReturn(singletonMap(changelogPartition, offset));
stateManager.flushCache();
EasyMock.expectLastCall().andThrow(new ProcessorStateException("KABOOM!")).anyTimes();
stateManager.flush();
EasyMock.expectLastCall().andThrow(new AssertionError("Flush should not be called")).anyTimes();
stateManager.checkpoint();
EasyMock.expectLastCall().andThrow(new AssertionError("Checkpoint should not be called")).anyTimes();
stateManager.close();
EasyMock.expectLastCall().andThrow(new AssertionError("Close should not be called!")).anyTimes();
EasyMock.expect(stateManager.changelogPartitions()).andReturn(Collections.emptySet()).anyTimes();
EasyMock.expect(stateManager.changelogOffsets()).andReturn(emptyMap()).anyTimes();
EasyMock.replay(recordCollector, stateManager);
final MetricName metricName = setupCloseTaskMetric();
task = createOptimizedStatefulTask(createConfig("100"), consumer);
task.initializeIfNeeded();
task.completeRestoration(noOpResetter -> {
});
// process one record to make commit needed
task.addRecords(partition1, singletonList(getConsumerRecordWithOffsetAsTimestamp(partition1, offset)));
task.process(100L);
assertThrows(ProcessorStateException.class, task::prepareCommit);
assertEquals(RUNNING, task.state());
final double expectedCloseTaskMetric = 0.0;
verifyCloseTaskMetric(expectedCloseTaskMetric, streamsMetrics, metricName);
EasyMock.verify(stateManager);
EasyMock.reset(stateManager);
EasyMock.expect(stateManager.changelogPartitions()).andReturn(Collections.emptySet()).anyTimes();
EasyMock.replay(stateManager);
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class StreamTaskTest method shouldThrowExceptionOnCloseCleanError.
@Test
public void shouldThrowExceptionOnCloseCleanError() {
final long offset = 543L;
EasyMock.expect(recordCollector.offsets()).andReturn(emptyMap()).anyTimes();
stateManager.checkpoint();
EasyMock.expectLastCall().once();
EasyMock.expect(stateManager.changelogPartitions()).andReturn(singleton(changelogPartition)).anyTimes();
EasyMock.expect(stateManager.changelogOffsets()).andReturn(singletonMap(changelogPartition, offset)).anyTimes();
stateManager.close();
EasyMock.expectLastCall().andThrow(new ProcessorStateException("KABOOM!")).anyTimes();
EasyMock.replay(recordCollector, stateManager);
final MetricName metricName = setupCloseTaskMetric();
task = createOptimizedStatefulTask(createConfig("100"), consumer);
task.initializeIfNeeded();
task.completeRestoration(noOpResetter -> {
});
task.addRecords(partition1, singletonList(getConsumerRecordWithOffsetAsTimestamp(partition1, offset)));
task.process(100L);
assertTrue(task.commitNeeded());
task.suspend();
task.prepareCommit();
task.postCommit(true);
assertThrows(ProcessorStateException.class, () -> task.closeClean());
final double expectedCloseTaskMetric = 0.0;
verifyCloseTaskMetric(expectedCloseTaskMetric, streamsMetrics, metricName);
EasyMock.verify(stateManager);
EasyMock.reset(stateManager);
EasyMock.expect(stateManager.changelogPartitions()).andStubReturn(singleton(changelogPartition));
stateManager.close();
EasyMock.expectLastCall();
EasyMock.replay(stateManager);
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class ProcessorStateManager method flush.
/**
* @throws TaskMigratedException recoverable error sending changelog records that would cause the task to be removed
* @throws StreamsException fatal error when flushing the state store, for example sending changelog records failed
* or flushing state store get IO errors; such error should cause the thread to die
*/
@Override
public void flush() {
RuntimeException firstException = null;
// attempting to flush the stores
if (!stores.isEmpty()) {
log.debug("Flushing all stores registered in the state manager: {}", stores);
for (final StateStoreMetadata metadata : stores.values()) {
final StateStore store = metadata.stateStore;
log.trace("Flushing store {}", store.name());
try {
store.flush();
} catch (final RuntimeException exception) {
if (firstException == null) {
// do NOT wrap the error if it is actually caused by Streams itself
if (exception instanceof StreamsException)
firstException = exception;
else
firstException = new ProcessorStateException(format("%sFailed to flush state store %s", logPrefix, store.name()), exception);
}
log.error("Failed to flush state store {}: ", store.name(), exception);
}
}
}
if (firstException != null) {
throw firstException;
}
}
Aggregations