Java Code Examples for org.apache.flink.runtime.state.CheckpointStorageLocationReference#isDefaultReference()

The following examples show how to use org.apache.flink.runtime.state.CheckpointStorageLocationReference#isDefaultReference() . 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: AbstractFsCheckpointStorage.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Decodes the given reference into a path. This method validates that the reference bytes start with
 * the correct magic number (as written by {@link #encodePathAsReference(Path)}) and converts
 * the remaining bytes back to a proper path.
 *
 * @param reference The bytes representing the reference.
 * @return The path decoded from the reference.
 *
 * @throws IllegalArgumentException Thrown, if the bytes do not represent a proper reference.
 */
public static Path decodePathFromReference(CheckpointStorageLocationReference reference) {
	if (reference.isDefaultReference()) {
		throw new IllegalArgumentException("Cannot decode default reference");
	}

	final byte[] bytes = reference.getReferenceBytes();
	final int headerLen = REFERENCE_MAGIC_NUMBER.length;

	if (bytes.length > headerLen) {
		// compare magic number
		for (int i = 0; i < headerLen; i++) {
			if (bytes[i] != REFERENCE_MAGIC_NUMBER[i]) {
				throw new IllegalArgumentException("Reference starts with the wrong magic number");
			}
		}

		// covert to string and path
		try {
			return new Path(new String(bytes, headerLen, bytes.length - headerLen, StandardCharsets.UTF_8));
		}
		catch (Exception e) {
			throw new IllegalArgumentException("Reference cannot be decoded to a path", e);
		}
	}
	else {
		throw new IllegalArgumentException("Reference too short.");
	}
}
 
Example 2
Source File: FsCheckpointStorage.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public CheckpointStreamFactory resolveCheckpointStorageLocation(
		long checkpointId,
		CheckpointStorageLocationReference reference) throws IOException {

	if (reference.isDefaultReference()) {
		// default reference, construct the default location for that particular checkpoint
		final Path checkpointDir = createCheckpointDirectory(checkpointsDirectory, checkpointId);

		return new FsCheckpointStorageLocation(
				fileSystem,
				checkpointDir,
				sharedStateDirectory,
				taskOwnedStateDirectory,
				reference,
				fileSizeThreshold);
	}
	else {
		// location encoded in the reference
		final Path path = decodePathFromReference(reference);

		return new FsCheckpointStorageLocation(
				path.getFileSystem(),
				path,
				path,
				path,
				reference,
				fileSizeThreshold);
	}
}
 
Example 3
Source File: AbstractFsCheckpointStorage.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Decodes the given reference into a path. This method validates that the reference bytes start with
 * the correct magic number (as written by {@link #encodePathAsReference(Path)}) and converts
 * the remaining bytes back to a proper path.
 *
 * @param reference The bytes representing the reference.
 * @return The path decoded from the reference.
 *
 * @throws IllegalArgumentException Thrown, if the bytes do not represent a proper reference.
 */
public static Path decodePathFromReference(CheckpointStorageLocationReference reference) {
	if (reference.isDefaultReference()) {
		throw new IllegalArgumentException("Cannot decode default reference");
	}

	final byte[] bytes = reference.getReferenceBytes();
	final int headerLen = REFERENCE_MAGIC_NUMBER.length;

	if (bytes.length > headerLen) {
		// compare magic number
		for (int i = 0; i < headerLen; i++) {
			if (bytes[i] != REFERENCE_MAGIC_NUMBER[i]) {
				throw new IllegalArgumentException("Reference starts with the wrong magic number");
			}
		}

		// covert to string and path
		try {
			return new Path(new String(bytes, headerLen, bytes.length - headerLen, StandardCharsets.UTF_8));
		}
		catch (Exception e) {
			throw new IllegalArgumentException("Reference cannot be decoded to a path", e);
		}
	}
	else {
		throw new IllegalArgumentException("Reference too short.");
	}
}
 
Example 4
Source File: FsCheckpointStorage.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CheckpointStreamFactory resolveCheckpointStorageLocation(
		long checkpointId,
		CheckpointStorageLocationReference reference) throws IOException {

	if (reference.isDefaultReference()) {
		// default reference, construct the default location for that particular checkpoint
		final Path checkpointDir = createCheckpointDirectory(checkpointsDirectory, checkpointId);

		return new FsCheckpointStorageLocation(
				fileSystem,
				checkpointDir,
				sharedStateDirectory,
				taskOwnedStateDirectory,
				reference,
				fileSizeThreshold,
				writeBufferSize);
	}
	else {
		// location encoded in the reference
		final Path path = decodePathFromReference(reference);

		return new FsCheckpointStorageLocation(
				path.getFileSystem(),
				path,
				path,
				path,
				reference,
				fileSizeThreshold,
				writeBufferSize);
	}
}
 
Example 5
Source File: SylphFsCheckpointStorage.java    From sylph with Apache License 2.0 5 votes vote down vote up
@Override
public CheckpointStreamFactory resolveCheckpointStorageLocation(
        long checkpointId,
        CheckpointStorageLocationReference reference)
        throws IOException
{
    if (reference.isDefaultReference()) {
        // default reference, construct the default location for that particular checkpoint
        final Path checkpointDir = createCheckpointDirectory(checkpointsDirectory, checkpointId);

        return new FsCheckpointStorageLocation(
                fileSystem,
                checkpointDir,
                sharedStateDirectory,
                taskOwnedStateDirectory,
                reference,
                fileSizeThreshold,
                writeBufferSize);
    }
    else {
        // location encoded in the reference
        final Path path = decodePathFromReference(reference);

        return new FsCheckpointStorageLocation(
                path.getFileSystem(),
                path,
                path,
                path,
                reference,
                fileSizeThreshold,
                writeBufferSize);
    }
}
 
Example 6
Source File: AbstractFsCheckpointStorage.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Decodes the given reference into a path. This method validates that the reference bytes start with
 * the correct magic number (as written by {@link #encodePathAsReference(Path)}) and converts
 * the remaining bytes back to a proper path.
 *
 * @param reference The bytes representing the reference.
 * @return The path decoded from the reference.
 *
 * @throws IllegalArgumentException Thrown, if the bytes do not represent a proper reference.
 */
public static Path decodePathFromReference(CheckpointStorageLocationReference reference) {
	if (reference.isDefaultReference()) {
		throw new IllegalArgumentException("Cannot decode default reference");
	}

	final byte[] bytes = reference.getReferenceBytes();
	final int headerLen = REFERENCE_MAGIC_NUMBER.length;

	if (bytes.length > headerLen) {
		// compare magic number
		for (int i = 0; i < headerLen; i++) {
			if (bytes[i] != REFERENCE_MAGIC_NUMBER[i]) {
				throw new IllegalArgumentException("Reference starts with the wrong magic number");
			}
		}

		// covert to string and path
		try {
			return new Path(new String(bytes, headerLen, bytes.length - headerLen, StandardCharsets.UTF_8));
		}
		catch (Exception e) {
			throw new IllegalArgumentException("Reference cannot be decoded to a path", e);
		}
	}
	else {
		throw new IllegalArgumentException("Reference too short.");
	}
}
 
Example 7
Source File: FsCheckpointStorage.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CheckpointStreamFactory resolveCheckpointStorageLocation(
		long checkpointId,
		CheckpointStorageLocationReference reference) throws IOException {

	if (reference.isDefaultReference()) {
		// default reference, construct the default location for that particular checkpoint
		final Path checkpointDir = createCheckpointDirectory(checkpointsDirectory, checkpointId);

		return new FsCheckpointStorageLocation(
				fileSystem,
				checkpointDir,
				sharedStateDirectory,
				taskOwnedStateDirectory,
				reference,
				fileSizeThreshold,
				writeBufferSize);
	}
	else {
		// location encoded in the reference
		final Path path = decodePathFromReference(reference);

		return new FsCheckpointStorageLocation(
				path.getFileSystem(),
				path,
				path,
				path,
				reference,
				fileSizeThreshold,
				writeBufferSize);
	}
}