Search in sources :

Example 1 with ResettableDriver

use of org.apache.flink.runtime.operators.ResettableDriver in project flink by apache.

the class AbstractIterativeTask method reinstantiateDriver.

private void reinstantiateDriver() throws Exception {
    if (this.driver instanceof ResettableDriver) {
        final ResettableDriver<?, ?> resDriver = (ResettableDriver<?, ?>) this.driver;
        resDriver.reset();
    } else {
        Class<? extends Driver<S, OT>> driverClass = this.config.getDriver();
        this.driver = InstantiationUtil.instantiate(driverClass, Driver.class);
        try {
            this.driver.setup(this);
        } catch (Throwable t) {
            throw new Exception("The pact driver setup for '" + this.getEnvironment().getTaskInfo().getTaskName() + "' , caused an error: " + t.getMessage(), t);
        }
    }
}
Also used : Driver(org.apache.flink.runtime.operators.Driver) ResettableDriver(org.apache.flink.runtime.operators.ResettableDriver) ResettableDriver(org.apache.flink.runtime.operators.ResettableDriver) IOException(java.io.IOException)

Example 2 with ResettableDriver

use of org.apache.flink.runtime.operators.ResettableDriver in project flink by apache.

the class AbstractIterativeTask method initialize.

// --------------------------------------------------------------------------------------------
// Main life cycle methods that implement the iterative behavior
// --------------------------------------------------------------------------------------------
@Override
protected void initialize() throws Exception {
    super.initialize();
    // check if the driver is resettable
    if (this.driver instanceof ResettableDriver) {
        final ResettableDriver<?, ?> resDriver = (ResettableDriver<?, ?>) this.driver;
        // make sure that the according inputs are not reseted
        for (int i = 0; i < resDriver.getNumberOfInputs(); i++) {
            if (resDriver.isInputResettable(i)) {
                excludeFromReset(i);
            }
        }
    }
    TaskConfig config = getLastTasksConfig();
    isWorksetIteration = config.getIsWorksetIteration();
    isWorksetUpdate = config.getIsWorksetUpdate();
    isSolutionSetUpdate = config.getIsSolutionSetUpdate();
    if (isWorksetUpdate) {
        worksetBackChannel = BlockingBackChannelBroker.instance().getAndRemove(brokerKey());
        if (isWorksetIteration) {
            worksetAggregator = getIterationAggregators().getAggregator(WorksetEmptyConvergenceCriterion.AGGREGATOR_NAME);
            if (worksetAggregator == null) {
                throw new RuntimeException("Missing workset elements count aggregator.");
            }
        }
    }
}
Also used : TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) ResettableDriver(org.apache.flink.runtime.operators.ResettableDriver)

Example 3 with ResettableDriver

use of org.apache.flink.runtime.operators.ResettableDriver in project flink by apache.

the class BinaryOperatorTestBase method testDriverInternal.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void testDriverInternal(Driver driver, Class stubClass) throws Exception {
    this.driver = driver;
    driver.setup(this);
    this.stub = (S) stubClass.newInstance();
    // regular running logic
    this.running = true;
    boolean stubOpen = false;
    try {
        // run the data preparation
        try {
            driver.prepare();
        } catch (Throwable t) {
            throw new Exception("The data preparation caused an error: " + t.getMessage(), t);
        }
        // open stub implementation
        try {
            FunctionUtils.openFunction(this.stub, getTaskConfig().getStubParameters());
            stubOpen = true;
        } catch (Throwable t) {
            throw new Exception("The user defined 'open()' method caused an exception: " + t.getMessage(), t);
        }
        if (!running) {
            return;
        }
        // run the user code
        driver.run();
        // close. We close here such that a regular close throwing an exception marks a task as failed.
        if (this.running) {
            FunctionUtils.closeFunction(this.stub);
            stubOpen = false;
        }
        this.output.close();
    } catch (Exception ex) {
        // close the input, but do not report any exceptions, since we already have another root cause
        if (stubOpen) {
            try {
                FunctionUtils.closeFunction(this.stub);
            } catch (Throwable ignored) {
            }
        }
        // if resettable driver invoke tear down
        if (this.driver instanceof ResettableDriver) {
            final ResettableDriver<?, ?> resDriver = (ResettableDriver<?, ?>) this.driver;
            try {
                resDriver.teardown();
            } catch (Throwable t) {
                throw new Exception("Error while shutting down an iterative operator: " + t.getMessage(), t);
            }
        }
        // drop exception, if the task was canceled
        if (this.running) {
            throw ex;
        }
    } finally {
        driver.cleanup();
    }
}
Also used : IOException(java.io.IOException) ResettableDriver(org.apache.flink.runtime.operators.ResettableDriver)

Aggregations

ResettableDriver (org.apache.flink.runtime.operators.ResettableDriver)3 IOException (java.io.IOException)2 Driver (org.apache.flink.runtime.operators.Driver)1 TaskConfig (org.apache.flink.runtime.operators.util.TaskConfig)1