Search in sources :

Example 1 with RelativeFileStateHandle

use of org.apache.flink.runtime.state.filesystem.RelativeFileStateHandle in project flink by apache.

the class MetadataV2V3SerializerBase method serializeStreamStateHandle.

// ------------------------------------------------------------------------
// low-level state handles
// ------------------------------------------------------------------------
static void serializeStreamStateHandle(StreamStateHandle stateHandle, DataOutputStream dos) throws IOException {
    if (stateHandle == null) {
        dos.writeByte(NULL_HANDLE);
    } else if (stateHandle instanceof RelativeFileStateHandle) {
        dos.writeByte(RELATIVE_STREAM_STATE_HANDLE);
        RelativeFileStateHandle relativeFileStateHandle = (RelativeFileStateHandle) stateHandle;
        dos.writeUTF(relativeFileStateHandle.getRelativePath());
        dos.writeLong(relativeFileStateHandle.getStateSize());
    } else if (stateHandle instanceof FileStateHandle) {
        dos.writeByte(FILE_STREAM_STATE_HANDLE);
        FileStateHandle fileStateHandle = (FileStateHandle) stateHandle;
        dos.writeLong(stateHandle.getStateSize());
        dos.writeUTF(fileStateHandle.getFilePath().toString());
    } else if (stateHandle instanceof ByteStreamStateHandle) {
        dos.writeByte(BYTE_STREAM_STATE_HANDLE);
        ByteStreamStateHandle byteStreamStateHandle = (ByteStreamStateHandle) stateHandle;
        dos.writeUTF(byteStreamStateHandle.getHandleName());
        byte[] internalData = byteStreamStateHandle.getData();
        dos.writeInt(internalData.length);
        dos.write(byteStreamStateHandle.getData());
    } else if (stateHandle instanceof KeyGroupsStateHandle) {
        KeyGroupsStateHandle keyGroupsStateHandle = (KeyGroupsStateHandle) stateHandle;
        dos.writeByte(KEY_GROUPS_HANDLE);
        dos.writeInt(keyGroupsStateHandle.getKeyGroupRange().getStartKeyGroup());
        dos.writeInt(keyGroupsStateHandle.getKeyGroupRange().getNumberOfKeyGroups());
        for (int keyGroup : keyGroupsStateHandle.getKeyGroupRange()) {
            dos.writeLong(keyGroupsStateHandle.getOffsetForKeyGroup(keyGroup));
        }
        serializeStreamStateHandle(keyGroupsStateHandle.getDelegateStateHandle(), dos);
    } else {
        throw new IOException("Unknown implementation of StreamStateHandle: " + stateHandle.getClass());
    }
}
Also used : RelativeFileStateHandle(org.apache.flink.runtime.state.filesystem.RelativeFileStateHandle) RelativeFileStateHandle(org.apache.flink.runtime.state.filesystem.RelativeFileStateHandle) FileStateHandle(org.apache.flink.runtime.state.filesystem.FileStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) IOException(java.io.IOException) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle)

Example 2 with RelativeFileStateHandle

use of org.apache.flink.runtime.state.filesystem.RelativeFileStateHandle in project flink by apache.

the class MetadataV2V3SerializerBase method deserializeStreamStateHandle.

