Search in sources :

Example 21 with StateMetaInfoSnapshot

use of org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot in project flink by apache.

the class KeyedBackendSerializationProxy method read.

@SuppressWarnings("unchecked")
@Override
public void read(DataInputView in) throws IOException {
    super.read(in);
    final int readVersion = getReadVersion();
    if (readVersion >= 4) {
        usingKeyGroupCompression = in.readBoolean();
    } else {
        usingKeyGroupCompression = false;
    }
    // only starting from version 3, we have the key serializer and its config snapshot written
    if (readVersion >= 6) {
        this.keySerializerSnapshot = TypeSerializerSnapshotSerializationUtil.readSerializerSnapshot(in, userCodeClassLoader, null);
    } else if (readVersion >= 3) {
        Tuple2<TypeSerializer<?>, TypeSerializerSnapshot<?>> keySerializerAndConfig = TypeSerializerSerializationUtil.readSerializersAndConfigsWithResilience(in, userCodeClassLoader).get(0);
        this.keySerializerSnapshot = (TypeSerializerSnapshot<K>) keySerializerAndConfig.f1;
    } else {
        this.keySerializerSnapshot = new BackwardsCompatibleSerializerSnapshot<>(TypeSerializerSerializationUtil.tryReadSerializer(in, userCodeClassLoader, true));
    }
    this.keySerializer = null;
    Integer metaInfoSnapshotVersion = META_INFO_SNAPSHOT_FORMAT_VERSION_MAPPER.get(readVersion);
    if (metaInfoSnapshotVersion == null) {
        // this should not happen; guard for the future
        throw new IOException("Cannot determine corresponding meta info snapshot version for keyed backend serialization readVersion=" + readVersion);
    }
    final StateMetaInfoReader stateMetaInfoReader = StateMetaInfoSnapshotReadersWriters.getReader(metaInfoSnapshotVersion, StateMetaInfoSnapshotReadersWriters.StateTypeHint.KEYED_STATE);
    int numKvStates = in.readShort();
    stateMetaInfoSnapshots = new ArrayList<>(numKvStates);
    for (int i = 0; i < numKvStates; i++) {
        StateMetaInfoSnapshot snapshot = stateMetaInfoReader.readStateMetaInfoSnapshot(in, userCodeClassLoader);
        stateMetaInfoSnapshots.add(snapshot);
    }
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) StateMetaInfoSnapshot(org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot) TypeSerializerSnapshot(org.apache.flink.api.common.typeutils.TypeSerializerSnapshot) IOException(java.io.IOException) StateMetaInfoReader(org.apache.flink.runtime.state.metainfo.StateMetaInfoReader) BackwardsCompatibleSerializerSnapshot(org.apache.flink.api.common.typeutils.BackwardsCompatibleSerializerSnapshot)

Example 22 with StateMetaInfoSnapshot

use of org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot in project flink by apache.

the class KeyedBackendSerializationProxy method write.

@Override
public void write(DataOutputView out) throws IOException {
    super.write(out);
    // write the compression format used to write each key-group
    out.writeBoolean(usingKeyGroupCompression);
    TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot(out, keySerializerSnapshot, keySerializer);
    // write individual registered keyed state metainfos
    out.writeShort(stateMetaInfoSnapshots.size());
    for (StateMetaInfoSnapshot metaInfoSnapshot : stateMetaInfoSnapshots) {
        StateMetaInfoSnapshotReadersWriters.getWriter().writeStateMetaInfoSnapshot(metaInfoSnapshot, out);
    }
}
Also used : StateMetaInfoSnapshot(org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot)

Example 23 with StateMetaInfoSnapshot

use of org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot in project flink by apache.

the class ChangelogBackendLogApplier method applyMetaDataChange.

private static void applyMetaDataChange(DataInputView in, ChangelogKeyedStateBackend<?> backend, ClassLoader classLoader, Map<Short, StateID> stateIds) throws Exception {
    StateMetaInfoSnapshot snapshot = readStateMetaInfoSnapshot(in, classLoader);
    RegisteredStateMetaInfoBase meta;
    switch(snapshot.getBackendStateType()) {
        case KEY_VALUE:
            meta = restoreKvMetaData(backend, snapshot, in);
            break;
        case PRIORITY_QUEUE:
            meta = restorePqMetaData(backend, snapshot);
            break;
        default:
            throw new RuntimeException("Unsupported state type: " + snapshot.getBackendStateType() + ", sate: " + snapshot.getName());
    }
    stateIds.put(in.readShort(), new StateID(meta.getName(), BackendStateType.byCode(in.readByte())));
}
Also used : RegisteredStateMetaInfoBase(org.apache.flink.runtime.state.RegisteredStateMetaInfoBase) StateMetaInfoSnapshot(org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot)

Aggregations

StateMetaInfoSnapshot (org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot)23 DataInputViewStreamWrapper (org.apache.flink.core.memory.DataInputViewStreamWrapper)8 ArrayList (java.util.ArrayList)7 DataOutputViewStreamWrapper (org.apache.flink.core.memory.DataOutputViewStreamWrapper)7 ByteArrayInputStreamWithPos (org.apache.flink.core.memory.ByteArrayInputStreamWithPos)5 ByteArrayOutputStreamWithPos (org.apache.flink.core.memory.ByteArrayOutputStreamWithPos)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 Map (java.util.Map)3 StateMetaInfoReader (org.apache.flink.runtime.state.metainfo.StateMetaInfoReader)3 KeyGroup (org.apache.flink.runtime.state.restore.KeyGroup)3 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)3 List (java.util.List)2 Nonnull (javax.annotation.Nonnull)2 RocksDbKvStateInfo (org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend.RocksDbKvStateInfo)2 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)2 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)2 KeyGroupsStateHandle (org.apache.flink.runtime.state.KeyGroupsStateHandle)2 KeyedBackendSerializationProxy (org.apache.flink.runtime.state.KeyedBackendSerializationProxy)2