m-trieu commented on code in PR #28537: URL: https://github.com/apache/beam/pull/28537#discussion_r1333626158
########## runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/streaming/ComputationState.java: ########## @@ -0,0 +1,276 @@ +/* + * 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.streaming; + +import com.google.api.services.dataflow.model.MapTask; +import java.io.PrintWriter; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; +import javax.annotation.Nullable; +import org.apache.beam.runners.dataflow.worker.WindmillStateCache; +import org.apache.beam.runners.dataflow.worker.util.BoundedQueueExecutor; +import org.apache.beam.runners.dataflow.worker.windmill.Windmill; +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.ImmutableMap; +import org.joda.time.Duration; +import org.joda.time.Instant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Class representing the state of a computation. + * + * <p>This class is synchronized, but only used from the dispatch and commit threads, so should not + * be heavily contended. Still, blocking work should not be done by it. + */ +public class ComputationState implements AutoCloseable { + + private static final Logger LOG = LoggerFactory.getLogger(ComputationState.class); + + // The max number of keys in COMMITTING or COMMIT_QUEUED status to be shown. + private static final int MAX_PRINTABLE_COMMIT_PENDING_KEYS = 50; + + private final String computationId; + private final MapTask mapTask; + private final ImmutableMap<String, String> transformUserNameToStateFamily; + // Map from key to work for the key. The first item in the queue is + // actively processing. Synchronized by itself. + private final Map<ShardedKey, Deque<Work>> activeWork = new HashMap<>(); + private final BoundedQueueExecutor executor; + private final ConcurrentLinkedQueue<ExecutionState> executionStateQueue = + new ConcurrentLinkedQueue<>(); + private final WindmillStateCache.ForComputation computationStateCache; + + public ComputationState( + String computationId, + MapTask mapTask, + BoundedQueueExecutor executor, + Map<String, String> transformUserNameToStateFamily, + WindmillStateCache.ForComputation computationStateCache) { + this.computationId = computationId; + this.mapTask = mapTask; + this.executor = executor; + this.transformUserNameToStateFamily = + transformUserNameToStateFamily != null 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
