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;
}
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);
}
Aggregations