Search in sources :

Example 1 with KeyGroupStatePartitionStreamProvider

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

the class StateInitializationContextImplTest method close.

@Test
public void close() throws Exception {
    int count = 0;
    int stopCount = NUM_HANDLES / 2;
    boolean isClosed = false;
    try {
        for (KeyGroupStatePartitionStreamProvider stateStreamProvider : initializationContext.getRawKeyedStateInputs()) {
            Assert.assertNotNull(stateStreamProvider);
            if (count == stopCount) {
                initializationContext.close();
                isClosed = true;
            }
            try (InputStream is = stateStreamProvider.getStream()) {
                DataInputView div = new DataInputViewStreamWrapper(is);
                try {
                    int val = div.readInt();
                    Assert.assertEquals(stateStreamProvider.getKeyGroupId(), val);
                    if (isClosed) {
                        Assert.fail("Close was ignored: stream");
                    }
                    ++count;
                } catch (IOException ioex) {
                    if (!isClosed) {
                        throw ioex;
                    }
                }
            }
        }
        Assert.fail("Close was ignored: registry");
    } catch (IOException iex) {
        Assert.assertTrue(isClosed);
        Assert.assertEquals(stopCount, count);
    }
}
Also used : FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) InputStream(java.io.InputStream) DataInputView(org.apache.flink.core.memory.DataInputView) IOException(java.io.IOException) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) Test(org.junit.Test)

Example 2 with KeyGroupStatePartitionStreamProvider

use of org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider in project beam by apache.

the class DoFnOperator method initializeState.

@Override
public void initializeState(StateInitializationContext context) throws Exception {
    if (getKeyedStateBackend() != null) {
        int totalKeyGroups = getKeyedStateBackend().getNumberOfKeyGroups();
        KeyGroupsList localKeyGroupRange = getKeyedStateBackend().getKeyGroupRange();
        for (KeyGroupStatePartitionStreamProvider streamProvider : context.getRawKeyedStateInputs()) {
            DataInputViewStreamWrapper div = new DataInputViewStreamWrapper(streamProvider.getStream());
            int keyGroupIdx = streamProvider.getKeyGroupId();
            checkArgument(localKeyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range.");
            // if (this instanceof KeyGroupRestoringOperator)
            restoreKeyGroupState(keyGroupIdx, div);
            // We just initialize our timerService
            if (keyCoder != null) {
                if (timerService == null) {
                    timerService = new HeapInternalTimerService<>(totalKeyGroups, localKeyGroupRange, this, getRuntimeContext().getProcessingTimeService());
                }
                timerService.restoreTimersForKeyGroup(div, keyGroupIdx, getUserCodeClassloader());
            }
        }
    }
}
Also used : KeyGroupsList(org.apache.flink.runtime.state.KeyGroupsList) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider)

Example 3 with KeyGroupStatePartitionStreamProvider

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

the class AbstractStreamOperator method initializeState.

/**
	 * Stream operators with state which can be restored need to override this hook method.
	 *
	 * @param context context that allows to register different states.
	 */
public void initializeState(StateInitializationContext context) throws Exception {
    if (getKeyedStateBackend() != null) {
        KeyGroupsList localKeyGroupRange = getKeyedStateBackend().getKeyGroupRange();
        // and then initialize the timer services
        for (KeyGroupStatePartitionStreamProvider streamProvider : context.getRawKeyedStateInputs()) {
            int keyGroupIdx = streamProvider.getKeyGroupId();
            checkArgument(localKeyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range.");
            timeServiceManager.restoreStateForKeyGroup(new DataInputViewStreamWrapper(streamProvider.getStream()), keyGroupIdx, getUserCodeClassloader());
        }
    }
}
Also used : KeyGroupsList(org.apache.flink.runtime.state.KeyGroupsList) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider)

Example 4 with KeyGroupStatePartitionStreamProvider

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

the class StateInitializationContextImplTest method getKeyedStateStreams.

@Test
public void getKeyedStateStreams() throws Exception {
    int readKeyGroupCount = 0;
    for (KeyGroupStatePartitionStreamProvider stateStreamProvider : initializationContext.getRawKeyedStateInputs()) {
        Assert.assertNotNull(stateStreamProvider);
        try (InputStream is = stateStreamProvider.getStream()) {
            DataInputView div = new DataInputViewStreamWrapper(is);
            int val = div.readInt();
            ++readKeyGroupCount;
            Assert.assertEquals(stateStreamProvider.getKeyGroupId(), val);
        }
    }
    Assert.assertEquals(writtenKeyGroups, readKeyGroupCount);
}
Also used : FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) InputStream(java.io.InputStream) DataInputView(org.apache.flink.core.memory.DataInputView) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) Test(org.junit.Test)

Example 5 with KeyGroupStatePartitionStreamProvider

use of org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider in project beam by apache.

the class DedupingOperator method initializeState.

@Override
public void initializeState(StateInitializationContext context) throws Exception {
    if (getKeyedStateBackend() != null) {
        KeyGroupsList localKeyGroupRange = getKeyedStateBackend().getKeyGroupRange();
        for (KeyGroupStatePartitionStreamProvider streamProvider : context.getRawKeyedStateInputs()) {
            DataInputViewStreamWrapper div = new DataInputViewStreamWrapper(streamProvider.getStream());
            int keyGroupIdx = streamProvider.getKeyGroupId();
            checkArgument(localKeyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range.");
            // if (this instanceof KeyGroupRestoringOperator)
            restoreKeyGroupState(keyGroupIdx, div);
        }
    }
}
Also used : KeyGroupsList(org.apache.flink.runtime.state.KeyGroupsList) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider)

Aggregations

DataInputViewStreamWrapper (org.apache.flink.core.memory.DataInputViewStreamWrapper)5 KeyGroupStatePartitionStreamProvider (org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider)5 KeyGroupsList (org.apache.flink.runtime.state.KeyGroupsList)3 InputStream (java.io.InputStream)2 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)2 DataInputView (org.apache.flink.core.memory.DataInputView)2 Test (org.junit.Test)2 IOException (java.io.IOException)1