use of org.apache.kafka.streams.errors.ProcessorStateException in project apache-kafka-on-k8s by banzaicloud.
the class AbstractTask method closeStateManager.
/**
* @throws ProcessorStateException if there is an error while closing the state manager
* @param writeCheckpoint boolean indicating if a checkpoint file should be written
*/
// visible for testing
void closeStateManager(final boolean writeCheckpoint) throws ProcessorStateException {
ProcessorStateException exception = null;
log.trace("Closing state manager");
try {
stateMgr.close(writeCheckpoint ? recordCollectorOffsets() : null);
} catch (final ProcessorStateException e) {
exception = e;
} finally {
try {
stateDirectory.unlock(id);
} catch (IOException e) {
if (exception == null) {
exception = new ProcessorStateException(String.format("%sFailed to release state dir lock", logPrefix), e);
}
}
}
if (exception != null) {
throw exception;
}
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project apache-kafka-on-k8s by banzaicloud.
the class GlobalStateManagerImpl method flush.
@Override
public void flush() {
log.debug("Flushing all global globalStores registered in the state manager");
for (StateStore store : this.globalStores.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 apache-kafka-on-k8s by banzaicloud.
the class StateDirectory method lock.
/**
* Get the lock for the {@link TaskId}s directory if it is available
* @param taskId
* @return true if successful
* @throws IOException
*/
synchronized boolean lock(final TaskId taskId) throws IOException {
final File lockFile;
// we already have the lock so bail out here
final LockAndOwner lockAndOwner = locks.get(taskId);
if (lockAndOwner != null && lockAndOwner.owningThread.equals(Thread.currentThread().getName())) {
log.trace("{} Found cached state dir lock for task {}", logPrefix(), taskId);
return true;
} else if (lockAndOwner != null) {
// another thread owns the lock
return false;
}
try {
lockFile = new File(directoryForTask(taskId), LOCK_FILE_NAME);
} catch (ProcessorStateException e) {
// has concurrently deleted the directory
return false;
}
final FileChannel channel;
try {
channel = getOrCreateFileChannel(taskId, lockFile.toPath());
} catch (NoSuchFileException e) {
// file, in this case we will return immediately indicating locking failed.
return false;
}
final FileLock lock = tryLock(channel);
if (lock != null) {
locks.put(taskId, new LockAndOwner(Thread.currentThread().getName(), lock));
log.debug("{} Acquired state dir lock for task {}", logPrefix(), taskId);
}
return lock != null;
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class AbstractSegments method openExisting.
@Override
public void openExisting(final ProcessorContext context, final long streamTime) {
try {
final File dir = new File(context.stateDir(), name);
if (dir.exists()) {
final String[] list = dir.list();
if (list != null) {
Arrays.stream(list).map(segment -> segmentIdFromSegmentName(segment, dir)).sorted().filter(segmentId -> segmentId >= 0).forEach(segmentId -> 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 (final Exception ex) {
// ignore
}
final long minLiveSegment = segmentId(streamTime - retentionPeriod);
cleanupEarlierThan(minLiveSegment);
}
use of org.apache.kafka.streams.errors.ProcessorStateException in project kafka by apache.
the class AbstractRocksDBSegmentedBytesStore method restoreAllInternal.
// Visible for testing
void restoreAllInternal(final Collection<ConsumerRecord<byte[], byte[]>> records) {
try {
final Map<S, WriteBatch> writeBatchMap = getWriteBatches(records);
for (final Map.Entry<S, WriteBatch> entry : writeBatchMap.entrySet()) {
final S segment = entry.getKey();
final WriteBatch batch = entry.getValue();
segment.write(batch);
batch.close();
}
} catch (final RocksDBException e) {
throw new ProcessorStateException("Error restoring batch to store " + this.name, e);
}
}
Aggregations