Search in sources :

Example 1 with CopyRequest

use of org.apache.flink.core.fs.DuplicatingFileSystem.CopyRequest in project flink by apache.

the class FsCheckpointStateToolset method duplicate.

@Override
public List<StreamStateHandle> duplicate(List<StreamStateHandle> stateHandles) throws IOException {
    final List<CopyRequest> requests = new ArrayList<>();
    for (StreamStateHandle handle : stateHandles) {
        if (!(handle instanceof FileStateHandle)) {
            throw new IllegalArgumentException("We can duplicate only FileStateHandles.");
        }
        final Path srcPath = ((FileStateHandle) handle).getFilePath();
        requests.add(CopyRequest.of(srcPath, getNewDstPath(srcPath.getName())));
    }
    fs.duplicate(requests);
    return IntStream.range(0, stateHandles.size()).mapToObj(idx -> {
        final StreamStateHandle originalHandle = stateHandles.get(idx);
        final Path dst = requests.get(idx).getDestination();
        if (originalHandle instanceof RelativeFileStateHandle) {
            return new RelativeFileStateHandle(dst, dst.getName(), originalHandle.getStateSize());
        } else {
            return new FileStateHandle(dst, originalHandle.getStateSize());
        }
    }).collect(Collectors.toList());
}
Also used : Path(org.apache.flink.core.fs.Path) IntStream(java.util.stream.IntStream) List(java.util.List) CheckpointStateToolset(org.apache.flink.runtime.state.CheckpointStateToolset) Path(org.apache.flink.core.fs.Path) EntropyInjector(org.apache.flink.core.fs.EntropyInjector) DuplicatingFileSystem(org.apache.flink.core.fs.DuplicatingFileSystem) CopyRequest(org.apache.flink.core.fs.DuplicatingFileSystem.CopyRequest) IOException(java.io.IOException) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CopyRequest(org.apache.flink.core.fs.DuplicatingFileSystem.CopyRequest) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ArrayList(java.util.ArrayList)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 DuplicatingFileSystem (org.apache.flink.core.fs.DuplicatingFileSystem)1 CopyRequest (org.apache.flink.core.fs.DuplicatingFileSystem.CopyRequest)1 EntropyInjector (org.apache.flink.core.fs.EntropyInjector)1 Path (org.apache.flink.core.fs.Path)1 CheckpointStateToolset (org.apache.flink.runtime.state.CheckpointStateToolset)1 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)1