-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BEAM-8382] Add polling interval to KinesisIO.Read
- Loading branch information
1 parent
a005fd7
commit 1a1b6bb
Showing
11 changed files
with
219 additions
and
14 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...kinesis/src/main/java/org/apache/beam/sdk/io/kinesis/KinesisClientThrottledException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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.kinesis; | ||
|
||
import com.amazonaws.AmazonClientException; | ||
|
||
/** Thrown when the Kinesis client was throttled due to rate limits. */ | ||
class KinesisClientThrottledException extends TransientKinesisException { | ||
|
||
public KinesisClientThrottledException(String s, AmazonClientException e) { | ||
super(s, e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
sdks/java/io/kinesis/src/main/java/org/apache/beam/sdk/io/kinesis/RateLimitPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.kinesis; | ||
|
||
import java.util.List; | ||
|
||
public interface RateLimitPolicy { | ||
|
||
/** | ||
* Called after Kinesis records are successfully retrieved. | ||
* | ||
* @param records The list of retrieved records. | ||
*/ | ||
default void onSuccess(List<KinesisRecord> records) throws InterruptedException {} | ||
|
||
/** | ||
* Called after the Kinesis client is throttled. | ||
* | ||
* @param e The {@code KinesisClientThrottledException} thrown by the client. | ||
*/ | ||
default void onThrottle(KinesisClientThrottledException e) throws InterruptedException {} | ||
} |
63 changes: 63 additions & 0 deletions
63
.../java/io/kinesis/src/main/java/org/apache/beam/sdk/io/kinesis/RateLimitPolicyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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.kinesis; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
import org.joda.time.Duration; | ||
|
||
/** | ||
* Implement this interface to create a {@code RateLimitPolicy}. Used to create a rate limiter for | ||
* each shard. | ||
*/ | ||
public interface RateLimitPolicyFactory extends Serializable { | ||
|
||
RateLimitPolicy getRateLimitPolicy(); | ||
|
||
static RateLimitPolicyFactory withoutLimiter() { | ||
return () -> new RateLimitPolicy() {}; | ||
} | ||
|
||
static RateLimitPolicyFactory withFixedDelay() { | ||
return FixedDelayRateLimiter::new; | ||
} | ||
|
||
static RateLimitPolicyFactory withFixedDelay(Duration delay) { | ||
return () -> new FixedDelayRateLimiter(delay); | ||
} | ||
|
||
class FixedDelayRateLimiter implements RateLimitPolicy { | ||
|
||
private static final Duration DEFAULT_DELAY = Duration.standardSeconds(1); | ||
|
||
private final Duration delay; | ||
|
||
public FixedDelayRateLimiter() { | ||
this(DEFAULT_DELAY); | ||
} | ||
|
||
public FixedDelayRateLimiter(Duration delay) { | ||
this.delay = delay; | ||
} | ||
|
||
@Override | ||
public void onSuccess(List<KinesisRecord> records) throws InterruptedException { | ||
Thread.sleep(delay.getMillis()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.