Search in sources :

Example 1 with StateSnapshotRestore

use of org.apache.flink.runtime.state.StateSnapshotRestore in project flink by apache.

the class HeapKeyedStateBackend method getKeys.

@SuppressWarnings("unchecked")
@Override
public <N> Stream<K> getKeys(String state, N namespace) {
    if (!registeredKVStates.containsKey(state)) {
        return Stream.empty();
    }
    final StateSnapshotRestore stateSnapshotRestore = registeredKVStates.get(state);
    StateTable<K, N, ?> table = (StateTable<K, N, ?>) stateSnapshotRestore;
    return table.getKeys(namespace);
}
Also used : StateSnapshotRestore(org.apache.flink.runtime.state.StateSnapshotRestore)

Example 2 with StateSnapshotRestore

use of org.apache.flink.runtime.state.StateSnapshotRestore in project flink by apache.

the class HeapMetaInfoRestoreOperation method createOrCheckStateForMetaInfo.

Map<Integer, StateMetaInfoSnapshot> createOrCheckStateForMetaInfo(List<StateMetaInfoSnapshot> restoredMetaInfo, Map<String, StateTable<K, ?, ?>> registeredKVStates, Map<String, HeapPriorityQueueSnapshotRestoreWrapper<?>> registeredPQStates) {
    final Map<Integer, StateMetaInfoSnapshot> kvStatesById = new HashMap<>();
    for (StateMetaInfoSnapshot metaInfoSnapshot : restoredMetaInfo) {
        final StateSnapshotRestore registeredState;
        switch(metaInfoSnapshot.getBackendStateType()) {
            case KEY_VALUE:
                registeredState = registeredKVStates.get(metaInfoSnapshot.getName());
                if (registeredState == null) {
                    RegisteredKeyValueStateBackendMetaInfo<?, ?> registeredKeyedBackendStateMetaInfo = new RegisteredKeyValueStateBackendMetaInfo<>(metaInfoSnapshot);
                    registeredKVStates.put(metaInfoSnapshot.getName(), stateTableFactory.newStateTable(keyContext, registeredKeyedBackendStateMetaInfo, keySerializerProvider.currentSchemaSerializer()));
                }
                break;
            case PRIORITY_QUEUE:
                registeredState = registeredPQStates.get(metaInfoSnapshot.getName());
                if (registeredState == null) {
                    registeredPQStates.put(metaInfoSnapshot.getName(), createInternal(new RegisteredPriorityQueueStateBackendMetaInfo<>(metaInfoSnapshot)));
                }
                break;
            default:
                throw new IllegalStateException("Unexpected state type: " + metaInfoSnapshot.getBackendStateType() + ".");
        }
        // always put metaInfo into kvStatesById, because kvStatesById is KeyGroupsStateHandle
        // related
        kvStatesById.put(kvStatesById.size(), metaInfoSnapshot);
    }
    return kvStatesById;
}
Also used : HashMap(java.util.HashMap) StateMetaInfoSnapshot(org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot) StateSnapshotRestore(org.apache.flink.runtime.state.StateSnapshotRestore) RegisteredKeyValueStateBackendMetaInfo(org.apache.flink.runtime.state.RegisteredKeyValueStateBackendMetaInfo) RegisteredPriorityQueueStateBackendMetaInfo(org.apache.flink.runtime.state.RegisteredPriorityQueueStateBackendMetaInfo)

Example 3 with StateSnapshotRestore

use of org.apache.flink.runtime.state.StateSnapshotRestore in project flink by apache.

the class HeapRestoreOperation method readKeyGroupStateData.

