Search in sources :

Example 16 with InputSplit

use of org.apache.flink.core.io.InputSplit in project flink by apache.

the class LocatableSplitAssignerTest method testSerialSplitAssignmentAllForSameHost.

@Test
public void testSerialSplitAssignmentAllForSameHost() {
    try {
        final int NUM_SPLITS = 50;
        // load some splits
        Set<LocatableInputSplit> splits = new HashSet<LocatableInputSplit>();
        for (int i = 0; i < NUM_SPLITS; i++) {
            splits.add(new LocatableInputSplit(i, "testhost"));
        }
        // get all available splits
        LocatableInputSplitAssigner ia = new LocatableInputSplitAssigner(splits);
        InputSplit is = null;
        while ((is = ia.getNextInputSplit("testhost", 0)) != null) {
            assertTrue(splits.remove(is));
        }
        // check we had all
        assertTrue(splits.isEmpty());
        assertNull(ia.getNextInputSplit("", 0));
        assertEquals(0, ia.getNumberOfRemoteAssignments());
        assertEquals(NUM_SPLITS, ia.getNumberOfLocalAssignments());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : LocatableInputSplit(org.apache.flink.core.io.LocatableInputSplit) LocatableInputSplitAssigner(org.apache.flink.api.common.io.LocatableInputSplitAssigner) InputSplit(org.apache.flink.core.io.InputSplit) LocatableInputSplit(org.apache.flink.core.io.LocatableInputSplit) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with InputSplit

use of org.apache.flink.core.io.InputSplit in project flink by apache.

the class LocatableSplitAssignerTest method testSerialSplitAssignmentAllForRemoteHost.

@Test
public void testSerialSplitAssignmentAllForRemoteHost() {
    try {
        final String[] hosts = { "host1", "host1", "host1", "host2", "host2", "host3" };
        final int NUM_SPLITS = 10 * hosts.length;
        // load some splits
        Set<LocatableInputSplit> splits = new HashSet<LocatableInputSplit>();
        for (int i = 0; i < NUM_SPLITS; i++) {
            splits.add(new LocatableInputSplit(i, hosts[i % hosts.length]));
        }
        // get all available splits
        LocatableInputSplitAssigner ia = new LocatableInputSplitAssigner(splits);
        InputSplit is = null;
        while ((is = ia.getNextInputSplit("testhost", 0)) != null) {
            assertTrue(splits.remove(is));
        }
        // check we had all
        assertTrue(splits.isEmpty());
        assertNull(ia.getNextInputSplit("anotherHost", 0));
        assertEquals(NUM_SPLITS, ia.getNumberOfRemoteAssignments());
        assertEquals(0, ia.getNumberOfLocalAssignments());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : LocatableInputSplit(org.apache.flink.core.io.LocatableInputSplit) LocatableInputSplitAssigner(org.apache.flink.api.common.io.LocatableInputSplitAssigner) InputSplit(org.apache.flink.core.io.InputSplit) LocatableInputSplit(org.apache.flink.core.io.LocatableInputSplit) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with InputSplit

use of org.apache.flink.core.io.InputSplit in project flink by apache.

the class TaskInputSplitProviderTest method testRequestNextInputSplitWithInvalidExecutionID.

@Test
public void testRequestNextInputSplitWithInvalidExecutionID() throws InputSplitProviderException {
    final JobID jobID = new JobID();
    final JobVertexID vertexID = new JobVertexID();
    final ExecutionAttemptID executionID = new ExecutionAttemptID();
    final FiniteDuration timeout = new FiniteDuration(10, TimeUnit.SECONDS);
    final ActorGateway gateway = new NullInputSplitGateway();
    final TaskInputSplitProvider provider = new TaskInputSplitProvider(gateway, jobID, vertexID, executionID, timeout);
    // The jobManager will return a
    InputSplit nextInputSplit = provider.getNextInputSplit(getClass().getClassLoader());
    assertTrue(nextInputSplit == null);
}
Also used : ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) BaseTestingActorGateway(org.apache.flink.runtime.instance.BaseTestingActorGateway) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) FiniteDuration(scala.concurrent.duration.FiniteDuration) InputSplit(org.apache.flink.core.io.InputSplit) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 19 with InputSplit

use of org.apache.flink.core.io.InputSplit in project flink by apache.

the class InputFormatSourceFunction method getInputSplits.

private Iterator<InputSplit> getInputSplits() {
    return new Iterator<InputSplit>() {

        private InputSplit nextSplit;

        private boolean exhausted;

        @Override
        public boolean hasNext() {
            if (exhausted) {
                return false;
            }
            if (nextSplit != null) {
                return true;
            }
            final InputSplit split;
            try {
                split = provider.getNextInputSplit(getRuntimeContext().getUserCodeClassLoader());
            } catch (InputSplitProviderException e) {
                throw new RuntimeException("Could not retrieve next input split.", e);
            }
            if (split != null) {
                this.nextSplit = split;
                return true;
            } else {
                exhausted = true;
                return false;
            }
        }

        @Override
        public InputSplit next() {
            if (this.nextSplit == null && !hasNext()) {
                throw new NoSuchElementException();
            }
            final InputSplit tmp = this.nextSplit;
            this.nextSplit = null;
            return tmp;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : Iterator(java.util.Iterator) InputSplitProviderException(org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException) InputSplit(org.apache.flink.core.io.InputSplit) NoSuchElementException(java.util.NoSuchElementException)

Example 20 with InputSplit

use of org.apache.flink.core.io.InputSplit in project flink by apache.

the class JobMaster method requestNextInputSplit.

@RpcMethod
public SerializedInputSplit requestNextInputSplit(final UUID leaderSessionID, final JobVertexID vertexID, final ExecutionAttemptID executionAttempt) throws Exception {
    validateLeaderSessionId(leaderSessionID);
    final Execution execution = executionGraph.getRegisteredExecutions().get(executionAttempt);
    if (execution == null) {
        // but TaskManager get some delay to aware of that situation
        if (log.isDebugEnabled()) {
            log.debug("Can not find Execution for attempt {}.", executionAttempt);
        }
        // but we should TaskManager be aware of this
        throw new Exception("Can not find Execution for attempt " + executionAttempt);
    }
    final ExecutionJobVertex vertex = executionGraph.getJobVertex(vertexID);
    if (vertex == null) {
        log.error("Cannot find execution vertex for vertex ID {}.", vertexID);
        throw new Exception("Cannot find execution vertex for vertex ID " + vertexID);
    }
    final InputSplitAssigner splitAssigner = vertex.getSplitAssigner();
    if (splitAssigner == null) {
        log.error("No InputSplitAssigner for vertex ID {}.", vertexID);
        throw new Exception("No InputSplitAssigner for vertex ID " + vertexID);
    }
    final Slot slot = execution.getAssignedResource();
    final int taskId = execution.getVertex().getParallelSubtaskIndex();
    final String host = slot != null ? slot.getTaskManagerLocation().getHostname() : null;
    final InputSplit nextInputSplit = splitAssigner.getNextInputSplit(host, taskId);
    if (log.isDebugEnabled()) {
        log.debug("Send next input split {}.", nextInputSplit);
    }
    try {
        final byte[] serializedInputSplit = InstantiationUtil.serializeObject(nextInputSplit);
        return new SerializedInputSplit(serializedInputSplit);
    } catch (Exception ex) {
        log.error("Could not serialize the next input split of class {}.", nextInputSplit.getClass(), ex);
        IOException reason = new IOException("Could not serialize the next input split of class " + nextInputSplit.getClass() + ".", ex);
        vertex.fail(reason);
        throw reason;
    }
}
Also used : InputSplitAssigner(org.apache.flink.core.io.InputSplitAssigner) Execution(org.apache.flink.runtime.executiongraph.Execution) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) Slot(org.apache.flink.runtime.instance.Slot) AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) IOException(java.io.IOException) InputSplit(org.apache.flink.core.io.InputSplit) TimeoutException(java.util.concurrent.TimeoutException) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) LeaderIdMismatchException(org.apache.flink.runtime.highavailability.LeaderIdMismatchException) PartitionProducerDisposedException(org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) IOException(java.io.IOException) RpcEndpoint(org.apache.flink.runtime.rpc.RpcEndpoint) AcknowledgeCheckpoint(org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint) DeclineCheckpoint(org.apache.flink.runtime.messages.checkpoint.DeclineCheckpoint) RpcMethod(org.apache.flink.runtime.rpc.RpcMethod)

Aggregations

InputSplit (org.apache.flink.core.io.InputSplit)21 Test (org.junit.Test)12 HashSet (java.util.HashSet)7 LocatableInputSplit (org.apache.flink.core.io.LocatableInputSplit)6 LocatableInputSplitAssigner (org.apache.flink.api.common.io.LocatableInputSplitAssigner)5 InputSplitProviderException (org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException)4 ArrayList (java.util.ArrayList)3 NoSuchElementException (java.util.NoSuchElementException)3 GenericInputSplit (org.apache.flink.core.io.GenericInputSplit)3 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2 JobID (org.apache.flink.api.common.JobID)2 DefaultInputSplitAssigner (org.apache.flink.api.common.io.DefaultInputSplitAssigner)2 InputFormat (org.apache.flink.api.common.io.InputFormat)2 RichInputFormat (org.apache.flink.api.common.io.RichInputFormat)2 GenericParameterValuesProvider (org.apache.flink.api.java.io.jdbc.split.GenericParameterValuesProvider)2 ParameterValuesProvider (org.apache.flink.api.java.io.jdbc.split.ParameterValuesProvider)2 InputSplitAssigner (org.apache.flink.core.io.InputSplitAssigner)2 JobException (org.apache.flink.runtime.JobException)2