m-trieu commented on code in PR #30312: URL: https://github.com/apache/beam/pull/30312#discussion_r1508297252
########## runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/windmill/client/CloseableStream.java: ########## @@ -0,0 +1,47 @@ +/* + * 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; + +import com.google.auto.value.AutoValue; +import java.util.function.Supplier; + +/** + * Wrapper for a {@link WindmillStream} that allows callers to tie an action after the stream is + * finished being used. Has an option for closing code to be a no-op. + */ +@AutoValue +public abstract class CloseableStream<StreamT extends WindmillStream> implements AutoCloseable { + public static <StreamT extends WindmillStream> CloseableStream<StreamT> create( + Supplier<StreamT> stream, Runnable onClose) { + return new AutoValue_CloseableStream<>(stream, onClose); + } + + public static <StreamT extends WindmillStream> CloseableStream<StreamT> create( + Supplier<StreamT> stream) { + return create(stream, () -> {}); + } + + public abstract Supplier<StreamT> stream(); Review Comment: done ########## runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/windmill/client/commits/StreamingApplianceWorkCommitter.java: ########## @@ -0,0 +1,183 @@ +/* + * 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.commits; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Consumer; +import java.util.function.Supplier; +import javax.annotation.concurrent.ThreadSafe; +import org.apache.beam.runners.dataflow.worker.streaming.ComputationState; +import org.apache.beam.runners.dataflow.worker.streaming.ShardedKey; +import org.apache.beam.runners.dataflow.worker.streaming.WeightedBoundedQueue; +import org.apache.beam.runners.dataflow.worker.streaming.Work; +import org.apache.beam.runners.dataflow.worker.streaming.WorkId; +import org.apache.beam.runners.dataflow.worker.windmill.Windmill; +import org.apache.beam.runners.dataflow.worker.windmill.Windmill.CommitWorkRequest; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.util.concurrent.ThreadFactoryBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Streaming appliance implementation of {@link WorkCommitter}. */ +@ThreadSafe +final class StreamingApplianceWorkCommitter implements WorkCommitter { + private static final Logger LOG = LoggerFactory.getLogger(StreamingApplianceWorkCommitter.class); + private static final long TARGET_COMMIT_BUNDLE_BYTES = 32 << 20; + + private final Consumer<CommitWorkRequest> commitWork; + private final WeightedBoundedQueue<Commit> commitQueue; + private final ExecutorService commitWorkers; + private final AtomicLong activeCommitBytes; + private final Supplier<Boolean> shouldCommitWork; + private final int numCommitWorkers; + + private StreamingApplianceWorkCommitter( + Consumer<CommitWorkRequest> commitWork, + int numCommitWorkers, + Supplier<Boolean> shouldCommitWork) { + this.commitWork = commitWork; + this.commitQueue = + WeightedBoundedQueue.create( + MAX_COMMIT_QUEUE_BYTES, commit -> Math.min(MAX_COMMIT_QUEUE_BYTES, commit.getSize())); + this.commitWorkers = + Executors.newFixedThreadPool( 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]
