Search in sources :

Example 1 with RemoteGrpcPortWriteOperation

use of org.apache.beam.runners.dataflow.worker.fn.data.RemoteGrpcPortWriteOperation in project beam by apache.

the class BeamFnMapTaskExecutor method createProgressTracker.

private ProgressTracker createProgressTracker() {
    ReadOperation readOperation;
    RemoteGrpcPortWriteOperation grpcWriteOperation;
    RegisterAndProcessBundleOperation bundleProcessOperation;
    try {
        readOperation = getReadOperation();
    } catch (Exception exn) {
        readOperation = null;
        LOG.info("Unable to get read operation.", exn);
        return new NullProgressTracker();
    }
    // RegisterAndProcessBundleOperation we know they have the right topology.
    try {
        grpcWriteOperation = Iterables.getOnlyElement(Iterables.filter(operations, RemoteGrpcPortWriteOperation.class));
        bundleProcessOperation = Iterables.getOnlyElement(Iterables.filter(operations, RegisterAndProcessBundleOperation.class));
    } catch (IllegalArgumentException | NoSuchElementException exn) {
        // TODO: Handle more than one sdk worker processing a single bundle.
        grpcWriteOperation = null;
        bundleProcessOperation = null;
        LOG.debug("Does not have exactly one grpcWRite and bundleProcess operation.", exn);
    }
    if (grpcWriteOperation != null && bundleProcessOperation != null) {
        return new SingularProcessBundleProgressTracker(readOperation, grpcWriteOperation, bundleProcessOperation);
    } else {
        return new ReadOperationProgressTracker(readOperation);
    }
}
Also used : ReadOperation(org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation) RemoteGrpcPortWriteOperation(org.apache.beam.runners.dataflow.worker.fn.data.RemoteGrpcPortWriteOperation) CancellationException(java.util.concurrent.CancellationException) NoSuchElementException(java.util.NoSuchElementException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with RemoteGrpcPortWriteOperation

use of org.apache.beam.runners.dataflow.worker.fn.data.RemoteGrpcPortWriteOperation in project beam by apache.

the class BeamFnMapTaskExecutorFactory method createOperationTransformForGrpcPortNodes.

private Function<Node, Node> createOperationTransformForGrpcPortNodes(final Network<Node, Edge> network, final FnDataService beamFnDataService, final OperationContext context) {
    return new TypeSafeNodeFunction<RemoteGrpcPortNode>(RemoteGrpcPortNode.class) {

        @Override
        public Node typedApply(RemoteGrpcPortNode input) {
            RegisterAndProcessBundleOperation registerFnOperation = (RegisterAndProcessBundleOperation) Iterables.getOnlyElement(Iterables.filter(network.adjacentNodes(input), OperationNode.class)).getOperation();
            // The coder comes from the one and only adjacent output node
            Coder<?> coder = Iterables.getOnlyElement(Iterables.filter(network.adjacentNodes(input), OutputReceiverNode.class)).getCoder();
            // We figure out whether we are outputting some where if the output node is a
            // successor.
            Iterable<OutputReceiverNode> outputReceiverNodes = Iterables.filter(network.successors(input), OutputReceiverNode.class);
            Operation operation;
            if (outputReceiverNodes.iterator().hasNext()) {
                OutputReceiver[] outputReceivers = new OutputReceiver[] { Iterables.getOnlyElement(outputReceiverNodes).getOutputReceiver() };
                operation = new RemoteGrpcPortReadOperation<>(beamFnDataService, input.getPrimitiveTransformId(), registerFnOperation::getProcessBundleInstructionId, (Coder) coder, outputReceivers, context);
            } else {
                operation = new RemoteGrpcPortWriteOperation<>(beamFnDataService, input.getPrimitiveTransformId(), registerFnOperation::getProcessBundleInstructionId, (Coder) coder, context);
            }
            return OperationNode.create(operation);
        }
    };
}
Also used : WindowedValueCoder(org.apache.beam.sdk.util.WindowedValue.WindowedValueCoder) KvCoder(org.apache.beam.sdk.coders.KvCoder) Coder(org.apache.beam.sdk.coders.Coder) RemoteGrpcPortNode(org.apache.beam.runners.dataflow.worker.graph.Nodes.RemoteGrpcPortNode) OutputReceiver(org.apache.beam.runners.dataflow.worker.util.common.worker.OutputReceiver) FlattenOperation(org.apache.beam.runners.dataflow.worker.util.common.worker.FlattenOperation) ParDoOperation(org.apache.beam.runners.dataflow.worker.util.common.worker.ParDoOperation) ReadOperation(org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation) WriteOperation(org.apache.beam.runners.dataflow.worker.util.common.worker.WriteOperation) RemoteGrpcPortReadOperation(org.apache.beam.runners.dataflow.worker.fn.data.RemoteGrpcPortReadOperation) RegisterAndProcessBundleOperation(org.apache.beam.runners.dataflow.worker.fn.control.RegisterAndProcessBundleOperation) RemoteGrpcPortWriteOperation(org.apache.beam.runners.dataflow.worker.fn.data.RemoteGrpcPortWriteOperation) ProcessRemoteBundleOperation(org.apache.beam.runners.dataflow.worker.fn.control.ProcessRemoteBundleOperation) Operation(org.apache.beam.runners.dataflow.worker.util.common.worker.Operation) RegisterAndProcessBundleOperation(org.apache.beam.runners.dataflow.worker.fn.control.RegisterAndProcessBundleOperation) OutputReceiverNode(org.apache.beam.runners.dataflow.worker.graph.Nodes.OutputReceiverNode) OperationNode(org.apache.beam.runners.dataflow.worker.graph.Nodes.OperationNode) TypeSafeNodeFunction(org.apache.beam.runners.dataflow.worker.graph.Networks.TypeSafeNodeFunction)

Example 3 with RemoteGrpcPortWriteOperation

use of org.apache.beam.runners.dataflow.worker.fn.data.RemoteGrpcPortWriteOperation in project beam by apache.

the class SingularProcessBundleProgressTrackerTest method testProgressInterpolation.

@Test
public void testProgressInterpolation() throws Exception {
    ReadOperation read = Mockito.mock(ReadOperation.class);
    RemoteGrpcPortWriteOperation grpcWrite = Mockito.mock(RemoteGrpcPortWriteOperation.class);
    RegisterAndProcessBundleOperation process = Mockito.mock(RegisterAndProcessBundleOperation.class);
    when(grpcWrite.processedElementsConsumer()).thenReturn(elementsConsumed -> {
    });
    SingularProcessBundleProgressTracker tracker = new SingularProcessBundleProgressTracker(read, grpcWrite, process);
    when(read.getProgress()).thenReturn(new TestProgress("A"), new TestProgress("B"), new TestProgress("C"));
    when(grpcWrite.getElementsSent()).thenReturn(1, 10, 20, 30);
    // This test ignores them, directly working on mocked getInputElementsConsumed
    when(process.getProcessBundleProgress()).thenReturn(CompletableFuture.completedFuture(BeamFnApi.ProcessBundleProgressResponse.getDefaultInstance()));
    when(process.getInputElementsConsumed(any(Iterable.class))).thenReturn(1L, 4L, 10L).thenThrow(new RuntimeException());
    // Initially no progress is known.
    assertEquals(null, tracker.getWorkerProgress());
    // After reading, and writing, and processing one element, the progress is aligned at A.
    tracker.updateProgress();
    assertEquals(new TestProgress("A"), tracker.getWorkerProgress());
    // We've read up to B (10 elements) but only consumed 4.  Progress remains at A.
    tracker.updateProgress();
    assertEquals(new TestProgress("A"), tracker.getWorkerProgress());
    // Once 10 elements have been consumed, advance to B.
    tracker.updateProgress();
    assertEquals(new TestProgress("B"), tracker.getWorkerProgress());
    // An exception is thrown, default to latest read progress.
    tracker.updateProgress();
    assertEquals(new TestProgress("C"), tracker.getWorkerProgress());
}
Also used : ReadOperation(org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation) SingularProcessBundleProgressTracker(org.apache.beam.runners.dataflow.worker.fn.control.BeamFnMapTaskExecutor.SingularProcessBundleProgressTracker) RemoteGrpcPortWriteOperation(org.apache.beam.runners.dataflow.worker.fn.data.RemoteGrpcPortWriteOperation) Test(org.junit.Test)

Aggregations

RemoteGrpcPortWriteOperation (org.apache.beam.runners.dataflow.worker.fn.data.RemoteGrpcPortWriteOperation)3 ReadOperation (org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation)3 NoSuchElementException (java.util.NoSuchElementException)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 SingularProcessBundleProgressTracker (org.apache.beam.runners.dataflow.worker.fn.control.BeamFnMapTaskExecutor.SingularProcessBundleProgressTracker)1 ProcessRemoteBundleOperation (org.apache.beam.runners.dataflow.worker.fn.control.ProcessRemoteBundleOperation)1 RegisterAndProcessBundleOperation (org.apache.beam.runners.dataflow.worker.fn.control.RegisterAndProcessBundleOperation)1 RemoteGrpcPortReadOperation (org.apache.beam.runners.dataflow.worker.fn.data.RemoteGrpcPortReadOperation)1 TypeSafeNodeFunction (org.apache.beam.runners.dataflow.worker.graph.Networks.TypeSafeNodeFunction)1 OperationNode (org.apache.beam.runners.dataflow.worker.graph.Nodes.OperationNode)1 OutputReceiverNode (org.apache.beam.runners.dataflow.worker.graph.Nodes.OutputReceiverNode)1 RemoteGrpcPortNode (org.apache.beam.runners.dataflow.worker.graph.Nodes.RemoteGrpcPortNode)1 FlattenOperation (org.apache.beam.runners.dataflow.worker.util.common.worker.FlattenOperation)1 Operation (org.apache.beam.runners.dataflow.worker.util.common.worker.Operation)1 OutputReceiver (org.apache.beam.runners.dataflow.worker.util.common.worker.OutputReceiver)1 ParDoOperation (org.apache.beam.runners.dataflow.worker.util.common.worker.ParDoOperation)1 WriteOperation (org.apache.beam.runners.dataflow.worker.util.common.worker.WriteOperation)1 Coder (org.apache.beam.sdk.coders.Coder)1 KvCoder (org.apache.beam.sdk.coders.KvCoder)1