use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class ProcessorStateManager method checkpoint.
@Override
public void checkpoint() {
// checkpoint those stores that are only logged and persistent to the checkpoint file
final Map<TopicPartition, Long> checkpointingOffsets = new HashMap<>();
for (final StateStoreMetadata storeMetadata : stores.values()) {
if (storeMetadata.commitCallback != null && !storeMetadata.corrupted) {
try {
storeMetadata.commitCallback.onCommit();
} catch (final IOException e) {
throw new ProcessorStateException(format("%sException caught while trying to checkpoint store, " + "changelog partition %s", logPrefix, storeMetadata.changelogPartition), e);
}
}
// store is logged, persistent, not corrupted, and has a valid current offset
if (storeMetadata.changelogPartition != null && storeMetadata.stateStore.persistent() && !storeMetadata.corrupted) {
final long checkpointableOffset = checkpointableOffsetFromChangelogOffset(storeMetadata.offset);
checkpointingOffsets.put(storeMetadata.changelogPartition, checkpointableOffset);
}
}
log.debug("Writing checkpoint: {}", checkpointingOffsets);
try {
checkpointFile.write(checkpointingOffsets);
} catch (final IOException e) {
log.warn("Failed to write offset checkpoint file to [{}]." + " This may occur if OS cleaned the state.dir in case when it located in ${java.io.tmpdir} directory." + " This may also occur due to running multiple instances on the same machine using the same state dir." + " Changing the location of state.dir may resolve the problem.", checkpointFile, e);
}
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class ProcessorStateManagerTest method shouldThrowIllegalStateIfInitializingOffsetsForCorruptedTasks.
@Test
public void shouldThrowIllegalStateIfInitializingOffsetsForCorruptedTasks() {
final ProcessorStateManager stateMgr = getStateManager(Task.TaskType.ACTIVE, true);
try {
stateMgr.registerStore(persistentStore, persistentStore.stateRestoreCallback, null);
stateMgr.markChangelogAsCorrupted(mkSet(persistentStorePartition));
final ProcessorStateException thrown = assertThrows(ProcessorStateException.class, () -> stateMgr.initializeStoreOffsetsFromCheckpoint(true));
assertTrue(thrown.getCause() instanceof IllegalStateException);
} finally {
stateMgr.close();
}
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class ProcessorStateManagerTest method shouldThrowIfLoadCheckpointThrows.
@Test
public void shouldThrowIfLoadCheckpointThrows() throws Exception {
final ProcessorStateManager stateMgr = getStateManager(Task.TaskType.ACTIVE);
stateMgr.registerStore(persistentStore, persistentStore.stateRestoreCallback, null);
final File file = new File(stateMgr.baseDir(), CHECKPOINT_FILE_NAME);
file.createNewFile();
final FileWriter writer = new FileWriter(file);
writer.write("abcdefg");
writer.close();
try {
stateMgr.initializeStoreOffsetsFromCheckpoint(true);
fail("should have thrown processor state exception when IO exception happens");
} catch (final ProcessorStateException e) {
// pass
}
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class ProcessorStateManagerTest method shouldCloseAllStoresEvenIfStoreThrowsException.
@Test
public void shouldCloseAllStoresEvenIfStoreThrowsException() {
final AtomicBoolean closedStore = new AtomicBoolean(false);
final MockKeyValueStore stateStore1 = new MockKeyValueStore(persistentStoreName, true) {
@Override
public void close() {
throw new RuntimeException("KABOOM!");
}
};
final MockKeyValueStore stateStore2 = new MockKeyValueStore(persistentStoreTwoName, true) {
@Override
public void close() {
closedStore.set(true);
}
};
final ProcessorStateManager stateManager = getStateManager(Task.TaskType.ACTIVE);
stateManager.registerStore(stateStore1, stateStore1.stateRestoreCallback, null);
stateManager.registerStore(stateStore2, stateStore2.stateRestoreCallback, null);
try {
stateManager.close();
} catch (final ProcessorStateException expected) {
/* ignore */
}
Assert.assertTrue(closedStore.get());
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class RocksDBStore method openRocksDB.
void openRocksDB(final DBOptions dbOptions, final ColumnFamilyOptions columnFamilyOptions) {
final List<ColumnFamilyDescriptor> columnFamilyDescriptors = Collections.singletonList(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, columnFamilyOptions));
final List<ColumnFamilyHandle> columnFamilies = new ArrayList<>(columnFamilyDescriptors.size());
try {
db = RocksDB.open(dbOptions, dbDir.getAbsolutePath(), columnFamilyDescriptors, columnFamilies);
dbAccessor = new SingleColumnFamilyAccessor(columnFamilies.get(0));
} catch (final RocksDBException e) {
throw new ProcessorStateException("Error opening store " + name + " at location " + dbDir.toString(), e);
}
}
Aggregations