Search in sources :

Example 6 with StateDescriptor

use of org.apache.flink.api.common.state.StateDescriptor in project flink by apache.

the class ChangelogBackendLogApplier method restoreKvMetaData.

private static RegisteredKeyValueStateBackendMetaInfo restoreKvMetaData(ChangelogKeyedStateBackend<?> backend, StateMetaInfoSnapshot snapshot, DataInputView in) throws Exception {
    RegisteredKeyValueStateBackendMetaInfo meta = new RegisteredKeyValueStateBackendMetaInfo(snapshot);
    StateTtlConfig ttlConfig = readTtlConfig(in);
    Object defaultValue = readDefaultValue(in, meta);
    // Use regular API to create states in both changelog and the base backends the metadata is
    // persisted in log before data changes.
    // An alternative solution to load metadata "natively" by the base backends would require
    // base state to be always present, i.e. the 1st checkpoint would have to be "full" always.
    StateDescriptor stateDescriptor = toStateDescriptor(meta, defaultValue);
    // todo: support changing ttl (FLINK-23143)
    if (ttlConfig.isEnabled()) {
        stateDescriptor.enableTimeToLive(ttlConfig);
    }
    backend.getOrCreateKeyedState(meta.getNamespaceSerializer(), stateDescriptor);
    return meta;
}
Also used : ReducingStateDescriptor(org.apache.flink.api.common.state.ReducingStateDescriptor) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) AggregatingStateDescriptor(org.apache.flink.api.common.state.AggregatingStateDescriptor) StateDescriptor(org.apache.flink.api.common.state.StateDescriptor) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) StateTtlConfig(org.apache.flink.api.common.state.StateTtlConfig) RegisteredKeyValueStateBackendMetaInfo(org.apache.flink.runtime.state.RegisteredKeyValueStateBackendMetaInfo)

Example 7 with StateDescriptor

use of org.apache.flink.api.common.state.StateDescriptor in project flink by apache.

the class StreamingRuntimeContextTest method testReducingStateInstantiation.

@Test
public void testReducingStateInstantiation() throws Exception {
    final ExecutionConfig config = new ExecutionConfig();
    config.registerKryoType(Path.class);
    final AtomicReference<Object> descriptorCapture = new AtomicReference<>();
    StreamingRuntimeContext context = createRuntimeContext(descriptorCapture, config);
    @SuppressWarnings("unchecked") ReduceFunction<TaskInfo> reducer = (ReduceFunction<TaskInfo>) mock(ReduceFunction.class);
    ReducingStateDescriptor<TaskInfo> descr = new ReducingStateDescriptor<>("name", reducer, TaskInfo.class);
    context.getReducingState(descr);
    StateDescriptor<?, ?> descrIntercepted = (StateDescriptor<?, ?>) descriptorCapture.get();
    TypeSerializer<?> serializer = descrIntercepted.getSerializer();
    // check that the Path class is really registered, i.e., the execution config was applied
    assertTrue(serializer instanceof KryoSerializer);
    assertTrue(((KryoSerializer<?>) serializer).getKryo().getRegistration(Path.class).getId() > 0);
}
Also used : Path(org.apache.flink.core.fs.Path) ReducingStateDescriptor(org.apache.flink.api.common.state.ReducingStateDescriptor) ReduceFunction(org.apache.flink.api.common.functions.ReduceFunction) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer) TaskInfo(org.apache.flink.api.common.TaskInfo) ReducingStateDescriptor(org.apache.flink.api.common.state.ReducingStateDescriptor) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) AggregatingStateDescriptor(org.apache.flink.api.common.state.AggregatingStateDescriptor) StateDescriptor(org.apache.flink.api.common.state.StateDescriptor) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) Test(org.junit.Test)

Aggregations

ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)7 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)7 StateDescriptor (org.apache.flink.api.common.state.StateDescriptor)7 AggregatingStateDescriptor (org.apache.flink.api.common.state.AggregatingStateDescriptor)4 ReducingStateDescriptor (org.apache.flink.api.common.state.ReducingStateDescriptor)4 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)4 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)3 StateTtlConfig (org.apache.flink.api.common.state.StateTtlConfig)3 HashMap (java.util.HashMap)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ByteString (org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString)2 TaskInfo (org.apache.flink.api.common.TaskInfo)2 KryoSerializer (org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer)2 Path (org.apache.flink.core.fs.Path)2 FlinkFnApi (org.apache.flink.fnexecution.v1.FlinkFnApi)2 EOFException (java.io.EOFException)1 ObjectInputStream (java.io.ObjectInputStream)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1