Java Code Examples for org.apache.flink.runtime.checkpoint.Checkpoints#loadCheckpointMetadata()

The following examples show how to use org.apache.flink.runtime.checkpoint.Checkpoints#loadCheckpointMetadata() . 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: BravoTestPipeline.java    From bravo with Apache License 2.0 6 votes vote down vote up
public static Savepoint loadSavepoint(String checkpointPointer) {
	try {
		Method resolveCheckpointPointer = AbstractFsCheckpointStorage.class.getDeclaredMethod(
				"resolveCheckpointPointer",
				String.class);
		resolveCheckpointPointer.setAccessible(true);
		CompletedCheckpointStorageLocation loc = (CompletedCheckpointStorageLocation) resolveCheckpointPointer
				.invoke(null, checkpointPointer);

		return Checkpoints.loadCheckpointMetadata(new DataInputStream(loc.getMetadataHandle().openInputStream()),
				BravoTestPipeline.class.getClassLoader());
	} catch (Exception e) {
		throw new RuntimeException(e);
	}

}
 
Example 2
Source File: StateMetadataUtils.java    From bravo with Apache License 2.0 6 votes vote down vote up
/**
 * Load the Savepoint metadata object from the given path
 */
public static Savepoint loadSavepoint(String checkpointPointer) throws IOException {
	try {
		Method resolveCheckpointPointer = AbstractFsCheckpointStorage.class.getDeclaredMethod(
				"resolveCheckpointPointer",
				String.class);
		resolveCheckpointPointer.setAccessible(true);
		CompletedCheckpointStorageLocation loc = (CompletedCheckpointStorageLocation) resolveCheckpointPointer
				.invoke(null, checkpointPointer);

		return Checkpoints.loadCheckpointMetadata(new DataInputStream(loc.getMetadataHandle().openInputStream()),
				StateMetadataUtils.class.getClassLoader());
	} catch (Exception e) {
		throw new RuntimeException(e);
	}

}
 
Example 3
Source File: MetadataSerializer.java    From flink-learning with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    //  读取元数据文件
    File f = new File("flink-learning-state/src/main/resources/_metadata");
    // 第二步,建立管道,FileInputStream文件输入流类用于读文件
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    DataInputStream dis = new DataInputStream(bis);

    // 通过 Flink 的 Checkpoints 类解析元数据文件
    Savepoint savepoint = Checkpoints.loadCheckpointMetadata(dis,
            MetadataSerializer.class.getClassLoader());
    // 打印当前的 CheckpointId
    System.out.println(savepoint.getCheckpointId());

    // 遍历 OperatorState,这里的每个 OperatorState 对应一个 Flink 任务的 Operator 算子
    // 不要与 OperatorState  和 KeyedState 混淆,不是一个层级的概念
    for (OperatorState operatorState : savepoint.getOperatorStates()) {
        System.out.println(operatorState);
        // 当前算子的状态大小为 0 ,表示算子不带状态,直接退出
        if (operatorState.getStateSize() == 0) {
            continue;
        }

        // 遍历当前算子的所有 subtask
        for (OperatorSubtaskState operatorSubtaskState : operatorState.getStates()) {
            // 解析 operatorSubtaskState 的 ManagedKeyedState
            parseManagedKeyedState(operatorSubtaskState);
            // 解析 operatorSubtaskState 的 ManagedOperatorState
            parseManagedOperatorState(operatorSubtaskState);
        }
    }
}
 
Example 4
Source File: MetadataSerializer.java    From flink-learning with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    //  读取元数据文件
    File f = new File("flink-learning-state/src/main/resources/_metadata");
    // 第二步,建立管道,FileInputStream文件输入流类用于读文件
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    DataInputStream dis = new DataInputStream(bis);

    // 通过 Flink 的 Checkpoints 类解析元数据文件
    Savepoint savepoint = Checkpoints.loadCheckpointMetadata(dis,
            MetadataSerializer.class.getClassLoader());
    // 打印当前的 CheckpointId
    System.out.println(savepoint.getCheckpointId());

    // 遍历 OperatorState,这里的每个 OperatorState 对应一个 Flink 任务的 Operator 算子
    // 不要与 OperatorState  和 KeyedState 混淆,不是一个层级的概念
    for (OperatorState operatorState : savepoint.getOperatorStates()) {
        System.out.println(operatorState);
        // 当前算子的状态大小为 0 ,表示算子不带状态,直接退出
        if (operatorState.getStateSize() == 0) {
            continue;
        }

        // 遍历当前算子的所有 subtask
        for (OperatorSubtaskState operatorSubtaskState : operatorState.getStates()) {
            // 解析 operatorSubtaskState 的 ManagedKeyedState
            parseManagedKeyedState(operatorSubtaskState);
            // 解析 operatorSubtaskState 的 ManagedOperatorState
            parseManagedOperatorState(operatorSubtaskState);
        }
    }
}
 
Example 5
Source File: SavepointLoader.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Takes the given string (representing a pointer to a checkpoint) and resolves it to a file
 * status for the checkpoint's metadata file.
 *
 *<p>This should only be used when the user code class loader is the current classloader for
 * the thread.
 * @param savepointPath The path to an external savepoint.
 * @return A state handle to savepoint's metadata.
 * @throws IOException Thrown, if the path cannot be resolved, the file system not accessed, or
 *     the path points to a location that does not seem to be a savepoint.
 */
public static Savepoint loadSavepoint(String savepointPath) throws IOException {
	CompletedCheckpointStorageLocation location = AbstractFsCheckpointStorage
		.resolveCheckpointPointer(savepointPath);

	try (DataInputStream stream = new DataInputStream(location.getMetadataHandle().openInputStream())) {
		return Checkpoints.loadCheckpointMetadata(stream, Thread.currentThread().getContextClassLoader());
	}
}
 
Example 6
Source File: SavepointLoader.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Takes the given string (representing a pointer to a checkpoint) and resolves it to a file
 * status for the checkpoint's metadata file.
 *
 *<p>This should only be used when the user code class loader is the current classloader for
 * the thread.
 * @param savepointPath The path to an external savepoint.
 * @return A state handle to savepoint's metadata.
 * @throws IOException Thrown, if the path cannot be resolved, the file system not accessed, or
 *     the path points to a location that does not seem to be a savepoint.
 */
public static CheckpointMetadata loadSavepointMetadata(String savepointPath) throws IOException {
	CompletedCheckpointStorageLocation location = AbstractFsCheckpointStorage
		.resolveCheckpointPointer(savepointPath);

	try (DataInputStream stream = new DataInputStream(location.getMetadataHandle().openInputStream())) {
		return Checkpoints.loadCheckpointMetadata(stream, Thread.currentThread().getContextClassLoader(), savepointPath);
	}
}