m-trieu commented on code in PR #31784:
URL: https://github.com/apache/beam/pull/31784#discussion_r1691658955


##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/windmill/client/getdata/ApplianceGetDataClient.java:
##########
@@ -0,0 +1,253 @@
+/*
+ * 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.dataflow.worker.windmill.client.getdata;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import javax.annotation.concurrent.GuardedBy;
+import javax.annotation.concurrent.ThreadSafe;
+import org.apache.beam.runners.dataflow.worker.WindmillComputationKey;
+import 
org.apache.beam.runners.dataflow.worker.windmill.ApplianceWindmillClient;
+import org.apache.beam.runners.dataflow.worker.windmill.Windmill;
+import 
org.apache.beam.runners.dataflow.worker.windmill.Windmill.ComputationGetDataRequest;
+import 
org.apache.beam.runners.dataflow.worker.windmill.work.refresh.HeartbeatSender;
+import 
org.apache.beam.runners.dataflow.worker.windmill.work.refresh.Heartbeats;
+import org.apache.beam.sdk.annotations.Internal;
+import 
org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions;
+import 
org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Iterables;
+import 
org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.util.concurrent.SettableFuture;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+/** Appliance implementation of {@link GetDataClient}. */
+@Internal
+@ThreadSafe
+public final class ApplianceGetDataClient implements GetDataClient, 
WorkRefreshClient {
+  private static final int MAX_READS_PER_BATCH = 60;
+  private static final int MAX_ACTIVE_READS = 10;
+
+  private final ApplianceWindmillClient windmillClient;
+  private final ThrottlingGetDataMetricTracker getDataMetricTracker;
+
+  @GuardedBy("this")
+  private final List<ReadBatch> pendingReadBatches;
+
+  @GuardedBy("this")
+  private int activeReadThreads;
+
+  public ApplianceGetDataClient(
+      ApplianceWindmillClient windmillClient, ThrottlingGetDataMetricTracker 
getDataMetricTracker) {
+    this.windmillClient = windmillClient;
+    this.getDataMetricTracker = getDataMetricTracker;
+    this.pendingReadBatches = new ArrayList<>();
+    this.activeReadThreads = 0;
+  }
+
+  public static GetDataClient create(
+      ApplianceWindmillClient windmillClient, ThrottlingGetDataMetricTracker 
getDataMetricTracker) {
+    return new ApplianceGetDataClient(windmillClient, getDataMetricTracker);
+  }
+
+  @Override
+  public Windmill.KeyedGetDataResponse getStateData(
+      String computation, Windmill.KeyedGetDataRequest request) {
+    try (AutoCloseable ignored =
+        getDataMetricTracker.trackSingleCallWithThrottling(
+            ThrottlingGetDataMetricTracker.Type.STATE)) {
+      SettableFuture<Windmill.KeyedGetDataResponse> response = 
SettableFuture.create();
+      ReadBatch batch = addToReadBatch(new QueueEntry(computation, request, 
response));
+      if (batch != null) {
+        issueReadBatch(batch);
+      }
+      return response.get();
+    } catch (Exception e) {
+      throw new GetDataException(
+          "Error occurred fetching state for computation="
+              + computation
+              + ", key="
+              + request.getShardingKey(),
+          e);
+    }
+  }
+
+  @Override
+  public Windmill.GlobalData getSideInputData(Windmill.GlobalDataRequest 
request) {
+    try (AutoCloseable ignored =
+        getDataMetricTracker.trackSingleCallWithThrottling(
+            ThrottlingGetDataMetricTracker.Type.STATE)) {

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@beam.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to