[ 
https://issues.apache.org/jira/browse/BEAM-3676?focusedWorklogId=81462&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-81462
 ]

ASF GitHub Bot logged work on BEAM-3676:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Mar/18 00:42
            Start Date: 17/Mar/18 00:42
    Worklog Time Spent: 10m 
      Work Description: lukecwik commented on a change in pull request #4884: 
[BEAM-3676] Add Portable State Service 
URL: https://github.com/apache/beam/pull/4884#discussion_r175240862
 
 

 ##########
 File path: 
runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/state/GrpcStateService.java
 ##########
 @@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.fnexecution.state;
+
+import static com.google.common.base.Throwables.getStackTraceAsString;
+
+import io.grpc.stub.StreamObserver;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.beam.model.fnexecution.v1.BeamFnApi.StateRequest;
+import org.apache.beam.model.fnexecution.v1.BeamFnApi.StateResponse;
+import org.apache.beam.model.fnexecution.v1.BeamFnStateGrpc;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** An implementation of the Beam Fn State service. */
+public class GrpcStateService extends BeamFnStateGrpc.BeamFnStateImplBase 
implements StateService {
+  private static final Logger LOG = 
LoggerFactory.getLogger(GrpcStateService.class);
+  private final ConcurrentHashMap<String, StateRequestHandler>
+      requestHandlers;
+
+  public GrpcStateService()
+      throws Exception {
+    this.requestHandlers = new ConcurrentHashMap<>();
+  }
+
+  @Override
+  public void close() throws Exception {
+    // TODO: Track multiple clients and disconnect them cleanly instead of 
forcing termination
+  }
+
+  @Override
+  public StreamObserver<StateRequest> state(StreamObserver<StateResponse> 
responseObserver) {
+    return new Inbound(responseObserver);
+  }
+
+  @Override
+  public AutoCloseable registerForProcessBundleInstructionId(
+      String processBundleInstructionId, StateRequestHandler handler) {
+    requestHandlers.put(processBundleInstructionId, handler);
+    return () -> requestHandlers.remove(processBundleInstructionId);
+  }
+
+  /**
+   * An inbound {@link StreamObserver} which delegates requests to registered 
handlers.
+   *
+   * <p>TODO: Handle when the client indicates completion or an error on the 
inbound stream and
+   * there are pending requests.
+   */
+  private class Inbound implements StreamObserver<StateRequest> {
+    private final StreamObserver<StateResponse> outboundObserver;
+
+    Inbound(StreamObserver<StateResponse> outboundObserver) {
+      this.outboundObserver = outboundObserver;
+    }
+
+    @Override
+    public void onNext(StateRequest request) {
+      CompletionStage<StateResponse.Builder> responseStage = new 
CompletableFuture<>();
+      responseStage.whenCompleteAsync(
+          (StateResponse.Builder responseBuilder, Throwable t) ->
+              outboundObserver.onNext(
 
 Review comment:
   Add a comment that this isn't thread safe since the outboundObserver isn't 
thread safe.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 81462)

> FlinkRunner: Portable state service
> -----------------------------------
>
>                 Key: BEAM-3676
>                 URL: https://issues.apache.org/jira/browse/BEAM-3676
>             Project: Beam
>          Issue Type: Sub-task
>          Components: runner-flink
>            Reporter: Ben Sidhom
>            Assignee: Axel Magnuson
>            Priority: Major
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> The State API is an implementation of BeamFnState that exposes pipeline state 
> to SDK harnesses. Because it is used for side inputs, this service will also 
> need to be tied into side inputs/outputs during the translation phase.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to