Source:
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; } try { recordsResult = kinesis.getRecords( new GetRecordsRequest().withShardIterator(shardIterator).withLimit(FETCH_SEQUENCE_NUMBER_RECORD_COUNT) ); } catch (ProvisionedThroughputExceededException e) { log.warn( e, "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." ); try { Thread.sleep(PROVISIONED_THROUGHPUT_EXCEEDED_BACKOFF_MS); continue; } catch (InterruptedException e1) { log.warn(e1, "Thread interrupted!"); Thread.currentThread().interrupt(); break; } } 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; } 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; }); }

Target:
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; } 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; } 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; }); }