Search in sources :

Example 6 with ProvisionedThroughputExceededException

use of com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException in project hazelcast by hazelcast.

the class KinesisSinkP method checkIfSendingFinished.

private void checkIfSendingFinished() {
    if (sendResult.isDone()) {
        PutRecordsResult result;
        try {
            result = KinesisUtil.readResult(this.sendResult);
        } catch (ProvisionedThroughputExceededException pte) {
            dealWithThroughputExceeded("Data throughput rate exceeded. Backing off and retrying in %d ms");
            return;
        } catch (SdkClientException sce) {
            dealWithSendFailure(sce);
            return;
        } catch (Throwable t) {
            throw rethrow(t);
        } finally {
            sendResult = null;
        }
        pruneSentFromBuffer(result);
        if (result.getFailedRecordCount() > 0) {
            dealWithThroughputExceeded("Failed to send " + result.getFailedRecordCount() + " (out of " + result.getRecords().size() + ") record(s) to stream '" + stream + "'. Sending will be retried in %d ms, message reordering is likely.");
        } else {
            long sleepTimeNanos = throughputController.markSuccess();
            this.nextSendTime += sleepTimeNanos;
            this.sleepMetric.set(NANOSECONDS.toMillis(sleepTimeNanos));
            sendRetryTracker.reset();
        }
    }
}
Also used : PutRecordsResult(com.amazonaws.services.kinesis.model.PutRecordsResult) SdkClientException(com.amazonaws.SdkClientException) ProvisionedThroughputExceededException(com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException)

Example 7 with ProvisionedThroughputExceededException

use of com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException in project flink by apache.

the class KinesisProxyTest method testIsRecoverableExceptionWithProvisionedThroughputExceeded.

@Test
public void testIsRecoverableExceptionWithProvisionedThroughputExceeded() {
    final ProvisionedThroughputExceededException ex = new ProvisionedThroughputExceededException("asdf");
    ex.setErrorType(ErrorType.Client);
    assertTrue(KinesisProxy.isRecoverableException(ex));
}
Also used : ProvisionedThroughputExceededException(com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException) Test(org.junit.Test)

Example 8 with ProvisionedThroughputExceededException

use of com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException in project druid by druid-io.

the class KinesisRecordSupplier method getSequenceNumber.

/**
 * Given a partition and a {@link ShardIteratorType}, create a shard iterator and fetch
 * {@link #GET_SEQUENCE_NUMBER_RECORD_COUNT} records and return the first sequence number from the result set.
 * This method is thread safe as it does not depend on the internal state of the supplier (it doesn't use the
 * {@link PartitionResource} which have been assigned to the supplier), and the Kinesis client is thread safe.
 */
