psolomin commented on code in PR #23540: URL: https://github.com/apache/beam/pull/23540#discussion_r1068444521
########## sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/kinesis/enhancedfanout/ShardSubscriberImpl.java: ########## @@ -0,0 +1,275 @@ +/* + * 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.sdk.io.aws2.kinesis.enhancedfanout; + +import java.util.List; +import java.util.UUID; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import org.apache.beam.sdk.io.aws2.kinesis.KinesisRecord; +import org.apache.beam.sdk.io.aws2.kinesis.enhancedfanout.signals.ConsumerError; +import org.apache.beam.sdk.io.aws2.kinesis.enhancedfanout.signals.RecoverableConsumerError; +import org.apache.beam.sdk.io.aws2.kinesis.enhancedfanout.signals.ShardEventWrapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.services.kinesis.model.StartingPosition; +import software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent; +import software.amazon.awssdk.services.kinesis.model.SubscribeToShardRequest; +import software.amazon.awssdk.services.kinesis.model.SubscribeToShardResponseHandler; +import software.amazon.kinesis.retrieval.AggregatorUtil; +import software.amazon.kinesis.retrieval.KinesisClientRecord; + +class ShardSubscriberImpl implements ShardSubscriber { + private static final Logger LOG = LoggerFactory.getLogger(ShardSubscriberImpl.class); + private final String shardId; + private final Config config; + private final BlockingQueue<ShardEventWrapper> shardEventsBuffer = new LinkedBlockingQueue<>(2); + private final AtomicBoolean isRunning = new AtomicBoolean(false); + private final ShardSubscribersPool pool; + private final ShardSubscribersPoolState state; + private final RecordsBuffer recordsBuffer; + private final AsyncClientProxy asyncClientProxy; + + ShardSubscriberImpl( + Config config, + String shardId, + AsyncClientProxy asyncClientProxy, + ShardSubscribersPool pool, + ShardSubscribersPoolState initialState, + RecordsBuffer recordsBuffer) { + this.config = config; + this.shardId = shardId; + this.state = initialState; + this.pool = pool; + this.recordsBuffer = recordsBuffer; + this.isRunning.set(true); + this.asyncClientProxy = asyncClientProxy; + } + + @Override + public void run() { + while (isRunning.get()) { + try { + ShardCheckpoint shardCheckpoint = state.getCheckpoint(shardId); + boolean reSubscribe = subscribe(shardCheckpoint.toStartingPosition(), this::consume); Review Comment: > E.g. if the downstream of the Beam Kinesis reader is very slow Looks like something not hard to simulate and check if the system degrades cleanly. -- 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]
