Search in sources :

Example 1 with GaugePeriodTimer

use of org.apache.flink.streaming.runtime.tasks.mailbox.GaugePeriodTimer in project flink by apache.

the class StreamTask method processInput.

/**
 * This method implements the default action of the task (e.g. processing one event from the
 * input). Implementations should (in general) be non-blocking.
 *
 * @param controller controller object for collaborative interaction between the action and the
 *     stream task.
 * @throws Exception on any problems in the action.
 */
protected void processInput(MailboxDefaultAction.Controller controller) throws Exception {
    DataInputStatus status = inputProcessor.processInput();
    switch(status) {
        case MORE_AVAILABLE:
            if (recordWriter.isAvailable() && (changelogWriterAvailabilityProvider == null || changelogWriterAvailabilityProvider.isAvailable())) {
                return;
            }
            break;
        case NOTHING_AVAILABLE:
            break;
        case END_OF_RECOVERY:
            throw new IllegalStateException("We should not receive this event here.");
        case STOPPED:
            endData(StopMode.NO_DRAIN);
            return;
        case END_OF_DATA:
            endData(StopMode.DRAIN);
            return;
        case END_OF_INPUT:
            // Suspend the mailbox processor, it would be resumed in afterInvoke and finished
            // after all records processed by the downstream tasks. We also suspend the default
            // actions to avoid repeat executing the empty default operation (namely process
            // records).
            controller.suspendDefaultAction();
            mailboxProcessor.suspend();
            return;
    }
    TaskIOMetricGroup ioMetrics = getEnvironment().getMetricGroup().getIOMetricGroup();
    PeriodTimer timer;
    CompletableFuture<?> resumeFuture;
    if (!recordWriter.isAvailable()) {
        timer = new GaugePeriodTimer(ioMetrics.getSoftBackPressuredTimePerSecond());
        resumeFuture = recordWriter.getAvailableFuture();
    } else if (!inputProcessor.isAvailable()) {
        timer = new GaugePeriodTimer(ioMetrics.getIdleTimeMsPerSecond());
        resumeFuture = inputProcessor.getAvailableFuture();
    } else {
        // currently, waiting for changelog availability is reported as busy
        // todo: add new metric (FLINK-24402)
        timer = null;
        resumeFuture = changelogWriterAvailabilityProvider.getAvailableFuture();
    }
    assertNoException(resumeFuture.thenRun(new ResumeWrapper(controller.suspendDefaultAction(timer), timer)));
}
Also used : DataInputStatus(org.apache.flink.streaming.runtime.io.DataInputStatus) TaskIOMetricGroup(org.apache.flink.runtime.metrics.groups.TaskIOMetricGroup) GaugePeriodTimer(org.apache.flink.streaming.runtime.tasks.mailbox.GaugePeriodTimer) PeriodTimer(org.apache.flink.streaming.runtime.tasks.mailbox.PeriodTimer) GaugePeriodTimer(org.apache.flink.streaming.runtime.tasks.mailbox.GaugePeriodTimer)

Aggregations

TaskIOMetricGroup (org.apache.flink.runtime.metrics.groups.TaskIOMetricGroup)1 DataInputStatus (org.apache.flink.streaming.runtime.io.DataInputStatus)1 GaugePeriodTimer (org.apache.flink.streaming.runtime.tasks.mailbox.GaugePeriodTimer)1 PeriodTimer (org.apache.flink.streaming.runtime.tasks.mailbox.PeriodTimer)1