Search in sources :

Example 21 with VoidNamespace

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

the class RocksDBReducingStateTest method testAddAndGet.

// ------------------------------------------------------------------------
@Test
public void testAddAndGet() throws Exception {
    final ReducingStateDescriptor<Long> stateDescr = new ReducingStateDescriptor<>("my-state", new AddingFunction(), Long.class);
    stateDescr.initializeSerializerUnlessSet(new ExecutionConfig());
    final RocksDBStateBackend backend = new RocksDBStateBackend(tmp.newFolder().toURI());
    backend.setDbStoragePath(tmp.newFolder().getAbsolutePath());
    final RocksDBKeyedStateBackend<String> keyedBackend = createKeyedBackend(backend);
    try {
        InternalReducingState<VoidNamespace, Long> state = keyedBackend.createReducingState(VoidNamespaceSerializer.INSTANCE, stateDescr);
        state.setCurrentNamespace(VoidNamespace.INSTANCE);
        keyedBackend.setCurrentKey("abc");
        assertNull(state.get());
        keyedBackend.setCurrentKey("def");
        assertNull(state.get());
        state.add(17L);
        state.add(11L);
        assertEquals(28L, state.get().longValue());
        keyedBackend.setCurrentKey("abc");
        assertNull(state.get());
        keyedBackend.setCurrentKey("g");
        assertNull(state.get());
        state.add(1L);
        state.add(2L);
        keyedBackend.setCurrentKey("def");
        assertEquals(28L, state.get().longValue());
        state.clear();
        assertNull(state.get());
        keyedBackend.setCurrentKey("g");
        state.add(3L);
        state.add(2L);
        state.add(1L);
        keyedBackend.setCurrentKey("def");
        assertNull(state.get());
        keyedBackend.setCurrentKey("g");
        assertEquals(9L, state.get().longValue());
    } finally {
        keyedBackend.close();
        keyedBackend.dispose();
    }
}
Also used : ReducingStateDescriptor(org.apache.flink.api.common.state.ReducingStateDescriptor) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Example 22 with VoidNamespace

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

the class KvStateRequestSerializerTest method testMapSerialization.

/**
	 * Tests map serialization utils.
	 */
@Test
public void testMapSerialization() throws Exception {
    final long key = 0L;
    // objects for heap state list serialisation
    final HeapKeyedStateBackend<Long> longHeapKeyedStateBackend = new HeapKeyedStateBackend<>(mock(TaskKvStateRegistry.class), LongSerializer.INSTANCE, ClassLoader.getSystemClassLoader(), 1, new KeyGroupRange(0, 0), async, new ExecutionConfig());
    longHeapKeyedStateBackend.setCurrentKey(key);
    final InternalMapState<VoidNamespace, Long, String> mapState = (InternalMapState<VoidNamespace, Long, String>) longHeapKeyedStateBackend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, new MapStateDescriptor<>("test", LongSerializer.INSTANCE, StringSerializer.INSTANCE));
    testMapSerialization(key, mapState);
}
Also used : InternalMapState(org.apache.flink.runtime.state.internal.InternalMapState) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) HeapKeyedStateBackend(org.apache.flink.runtime.state.heap.HeapKeyedStateBackend) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) TaskKvStateRegistry(org.apache.flink.runtime.query.TaskKvStateRegistry) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Example 23 with VoidNamespace

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

the class HeapReducingStateTest method testAddAndGet.

@Test
public void testAddAndGet() throws Exception {
    final ReducingStateDescriptor<Long> stateDescr = new ReducingStateDescriptor<>("my-state", new AddingFunction(), Long.class);
    stateDescr.initializeSerializerUnlessSet(new ExecutionConfig());
    final HeapKeyedStateBackend<String> keyedBackend = createKeyedBackend();
    try {
        InternalReducingState<VoidNamespace, Long> state = keyedBackend.createReducingState(VoidNamespaceSerializer.INSTANCE, stateDescr);
        state.setCurrentNamespace(VoidNamespace.INSTANCE);
        keyedBackend.setCurrentKey("abc");
        assertNull(state.get());
        keyedBackend.setCurrentKey("def");
        assertNull(state.get());
        state.add(17L);
        state.add(11L);
        assertEquals(28L, state.get().longValue());
        keyedBackend.setCurrentKey("abc");
        assertNull(state.get());
        keyedBackend.setCurrentKey("g");
        assertNull(state.get());
        state.add(1L);
        state.add(2L);
        keyedBackend.setCurrentKey("def");
        assertEquals(28L, state.get().longValue());
        state.clear();
        assertNull(state.get());
        keyedBackend.setCurrentKey("g");
        state.add(3L);
        state.add(2L);
        state.add(1L);
        keyedBackend.setCurrentKey("def");
        assertNull(state.get());
        keyedBackend.setCurrentKey("g");
        assertEquals(9L, state.get().longValue());
        state.clear();
        // make sure all lists / maps are cleared
        StateTable<String, VoidNamespace, Long> stateTable = ((HeapReducingState<String, VoidNamespace, Long>) state).stateTable;
        assertTrue(stateTable.isEmpty());
    } finally {
        keyedBackend.close();
        keyedBackend.dispose();
    }
}
Also used : ReducingStateDescriptor(org.apache.flink.api.common.state.ReducingStateDescriptor) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Example 24 with VoidNamespace

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

