aqibmehmoodDH commented on code in PR #255:
URL:
https://github.com/apache/flink-connector-aws/pull/255#discussion_r4739933248
##########
flink-connector-aws/flink-connector-aws-kinesis-streams/src/main/java/org/apache/flink/connector/kinesis/source/reader/fanout/StreamConsumerRegistrar.java:
##########
@@ -143,6 +144,90 @@ public void deregisterStreamConsumer() {
}
}
+ /**
+ * Ensures an EFO consumer exists and is {@code ACTIVE}: waits out any
in-progress {@code
+ * DELETING}, then registers if missing. A concurrent {@link
ResourceInUseException} on register
+ * is treated as another caller winning the same race, not an error.
+ *
+ * @throws KinesisStreamsSourceException if it never reaches {@code
ACTIVE} within {@code
+ * maxAttempts}.
+ */
+ public static String ensureActiveConsumer(
+ StreamProxy kinesisStreamProxy,
+ String streamArn,
+ String consumerName,
+ Duration baseDelay,
+ Duration maxDelay,
+ int maxAttempts) {
+ for (int attempt = 1; ; attempt++) {
+ ConsumerStatus status;
+ String consumerArn;
+ try {
+ DescribeStreamConsumerResponse response =
+ kinesisStreamProxy.describeStreamConsumer(streamArn,
consumerName);
+ status = response.consumerDescription().consumerStatus();
+ consumerArn = response.consumerDescription().consumerARN();
+ } catch (ResourceNotFoundException e) {
+ status = null;
+ consumerArn = null;
+ }
+
+ if (status == ConsumerStatus.ACTIVE) {
+ return consumerArn;
+ }
+
+ if (status == null) {
+ try {
+ LOG.info("Registering stream consumer - {}::{}",
streamArn, consumerName);
+ kinesisStreamProxy.registerStreamConsumer(streamArn,
consumerName);
+ } catch (ResourceInUseException e) {
+ LOG.info(
+ "EFO consumer '{}' on stream {} appeared
concurrently while "
+ + "registering; waiting for it to become
ACTIVE.",
+ consumerName,
+ streamArn);
+ }
+ } else {
+ LOG.info(
+ "EFO consumer '{}' on stream {} is {}; waiting before
re-checking.",
+ consumerName,
+ streamArn,
+ status);
+ }
+
+ if (attempt >= maxAttempts) {
+ throw new KinesisStreamsSourceException(
+ "EFO consumer '"
+ + consumerName
+ + "' on stream "
+ + streamArn
+ + " did not become ACTIVE after "
+ + maxAttempts
+ + " attempts.",
+ null);
+ }
+
+ sleepUninterruptibly(computeBackoffMillis(baseDelay, maxDelay,
attempt));
+ }
+ }
+
+ /** Full-jitter exponential backoff: random duration between 0 and
min(base*2^(n-1), max). */
Review Comment:
Done. Both StreamConsumerRegistrar and FanOutKinesisShardSubscription now
use the SDK's FullJitterBackoffStrategy, and the custom helpers are removed
--
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]