Search in sources :

Example 1 with MultiplexingStreamRecordSerializer

use of org.apache.flink.migration.streaming.runtime.streamrecord.MultiplexingStreamRecordSerializer in project flink by apache.

the class AbstractKeyedCEPPatternOperator method restoreState.

//////////////////////			Backwards Compatibility			//////////////////////
@Override
public void restoreState(FSDataInputStream in) throws Exception {
    // this is the flag indicating if we have udf
    // state to restore (not needed here)
    in.read();
    DataInputViewStreamWrapper inputView = new DataInputViewStreamWrapper(in);
    InternalWatermarkCallbackService<KEY> watermarkCallbackService = getInternalWatermarkCallbackService();
    if (migratingFromOldKeyedOperator) {
        int numberEntries = inputView.readInt();
        for (int i = 0; i < numberEntries; i++) {
            watermarkCallbackService.registerKeyForWatermarkCallback(keySerializer.deserialize(inputView));
        }
    } else {
        final ObjectInputStream ois = new ObjectInputStream(in);
        // retrieve the NFA
        @SuppressWarnings("unchecked") NFA<IN> nfa = (NFA<IN>) ois.readObject();
        // retrieve the elements that were pending in the priority queue
        MultiplexingStreamRecordSerializer<IN> recordSerializer = new MultiplexingStreamRecordSerializer<>(inputSerializer);
        PriorityQueue<StreamRecord<IN>> priorityQueue = priorityQueueFactory.createPriorityQueue();
        int entries = ois.readInt();
        for (int i = 0; i < entries; i++) {
            StreamElement streamElement = recordSerializer.deserialize(inputView);
            priorityQueue.offer(streamElement.<IN>asRecord());
        }
        // finally register the retrieved state with the new keyed state.
        setCurrentKey((byte) 0);
        nfaOperatorState.update(nfa);
        priorityQueueOperatorState.update(priorityQueue);
        if (!isProcessingTime) {
            // this is relevant only for event/ingestion time
            // need to work around type restrictions
            InternalWatermarkCallbackService rawWatermarkCallbackService = (InternalWatermarkCallbackService) watermarkCallbackService;
            rawWatermarkCallbackService.registerKeyForWatermarkCallback((byte) 0);
        }
        ois.close();
    }
}
Also used : StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) NFA(org.apache.flink.cep.nfa.NFA) StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) MultiplexingStreamRecordSerializer(org.apache.flink.migration.streaming.runtime.streamrecord.MultiplexingStreamRecordSerializer) InternalWatermarkCallbackService(org.apache.flink.streaming.api.operators.InternalWatermarkCallbackService) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)1 NFA (org.apache.flink.cep.nfa.NFA)1 DataInputViewStreamWrapper (org.apache.flink.core.memory.DataInputViewStreamWrapper)1 MultiplexingStreamRecordSerializer (org.apache.flink.migration.streaming.runtime.streamrecord.MultiplexingStreamRecordSerializer)1 InternalWatermarkCallbackService (org.apache.flink.streaming.api.operators.InternalWatermarkCallbackService)1 StreamElement (org.apache.flink.streaming.runtime.streamrecord.StreamElement)1 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)1