the class KVStateRequestSerializerRocksDBTest method testMapSerialization.

/**
	 * Tests map serialization and deserialization match.
	 *
	 * @see KvStateRequestSerializerTest#testMapSerialization()
	 * KvStateRequestSerializerTest#testMapSerialization() using the heap state back-end
	 * test
	 */
@Test
public void testMapSerialization() throws Exception {
    final long key = 0L;
    // objects for RocksDB state list serialisation
    DBOptions dbOptions = PredefinedOptions.DEFAULT.createDBOptions();
    dbOptions.setCreateIfMissing(true);
    ColumnFamilyOptions columnFamilyOptions = PredefinedOptions.DEFAULT.createColumnOptions();
    final RocksDBKeyedStateBackend<Long> longHeapKeyedStateBackend = new RocksDBKeyedStateBackend<>(new JobID(), "no-op", ClassLoader.getSystemClassLoader(), temporaryFolder.getRoot(), dbOptions, columnFamilyOptions, mock(TaskKvStateRegistry.class), LongSerializer.INSTANCE, 1, new KeyGroupRange(0, 0), new ExecutionConfig());
    longHeapKeyedStateBackend.setCurrentKey(key);
    final InternalMapState<VoidNamespace, Long, String> mapState = (InternalMapState<VoidNamespace, Long, String>) longHeapKeyedStateBackend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, new MapStateDescriptor<>("test", LongSerializer.INSTANCE, StringSerializer.INSTANCE));
    KvStateRequestSerializerTest.testMapSerialization(key, mapState);
}
Also used : MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) TaskKvStateRegistry(org.apache.flink.runtime.query.TaskKvStateRegistry) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) RocksDBKeyedStateBackend(org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend) ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) InternalMapState(org.apache.flink.runtime.state.internal.InternalMapState) DBOptions(org.rocksdb.DBOptions) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test) KvStateRequestSerializerTest(org.apache.flink.runtime.query.netty.message.KvStateRequestSerializerTest)

Example 25 with VoidNamespace

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

the class AbstractStreamArrowPythonOverWindowAggregateFunctionOperator method open.

@Override
public void open() throws Exception {
    super.open();
    InternalTimerService<VoidNamespace> internalTimerService = getInternalTimerService("python-over-window-timers", VoidNamespaceSerializer.INSTANCE, this);
    timerService = new SimpleTimerService(internalTimerService);
    InternalTypeInfo<RowData> inputTypeInfo = InternalTypeInfo.of(inputType);
    ListTypeInfo<RowData> rowListTypeInfo = new ListTypeInfo<>(inputTypeInfo);
    MapStateDescriptor<Long, List<RowData>> inputStateDesc = new MapStateDescriptor<>("inputState", Types.LONG, rowListTypeInfo);
    ValueStateDescriptor<Long> lastTriggeringTsDescriptor = new ValueStateDescriptor<>("lastTriggeringTsState", Types.LONG);
    lastTriggeringTsState = getRuntimeContext().getState(lastTriggeringTsDescriptor);
    ValueStateDescriptor<Long> cleanupTsStateDescriptor = new ValueStateDescriptor<>("cleanupTsState", Types.LONG);
    cleanupTsState = getRuntimeContext().getState(cleanupTsStateDescriptor);
    inputState = getRuntimeContext().getMapState(inputStateDesc);
}
Also used : MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) SimpleTimerService(org.apache.flink.streaming.api.SimpleTimerService) RowData(org.apache.flink.table.data.RowData) ListTypeInfo(org.apache.flink.api.java.typeutils.ListTypeInfo) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) List(java.util.List)

Aggregations

VoidNamespace (org.apache.flink.runtime.state.VoidNamespace)31 Test (org.junit.Test)21 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)11 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)10 ArrayList (java.util.ArrayList)9 SimpleTimerService (org.apache.flink.streaming.api.SimpleTimerService)8 JobID (org.apache.flink.api.common.JobID)6 VoidNamespaceSerializer (org.apache.flink.runtime.state.VoidNamespaceSerializer)6 InternalTimerService (org.apache.flink.streaming.api.operators.InternalTimerService)6 TestProcessingTimeService (org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService)6 List (java.util.List)5 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)5 TimerService (org.apache.flink.streaming.api.TimerService)5 Arrays (java.util.Arrays)4 TaskKvStateRegistry (org.apache.flink.runtime.query.TaskKvStateRegistry)4 Watermark (org.apache.flink.streaming.api.watermark.Watermark)4 Assert (org.junit.Assert)4 Collections (java.util.Collections)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3 BiConsumer (java.util.function.BiConsumer)3