use of org.apache.kafka.streams.errors.LockException in project kafka by apache.
the class ProcessorStateManagerTest method shouldThrowLockExceptionIfFailedToLockStateDirectory.
@Test
public void shouldThrowLockExceptionIfFailedToLockStateDirectory() throws Exception {
final File taskDirectory = stateDirectory.directoryForTask(taskId);
final FileChannel channel = FileChannel.open(new File(taskDirectory, StateDirectory.LOCK_FILE_NAME).toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
// lock the task directory
final FileLock lock = channel.lock();
try {
new ProcessorStateManager(taskId, noPartitions, false, stateDirectory, Collections.<String, String>emptyMap(), changelogReader);
fail("Should have thrown LockException");
} catch (final LockException e) {
// pass
} finally {
lock.release();
channel.close();
}
}
use of org.apache.kafka.streams.errors.LockException in project kafka by apache.
the class GlobalStateManagerImpl method initialize.
@Override
public Set<String> initialize(final InternalProcessorContext processorContext) {
try {
if (!stateDirectory.lockGlobalState(MAX_LOCK_ATTEMPTS)) {
throw new LockException(String.format("Failed to lock the global state directory: %s", baseDir));
}
} catch (IOException e) {
throw new LockException(String.format("Failed to lock the global state directory: %s", baseDir));
}
try {
this.checkpointableOffsets.putAll(checkpoint.read());
} catch (IOException e) {
try {
stateDirectory.unlockGlobalState();
} catch (IOException e1) {
log.error("failed to unlock the global state directory", e);
}
throw new StreamsException("Failed to read checkpoints for global state stores", e);
}
final List<StateStore> stateStores = topology.globalStateStores();
for (final StateStore stateStore : stateStores) {
globalStoreNames.add(stateStore.name());
stateStore.init(processorContext, stateStore);
}
return Collections.unmodifiableSet(globalStoreNames);
}
Aggregations