private void readKeyGroupStateData(InputStream inputStream, Map<Integer, StateMetaInfoSnapshot> kvStatesById, int keyGroupIndex, int numStates, int readVersion) throws IOException {
    DataInputViewStreamWrapper inView = new DataInputViewStreamWrapper(inputStream);
    for (int i = 0; i < numStates; i++) {
        final int kvStateId = inView.readShort();
        final StateMetaInfoSnapshot stateMetaInfoSnapshot = kvStatesById.get(kvStateId);
        final StateSnapshotRestore registeredState;
        switch(stateMetaInfoSnapshot.getBackendStateType()) {
            case KEY_VALUE:
                registeredState = registeredKVStates.get(stateMetaInfoSnapshot.getName());
                break;
            case PRIORITY_QUEUE:
                registeredState = registeredPQStates.get(stateMetaInfoSnapshot.getName());
                break;
            default:
                throw new IllegalStateException("Unexpected state type: " + stateMetaInfoSnapshot.getBackendStateType() + ".");
        }
        StateSnapshotKeyGroupReader keyGroupReader = registeredState.keyGroupReader(readVersion);
        keyGroupReader.readMappingsInKeyGroup(inView, keyGroupIndex);
    }
}
Also used : StateSnapshotKeyGroupReader(org.apache.flink.runtime.state.StateSnapshotKeyGroupReader) StateMetaInfoSnapshot(org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot) StateSnapshotRestore(org.apache.flink.runtime.state.StateSnapshotRestore) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper)

Example 4 with StateSnapshotRestore

use of org.apache.flink.runtime.state.StateSnapshotRestore in project flink by apache.

the class HeapSnapshotResources method processSnapshotMetaInfoForAllStates.

private static void processSnapshotMetaInfoForAllStates(List<StateMetaInfoSnapshot> metaInfoSnapshots, Map<StateUID, StateSnapshot> cowStateStableSnapshots, Map<StateUID, Integer> stateNamesToId, Map<String, ? extends StateSnapshotRestore> registeredStates, StateMetaInfoSnapshot.BackendStateType stateType) {
    for (Map.Entry<String, ? extends StateSnapshotRestore> kvState : registeredStates.entrySet()) {
        final StateUID stateUid = StateUID.of(kvState.getKey(), stateType);
        stateNamesToId.put(stateUid, stateNamesToId.size());
        StateSnapshotRestore state = kvState.getValue();
        if (null != state) {
            final StateSnapshot stateSnapshot = state.stateSnapshot();
            metaInfoSnapshots.add(stateSnapshot.getMetaInfoSnapshot());
            cowStateStableSnapshots.put(stateUid, stateSnapshot);
        }
    }
}
Also used : StateSnapshotRestore(org.apache.flink.runtime.state.StateSnapshotRestore) StateSnapshot(org.apache.flink.runtime.state.StateSnapshot) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with StateSnapshotRestore

use of org.apache.flink.runtime.state.StateSnapshotRestore in project flink by apache.

the class HeapKeyedStateBackend method getKeysAndNamespaces.

@SuppressWarnings("unchecked")
@Override
public <N> Stream<Tuple2<K, N>> getKeysAndNamespaces(String state) {
    if (!registeredKVStates.containsKey(state)) {
        return Stream.empty();
    }
    final StateSnapshotRestore stateSnapshotRestore = registeredKVStates.get(state);
    StateTable<K, N, ?> table = (StateTable<K, N, ?>) stateSnapshotRestore;
    return table.getKeysAndNamespaces();
}
Also used : StateSnapshotRestore(org.apache.flink.runtime.state.StateSnapshotRestore)

Aggregations

StateSnapshotRestore (org.apache.flink.runtime.state.StateSnapshotRestore)5 HashMap (java.util.HashMap)2 StateMetaInfoSnapshot (org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot)2 Map (java.util.Map)1 DataInputViewStreamWrapper (org.apache.flink.core.memory.DataInputViewStreamWrapper)1 RegisteredKeyValueStateBackendMetaInfo (org.apache.flink.runtime.state.RegisteredKeyValueStateBackendMetaInfo)1 RegisteredPriorityQueueStateBackendMetaInfo (org.apache.flink.runtime.state.RegisteredPriorityQueueStateBackendMetaInfo)1 StateSnapshot (org.apache.flink.runtime.state.StateSnapshot)1 StateSnapshotKeyGroupReader (org.apache.flink.runtime.state.StateSnapshotKeyGroupReader)1