use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class GlobalStateManagerImpl method flush.
public void flush(final InternalProcessorContext context) {
log.debug("Flushing all global stores registered in the state manager");
for (StateStore store : this.stores.values()) {
try {
log.trace("Flushing global store={}", store.name());
store.flush();
} catch (Exception e) {
throw new ProcessorStateException(String.format("Failed to flush global state store %s", store.name()), e);
}
}
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class ProcessorStateManager method updateStandbyStates.
public List<ConsumerRecord<byte[], byte[]>> updateStandbyStates(TopicPartition storePartition, List<ConsumerRecord<byte[], byte[]>> records) {
long limit = offsetLimit(storePartition);
List<ConsumerRecord<byte[], byte[]>> remainingRecords = null;
// restore states from changelog records
StateRestoreCallback restoreCallback = restoreCallbacks.get(storePartition.topic());
long lastOffset = -1L;
int count = 0;
for (ConsumerRecord<byte[], byte[]> record : records) {
if (record.offset() < limit) {
try {
restoreCallback.restore(record.key(), record.value());
} catch (Exception e) {
throw new ProcessorStateException(String.format("%s exception caught while trying to restore state from %s", logPrefix, storePartition), e);
}
lastOffset = record.offset();
} else {
if (remainingRecords == null)
remainingRecords = new ArrayList<>(records.size() - count);
remainingRecords.add(record);
}
count++;
}
// record the restored offset for its change log partition
restoredOffsets.put(storePartition, lastOffset + 1);
return remainingRecords;
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class Segments method openExisting.
void openExisting(final ProcessorContext context) {
try {
File dir = new File(context.stateDir(), name);
if (dir.exists()) {
String[] list = dir.list();
if (list != null) {
long[] segmentIds = new long[list.length];
for (int i = 0; i < list.length; i++) segmentIds[i] = segmentIdFromSegmentName(list[i]);
// open segments in the id order
Arrays.sort(segmentIds);
for (long segmentId : segmentIds) {
if (segmentId >= 0) {
getOrCreateSegment(segmentId, context);
}
}
}
} else {
if (!dir.mkdir()) {
throw new ProcessorStateException(String.format("dir %s doesn't exist and cannot be created for segments %s", dir, name));
}
}
} catch (Exception ex) {
// ignore
}
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class GlobalStateManagerImplTest method shouldAttemptToCloseAllStoresEvenWhenSomeException.
@Test
public void shouldAttemptToCloseAllStoresEvenWhenSomeException() throws Exception {
stateManager.initialize(context);
initializeConsumer(1, 1, t1);
initializeConsumer(1, 1, t2);
final NoOpReadOnlyStore store = new NoOpReadOnlyStore("t1-store") {
@Override
public void close() {
super.close();
throw new RuntimeException("KABOOM!");
}
};
stateManager.register(store, false, stateRestoreCallback);
stateManager.register(store2, false, stateRestoreCallback);
try {
stateManager.close(Collections.<TopicPartition, Long>emptyMap());
} catch (ProcessorStateException e) {
// expected
}
assertFalse(store.isOpen());
assertFalse(store2.isOpen());
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project apache-kafka-on-k8s by banzaicloud.
the class RocksDBStore method toggleDbForBulkLoading.
private void toggleDbForBulkLoading(final boolean prepareForBulkload) {
if (prepareForBulkload) {
// if the store is not empty, we need to compact to get around the num.levels check
// for bulk loading
final String[] sstFileNames = dbDir.list(new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
return name.matches(".*\\.sst");
}
});
if (sstFileNames != null && sstFileNames.length > 0) {
try {
this.db.compactRange(true, 1, 0);
} catch (final RocksDBException e) {
throw new ProcessorStateException("Error while range compacting during restoring store " + this.name, e);
}
// we need to re-open with the old num.levels again, this is a workaround
// until https://github.com/facebook/rocksdb/pull/2740 is merged in rocksdb
close();
openDB(internalProcessorContext);
}
}
close();
this.prepareForBulkload = prepareForBulkload;
openDB(internalProcessorContext);
}
Aggregations