@Nullable
static StreamStateHandle deserializeStreamStateHandle(DataInputStream dis, @Nullable DeserializationContext context) throws IOException {
    final int type = dis.read();
    if (NULL_HANDLE == type) {
        return null;
    } else if (FILE_STREAM_STATE_HANDLE == type) {
        long size = dis.readLong();
        String pathString = dis.readUTF();
        return new FileStateHandle(new Path(pathString), size);
    } else if (BYTE_STREAM_STATE_HANDLE == type) {
        String handleName = dis.readUTF();
        int numBytes = dis.readInt();
        byte[] data = new byte[numBytes];
        dis.readFully(data);
        return new ByteStreamStateHandle(handleName, data);
    } else if (RELATIVE_STREAM_STATE_HANDLE == type) {
        if (context == null) {
            throw new IOException("Cannot deserialize a RelativeFileStateHandle without a context to make it relative to.");
        }
        String relativePath = dis.readUTF();
        long size = dis.readLong();
        Path statePath = new Path(context.getExclusiveDirPath(), relativePath);
        return new RelativeFileStateHandle(statePath, relativePath, size);
    } else if (KEY_GROUPS_HANDLE == type) {
        int startKeyGroup = dis.readInt();
        int numKeyGroups = dis.readInt();
        KeyGroupRange keyGroupRange = KeyGroupRange.of(startKeyGroup, startKeyGroup + numKeyGroups - 1);
        long[] offsets = new long[numKeyGroups];
        for (int i = 0; i < numKeyGroups; ++i) {
            offsets[i] = dis.readLong();
        }
        KeyGroupRangeOffsets keyGroupRangeOffsets = new KeyGroupRangeOffsets(keyGroupRange, offsets);
        StreamStateHandle stateHandle = deserializeStreamStateHandle(dis, context);
        return new KeyGroupsStateHandle(keyGroupRangeOffsets, stateHandle);
    } else {
        throw new IOException("Unknown implementation of StreamStateHandle, code: " + type);
    }
}
Also used : Path(org.apache.flink.core.fs.Path) KeyGroupRangeOffsets(org.apache.flink.runtime.state.KeyGroupRangeOffsets) RelativeFileStateHandle(org.apache.flink.runtime.state.filesystem.RelativeFileStateHandle) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) RelativeFileStateHandle(org.apache.flink.runtime.state.filesystem.RelativeFileStateHandle) FileStateHandle(org.apache.flink.runtime.state.filesystem.FileStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) IOException(java.io.IOException) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle) OperatorStreamStateHandle(org.apache.flink.runtime.state.OperatorStreamStateHandle) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) Nullable(javax.annotation.Nullable)

Example 3 with RelativeFileStateHandle

use of org.apache.flink.runtime.state.filesystem.RelativeFileStateHandle in project flink by apache.

the class CheckpointTestUtils method createDummyStreamStateHandle.

public static StreamStateHandle createDummyStreamStateHandle(Random rnd, @Nullable String basePath) {
    if (!isSavepoint(basePath)) {
        return new ByteStreamStateHandle(String.valueOf(createRandomUUID(rnd)), String.valueOf(createRandomUUID(rnd)).getBytes(ConfigConstants.DEFAULT_CHARSET));
    } else {
        long stateSize = rnd.nextLong();
        if (stateSize <= 0) {
            stateSize = -stateSize;
        }
        String relativePath = String.valueOf(createRandomUUID(rnd));
        Path statePath = new Path(basePath, relativePath);
        return new RelativeFileStateHandle(statePath, relativePath, stateSize);
    }
}
Also used : Path(org.apache.flink.core.fs.Path) RelativeFileStateHandle(org.apache.flink.runtime.state.filesystem.RelativeFileStateHandle) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle)

Aggregations

RelativeFileStateHandle (org.apache.flink.runtime.state.filesystem.RelativeFileStateHandle)3 ByteStreamStateHandle (org.apache.flink.runtime.state.memory.ByteStreamStateHandle)3 IOException (java.io.IOException)2 Path (org.apache.flink.core.fs.Path)2 KeyGroupsStateHandle (org.apache.flink.runtime.state.KeyGroupsStateHandle)2 FileStateHandle (org.apache.flink.runtime.state.filesystem.FileStateHandle)2 Nullable (javax.annotation.Nullable)1 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)1 KeyGroupRangeOffsets (org.apache.flink.runtime.state.KeyGroupRangeOffsets)1 OperatorStreamStateHandle (org.apache.flink.runtime.state.OperatorStreamStateHandle)1 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)1