org.apache.flink.runtime.state.SnapshotDirectory Java Examples

The following examples show how to use org.apache.flink.runtime.state.SnapshotDirectory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RocksIncrementalSnapshotStrategy.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected RunnableFuture<SnapshotResult<KeyedStateHandle>> doSnapshot(
	long checkpointId,
	long checkpointTimestamp,
	@Nonnull CheckpointStreamFactory checkpointStreamFactory,
	@Nonnull CheckpointOptions checkpointOptions) throws Exception {

	final SnapshotDirectory snapshotDirectory = prepareLocalSnapshotDirectory(checkpointId);
	LOG.trace("Local RocksDB checkpoint goes to backup path {}.", snapshotDirectory);

	final List<StateMetaInfoSnapshot> stateMetaInfoSnapshots = new ArrayList<>(kvStateInformation.size());
	final Set<StateHandleID> baseSstFiles = snapshotMetaData(checkpointId, stateMetaInfoSnapshots);

	takeDBNativeCheckpoint(snapshotDirectory);

	final RocksDBIncrementalSnapshotOperation snapshotOperation =
		new RocksDBIncrementalSnapshotOperation(
			checkpointId,
			checkpointStreamFactory,
			snapshotDirectory,
			baseSstFiles,
			stateMetaInfoSnapshots);

	return snapshotOperation.toAsyncSnapshotFutureTask(cancelStreamRegistry);
}
 
Example #2
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected RunnableFuture<SnapshotResult<KeyedStateHandle>> doSnapshot(
	long checkpointId,
	long checkpointTimestamp,
	@Nonnull CheckpointStreamFactory checkpointStreamFactory,
	@Nonnull CheckpointOptions checkpointOptions) throws Exception {

	final SnapshotDirectory snapshotDirectory = prepareLocalSnapshotDirectory(checkpointId);
	LOG.trace("Local RocksDB checkpoint goes to backup path {}.", snapshotDirectory);

	final List<StateMetaInfoSnapshot> stateMetaInfoSnapshots = new ArrayList<>(kvStateInformation.size());
	final Set<StateHandleID> baseSstFiles = snapshotMetaData(checkpointId, stateMetaInfoSnapshots);

	takeDBNativeCheckpoint(snapshotDirectory);

	final RocksDBIncrementalSnapshotOperation snapshotOperation =
		new RocksDBIncrementalSnapshotOperation(
			checkpointId,
			checkpointStreamFactory,
			snapshotDirectory,
			baseSstFiles,
			stateMetaInfoSnapshots);

	return snapshotOperation.toAsyncSnapshotFutureTask(cancelStreamRegistry);
}
 
Example #3
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected RunnableFuture<SnapshotResult<KeyedStateHandle>> doSnapshot(
	long checkpointId,
	long checkpointTimestamp,
	@Nonnull CheckpointStreamFactory checkpointStreamFactory,
	@Nonnull CheckpointOptions checkpointOptions) throws Exception {

	final SnapshotDirectory snapshotDirectory = prepareLocalSnapshotDirectory(checkpointId);
	LOG.trace("Local RocksDB checkpoint goes to backup path {}.", snapshotDirectory);

	final List<StateMetaInfoSnapshot> stateMetaInfoSnapshots = new ArrayList<>(kvStateInformation.size());
	final Set<StateHandleID> baseSstFiles = snapshotMetaData(checkpointId, stateMetaInfoSnapshots);

	takeDBNativeCheckpoint(snapshotDirectory);

	final RocksDBIncrementalSnapshotOperation snapshotOperation =
		new RocksDBIncrementalSnapshotOperation(
			checkpointId,
			checkpointStreamFactory,
			snapshotDirectory,
			baseSstFiles,
			stateMetaInfoSnapshots);

	return snapshotOperation.toAsyncSnapshotFutureTask(cancelStreamRegistry);
}
 
