Search in sources :

Example 1 with MistCheckpointEvent

use of edu.snu.mist.core.MistCheckpointEvent in project mist by snuspl.

the class UnionOperator method drainUntilMinimumWatermark.

/**
 * Emits events which have less timestamp than the minimum watermark
 * calculated from the leftUpstreamQueue, currentLeftWatermark, rightUpstreamQueue, and currentRightWatermark.
 * This method is not thread-safe now. Therefore, only one event processor have to process union operation at once.
 */
private void drainUntilMinimumWatermark() {
    final long leftWatermarkTimestamp = latestLeftWatermark.getTimestamp();
    final long rightWatermarkTimestamp = latestRightWatermark.getTimestamp();
    final long timestamp = getMinimumWatermark(leftWatermarkTimestamp, rightWatermarkTimestamp);
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "{0} drains inputs until timestamp {1}", new Object[] { this.getClass().getName(), timestamp });
    }
    // The events in the queue is ordered by timestamp, so just peeks one by one
    while (!leftUpstreamQueue.isEmpty() && !rightUpstreamQueue.isEmpty()) {
        // The left and right checkpoint events do not have to be ordered because they are the same.
        if (leftUpstreamQueue.peek().isCheckpoint()) {
            final MistCheckpointEvent event = (MistCheckpointEvent) leftUpstreamQueue.poll();
            outputEmitter.emitCheckpoint(event);
        } else if (rightUpstreamQueue.peek().isCheckpoint()) {
            final MistCheckpointEvent event = (MistCheckpointEvent) rightUpstreamQueue.poll();
            outputEmitter.emitCheckpoint(event);
        } else {
            // Pick minimum timestamp from left and right queue.
            long leftTs = peekTimestamp(leftUpstreamQueue);
            long rightTs = peekTimestamp(rightUpstreamQueue);
            // End of the drain
            if (leftTs > timestamp && rightTs > timestamp) {
                return;
            }
            if (leftTs <= rightTs) {
                final MistDataEvent event = (MistDataEvent) leftUpstreamQueue.poll();
                outputEmitter.emitData(event);
            } else {
                final MistDataEvent event = (MistDataEvent) rightUpstreamQueue.poll();
                outputEmitter.emitData(event);
            }
        }
    }
    // If one of the upstreamQueues is not empty, then drain events from the queue
    if (!(leftUpstreamQueue.isEmpty() && rightUpstreamQueue.isEmpty())) {
        if (leftUpstreamQueue.isEmpty()) {
            // Drain from right upstream queue.
            drainUntilTimestamp(rightUpstreamQueue, timestamp);
        } else {
            // Drain from left upstream queue.
            drainUntilTimestamp(leftUpstreamQueue, timestamp);
        }
    }
    emitWatermarkUntilTimestamp(leftWatermarkTimestamp, rightWatermarkTimestamp, timestamp);
}
Also used : MistDataEvent(edu.snu.mist.core.MistDataEvent) MistCheckpointEvent(edu.snu.mist.core.MistCheckpointEvent)

Aggregations

MistCheckpointEvent (edu.snu.mist.core.MistCheckpointEvent)1 MistDataEvent (edu.snu.mist.core.MistDataEvent)1