@Nullable
private String getSequenceNumber(StreamPartition<String> partition, ShardIteratorType iteratorEnum) {
    return wrapExceptions(() -> {
        String shardIterator = kinesis.getShardIterator(partition.getStream(), partition.getPartitionId(), iteratorEnum.toString()).getShardIterator();
        long timeoutMillis = System.currentTimeMillis() + fetchSequenceNumberTimeout;
        GetRecordsResult recordsResult = null;
        while (shardIterator != null && System.currentTimeMillis() < timeoutMillis) {
            if (closed) {
                log.info("KinesisRecordSupplier closed while fetching sequenceNumber");
                return null;
            }
            final String currentShardIterator = shardIterator;
            final GetRecordsRequest request = new GetRecordsRequest().withShardIterator(currentShardIterator).withLimit(GET_SEQUENCE_NUMBER_RECORD_COUNT);
            recordsResult = RetryUtils.retry(() -> kinesis.getRecords(request), (throwable) -> {
                if (throwable instanceof ProvisionedThroughputExceededException) {
                    log.warn(throwable, "encountered ProvisionedThroughputExceededException while fetching records, this means " + "that the request rate for the stream is too high, or the requested data is too large for " + "the available throughput. Reduce the frequency or size of your requests. Consider increasing " + "the number of shards to increase throughput.");
                    return true;
                }
                if (throwable instanceof AmazonClientException) {
                    AmazonClientException ase = (AmazonClientException) throwable;
                    return AWSClientUtil.isClientExceptionRecoverable(ase);
                }
                return false;
            }, GET_SEQUENCE_NUMBER_RETRY_COUNT);
            List<Record> records = recordsResult.getRecords();
            if (!records.isEmpty()) {
                return records.get(0).getSequenceNumber();
            }
            shardIterator = recordsResult.getNextShardIterator();
        }
        if (shardIterator == null) {
            log.info("Partition[%s] returned a null shard iterator, is the shard closed?", partition.getPartitionId());
            return KinesisSequenceNumber.END_OF_SHARD_MARKER;
        }
        // if we reach here, it usually means either the shard has no more records, or records have not been
        // added to this shard
        log.warn("timed out while trying to fetch position for shard[%s], millisBehindLatest is [%s], likely no more records in shard", partition.getPartitionId(), recordsResult != null ? recordsResult.getMillisBehindLatest() : "UNKNOWN");
        return null;
    });
}
Also used : Shard(com.amazonaws.services.kinesis.model.Shard) StreamPartition(org.apache.druid.indexing.seekablestream.common.StreamPartition) ScheduledFuture(java.util.concurrent.ScheduledFuture) AWSClientUtil(org.apache.druid.common.aws.AWSClientUtil) OrderedPartitionableRecord(org.apache.druid.indexing.seekablestream.common.OrderedPartitionableRecord) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) ByteBuffer(java.nio.ByteBuffer) Map(java.util.Map) Method(java.lang.reflect.Method) ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) ImmutableSet(com.google.common.collect.ImmutableSet) Execs(org.apache.druid.java.util.common.concurrent.Execs) AWSSecurityTokenServiceClientBuilder(com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder) AmazonKinesis(com.amazonaws.services.kinesis.AmazonKinesis) ShardIteratorType(com.amazonaws.services.kinesis.model.ShardIteratorType) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StringUtils(org.apache.druid.java.util.common.StringUtils) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) BlockingQueue(java.util.concurrent.BlockingQueue) UUID(java.util.UUID) STSAssumeRoleSessionCredentialsProvider(com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) StreamException(org.apache.druid.indexing.seekablestream.common.StreamException) Queues(com.google.common.collect.Queues) List(java.util.List) ByteEntity(org.apache.druid.data.input.impl.ByteEntity) KinesisSupervisor(org.apache.druid.indexing.kinesis.supervisor.KinesisSupervisor) AmazonClientException(com.amazonaws.AmazonClientException) MethodHandle(java.lang.invoke.MethodHandle) Record(com.amazonaws.services.kinesis.model.Record) RecordSupplier(org.apache.druid.indexing.seekablestream.common.RecordSupplier) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ProvisionedThroughputExceededException(com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) AwsHostNameUtils(com.amazonaws.util.AwsHostNameUtils) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) AWSCredentialsUtils(org.apache.druid.common.aws.AWSCredentialsUtils) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ResourceNotFoundException(com.amazonaws.services.kinesis.model.ResourceNotFoundException) RetryUtils(org.apache.druid.java.util.common.RetryUtils) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) Iterator(java.util.Iterator) InvalidArgumentException(com.amazonaws.services.kinesis.model.InvalidArgumentException) Maps(com.google.common.collect.Maps) AWSCredentialsConfig(org.apache.druid.common.aws.AWSCredentialsConfig) TimeUnit(java.util.concurrent.TimeUnit) ClientConfiguration(com.amazonaws.ClientConfiguration) AmazonKinesisClientBuilder(com.amazonaws.services.kinesis.AmazonKinesisClientBuilder) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ExpiredIteratorException(com.amazonaws.services.kinesis.model.ExpiredIteratorException) Collections(java.util.Collections) GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) AmazonClientException(com.amazonaws.AmazonClientException) OrderedPartitionableRecord(org.apache.druid.indexing.seekablestream.common.OrderedPartitionableRecord) Record(com.amazonaws.services.kinesis.model.Record) ProvisionedThroughputExceededException(com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest) Nullable(javax.annotation.Nullable)

Aggregations

ProvisionedThroughputExceededException (com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException)8 GetRecordsResult (com.amazonaws.services.kinesis.model.GetRecordsResult)5 Record (com.amazonaws.services.kinesis.model.Record)4 ExpiredIteratorException (com.amazonaws.services.kinesis.model.ExpiredIteratorException)3 SdkClientException (com.amazonaws.SdkClientException)2 Map (java.util.Map)2 SourceRecord (org.apache.kafka.connect.source.SourceRecord)2 AmazonClientException (com.amazonaws.AmazonClientException)1 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 STSAssumeRoleSessionCredentialsProvider (com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider)1 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)1 AmazonKinesis (com.amazonaws.services.kinesis.AmazonKinesis)1 AmazonKinesisClientBuilder (com.amazonaws.services.kinesis.AmazonKinesisClientBuilder)1 GetRecordsRequest (com.amazonaws.services.kinesis.model.GetRecordsRequest)1 GetShardIteratorResult (com.amazonaws.services.kinesis.model.GetShardIteratorResult)1 InvalidArgumentException (com.amazonaws.services.kinesis.model.InvalidArgumentException)1 ListShardsRequest (com.amazonaws.services.kinesis.model.ListShardsRequest)1 ListShardsResult (com.amazonaws.services.kinesis.model.ListShardsResult)1 PutRecordsResult (com.amazonaws.services.kinesis.model.PutRecordsResult)1