Example #4
Source File: RocksIncrementalSnapshotStrategy.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Nonnull
private SnapshotDirectory prepareLocalSnapshotDirectory(long checkpointId) throws IOException {

	if (localRecoveryConfig.isLocalRecoveryEnabled()) {
		// create a "permanent" snapshot directory for local recovery.
		LocalRecoveryDirectoryProvider directoryProvider = localRecoveryConfig.getLocalStateDirectoryProvider();
		File directory = directoryProvider.subtaskSpecificCheckpointDirectory(checkpointId);

		if (!directory.exists() && !directory.mkdirs()) {
			throw new IOException("Local state base directory for checkpoint " + checkpointId +
				" already exists: " + directory);
		}

		// introduces an extra directory because RocksDB wants a non-existing directory for native checkpoints.
		// append localDirectoryName here to solve directory collision problem when two stateful operators chained in one task.
		File rdbSnapshotDir = new File(directory, localDirectoryName);
		if (rdbSnapshotDir.exists()) {
			FileUtils.deleteDirectory(rdbSnapshotDir);
		}

		Path path = new Path(rdbSnapshotDir.toURI());
		// create a "permanent" snapshot directory because local recovery is active.
		try {
			return SnapshotDirectory.permanent(path);
		} catch (IOException ex) {
			try {
				FileUtils.deleteDirectory(directory);
			} catch (IOException delEx) {
				ex = ExceptionUtils.firstOrSuppressed(delEx, ex);
			}
			throw ex;
		}
	} else {
		// create a "temporary" snapshot directory because local recovery is inactive.
		File snapshotDir = new File(instanceBasePath, "chk-" + checkpointId);
		return SnapshotDirectory.temporary(snapshotDir);
	}
}
 
Example #5
Source File: RocksIncrementalSnapshotStrategy.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void takeDBNativeCheckpoint(@Nonnull SnapshotDirectory outputDirectory) throws Exception {
	// create hard links of living files in the output path
	try (
		ResourceGuard.Lease ignored = rocksDBResourceGuard.acquireResource();
		Checkpoint checkpoint = Checkpoint.create(db)) {
		checkpoint.createCheckpoint(outputDirectory.getDirectory().getPath());
	} catch (Exception ex) {
		try {
			outputDirectory.cleanup();
		} catch (IOException cleanupEx) {
			ex = ExceptionUtils.firstOrSuppressed(cleanupEx, ex);
		}
		throw ex;
	}
}
 
Example #6
Source File: RocksIncrementalSnapshotStrategy.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private RocksDBIncrementalSnapshotOperation(
	long checkpointId,
	@Nonnull CheckpointStreamFactory checkpointStreamFactory,
	@Nonnull SnapshotDirectory localBackupDirectory,
	@Nullable Set<StateHandleID> baseSstFiles,
	@Nonnull List<StateMetaInfoSnapshot> stateMetaInfoSnapshots) {

	this.checkpointStreamFactory = checkpointStreamFactory;
	this.baseSstFiles = baseSstFiles;
	this.checkpointId = checkpointId;
	this.localBackupDirectory = localBackupDirectory;
	this.stateMetaInfoSnapshots = stateMetaInfoSnapshots;
}
 
Example #7
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
private SnapshotDirectory prepareLocalSnapshotDirectory(long checkpointId) throws IOException {

	if (localRecoveryConfig.isLocalRecoveryEnabled()) {
		// create a "permanent" snapshot directory for local recovery.
		LocalRecoveryDirectoryProvider directoryProvider = localRecoveryConfig.getLocalStateDirectoryProvider();
		File directory = directoryProvider.subtaskSpecificCheckpointDirectory(checkpointId);

		if (!directory.exists() && !directory.mkdirs()) {
			throw new IOException("Local state base directory for checkpoint " + checkpointId +
				" already exists: " + directory);
		}

		// introduces an extra directory because RocksDB wants a non-existing directory for native checkpoints.
		// append localDirectoryName here to solve directory collision problem when two stateful operators chained in one task.
		File rdbSnapshotDir = new File(directory, localDirectoryName);
		if (rdbSnapshotDir.exists()) {
			FileUtils.deleteDirectory(rdbSnapshotDir);
		}

		Path path = new Path(rdbSnapshotDir.toURI());
		// create a "permanent" snapshot directory because local recovery is active.
		try {
			return SnapshotDirectory.permanent(path);
		} catch (IOException ex) {
			try {
				FileUtils.deleteDirectory(directory);
			} catch (IOException delEx) {
				ex = ExceptionUtils.firstOrSuppressed(delEx, ex);
			}
			throw ex;
		}
	} else {
		// create a "temporary" snapshot directory because local recovery is inactive.
		File snapshotDir = new File(instanceBasePath, "chk-" + checkpointId);
		return SnapshotDirectory.temporary(snapshotDir);
	}
}
 
