[
https://issues.apache.org/jira/browse/BEAM-3327?focusedWorklogId=92875&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-92875
]
ASF GitHub Bot logged work on BEAM-3327:
----------------------------------------
Author: ASF GitHub Bot
Created on: 19/Apr/18 21:57
Start Date: 19/Apr/18 21:57
Worklog Time Spent: 10m
Work Description: jkff commented on a change in pull request #5189:
[BEAM-3327] Basic Docker environment factory
URL: https://github.com/apache/beam/pull/5189#discussion_r182896323
##########
File path:
runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/control/MapControlClientPool.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.control;
+
+import com.google.common.collect.Maps;
+import java.time.Duration;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import javax.annotation.concurrent.GuardedBy;
+
+/**
+ * A {@link ControlClientPool} backed by a client map. It is expected that a
given client id will be
+ * requested at most once.
+ */
+public class MapControlClientPool implements ControlClientPool {
+
+ /** Creates a {@link MapControlClientPool} with an unspecified timeout. */
+ public static MapControlClientPool create() {
+ return withTimeout(Duration.ofSeconds(Long.MAX_VALUE));
+ }
+
+ /**
+ * Creates a {@link MapControlClientPool} with the given timeout. Timeouts
only apply to source
+ * requests.
+ */
+ public static MapControlClientPool withTimeout(Duration timeout) {
+ return new MapControlClientPool(timeout);
+ }
+
+ private final Duration timeout;
+ private final Object lock = new Object();
+
+ @GuardedBy("lock")
+ private final Map<String, CompletableFuture<InstructionRequestHandler>>
clients =
+ Maps.newHashMap();
+
+ private MapControlClientPool(Duration timeout) {
+ this.timeout = timeout;
+ }
+
+ @Override
+ public ControlClientSource getSource() {
+ return this::getClient;
+ }
+
+ @Override
+ public ControlClientSink getSink() {
+ return this::putClient;
+ }
+
+ private void putClient(String workerId, InstructionRequestHandler client) {
+ synchronized (lock) {
+ CompletableFuture<InstructionRequestHandler> future =
+ clients.computeIfAbsent(workerId,
MapControlClientPool::createClientFuture);
+ boolean success = future.complete(client);
+ if (!success) {
+ throw new IllegalStateException(
+ String.format("Control client for worker id %s failed to compete",
workerId));
+ }
+ }
+ }
+
+ private InstructionRequestHandler getClient(String workerId)
+ throws ExecutionException, InterruptedException, TimeoutException {
+ CompletableFuture<InstructionRequestHandler> future;
+ synchronized (lock) {
+ future = clients.computeIfAbsent(workerId,
MapControlClientPool::createClientFuture);
+ }
+ // TODO: Wire in health checking of clients so requests don't hang.
+ future.get(timeout.getSeconds(), TimeUnit.SECONDS);
Review comment:
<!--new_thread; commit:1fd121da1417624b3b84f0300648251da64b9cb5;
resolved:0-->
What exactly are we waiting for here: are we waiting for a matching
put(workerId, _) call? When can there happen a getClient(workerId) call for a
workerId that hasn't been put() yet?
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 92875)
Time Spent: 10h 50m (was: 10h 40m)
> Add abstractions to manage Environment Instance lifecycles.
> -----------------------------------------------------------
>
> Key: BEAM-3327
> URL: https://issues.apache.org/jira/browse/BEAM-3327
> Project: Beam
> Issue Type: New Feature
> Components: runner-core
> Reporter: Thomas Groh
> Assignee: Ben Sidhom
> Priority: Major
> Labels: portability
> Time Spent: 10h 50m
> Remaining Estimate: 0h
>
> This permits remote stage execution for arbitrary environments
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)