Example #8
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
private void takeDBNativeCheckpoint(@Nonnull SnapshotDirectory outputDirectory) throws Exception {
	// create hard links of living files in the output path
	try (
		ResourceGuard.Lease ignored = rocksDBResourceGuard.acquireResource();
		Checkpoint checkpoint = Checkpoint.create(db)) {
		checkpoint.createCheckpoint(outputDirectory.getDirectory().getPath());
	} catch (Exception ex) {
		try {
			outputDirectory.cleanup();
		} catch (IOException cleanupEx) {
			ex = ExceptionUtils.firstOrSuppressed(cleanupEx, ex);
		}
		throw ex;
	}
}
 
Example #9
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
private RocksDBIncrementalSnapshotOperation(
	long checkpointId,
	@Nonnull CheckpointStreamFactory checkpointStreamFactory,
	@Nonnull SnapshotDirectory localBackupDirectory,
	@Nullable Set<StateHandleID> baseSstFiles,
	@Nonnull List<StateMetaInfoSnapshot> stateMetaInfoSnapshots) {

	this.checkpointStreamFactory = checkpointStreamFactory;
	this.baseSstFiles = baseSstFiles;
	this.checkpointId = checkpointId;
	this.localBackupDirectory = localBackupDirectory;
	this.stateMetaInfoSnapshots = stateMetaInfoSnapshots;
}
 
Example #10
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
private SnapshotDirectory prepareLocalSnapshotDirectory(long checkpointId) throws IOException {

	if (localRecoveryConfig.isLocalRecoveryEnabled()) {
		// create a "permanent" snapshot directory for local recovery.
		LocalRecoveryDirectoryProvider directoryProvider = localRecoveryConfig.getLocalStateDirectoryProvider();
		File directory = directoryProvider.subtaskSpecificCheckpointDirectory(checkpointId);

		if (!directory.exists() && !directory.mkdirs()) {
			throw new IOException("Local state base directory for checkpoint " + checkpointId +
				" does not exist and could not be created: " + directory);
		}

		// introduces an extra directory because RocksDB wants a non-existing directory for native checkpoints.
		// append localDirectoryName here to solve directory collision problem when two stateful operators chained in one task.
		File rdbSnapshotDir = new File(directory, localDirectoryName);
		if (rdbSnapshotDir.exists()) {
			FileUtils.deleteDirectory(rdbSnapshotDir);
		}

		Path path = rdbSnapshotDir.toPath();
		// create a "permanent" snapshot directory because local recovery is active.
		try {
			return SnapshotDirectory.permanent(path);
		} catch (IOException ex) {
			try {
				FileUtils.deleteDirectory(directory);
			} catch (IOException delEx) {
				ex = ExceptionUtils.firstOrSuppressed(delEx, ex);
			}
			throw ex;
		}
	} else {
		// create a "temporary" snapshot directory because local recovery is inactive.
		File snapshotDir = new File(instanceBasePath, "chk-" + checkpointId);
		return SnapshotDirectory.temporary(snapshotDir);
	}
}
 
Example #11
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
private void takeDBNativeCheckpoint(@Nonnull SnapshotDirectory outputDirectory) throws Exception {
	// create hard links of living files in the output path
	try (
		ResourceGuard.Lease ignored = rocksDBResourceGuard.acquireResource();
		Checkpoint checkpoint = Checkpoint.create(db)) {
		checkpoint.createCheckpoint(outputDirectory.getDirectory().toString());
	} catch (Exception ex) {
		try {
			outputDirectory.cleanup();
		} catch (IOException cleanupEx) {
			ex = ExceptionUtils.firstOrSuppressed(cleanupEx, ex);
		}
		throw ex;
	}
}
 
Example #12
Source File: RocksIncrementalSnapshotStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
private RocksDBIncrementalSnapshotOperation(
	long checkpointId,
	@Nonnull CheckpointStreamFactory checkpointStreamFactory,
	@Nonnull SnapshotDirectory localBackupDirectory,
	@Nullable Set<StateHandleID> baseSstFiles,
	@Nonnull List<StateMetaInfoSnapshot> stateMetaInfoSnapshots) {

	this.checkpointStreamFactory = checkpointStreamFactory;
	this.baseSstFiles = baseSstFiles;
	this.checkpointId = checkpointId;
	this.localBackupDirectory = localBackupDirectory;
	this.stateMetaInfoSnapshots = stateMetaInfoSnapshots;
}