Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KinesisIO throwing NullPointerException when progress check made before starting reader #26953

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
## Bugfixes

* Fixed X (Java/Python) ([#X](https://github.com/apache/beam/issues/X)).
* Fixed KinesisIO `NullPointerException` when a progress check is made before the reader is started (IO) ([#23868](https://github.com/apache/beam/issues/23868))

## Known Issues

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.util.NoSuchElementException;
import org.apache.beam.sdk.io.UnboundedSource;
import org.apache.beam.sdk.io.UnboundedSource.UnboundedReader;
import org.apache.beam.sdk.io.aws2.kinesis.KinesisIO.Read;
import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
import org.joda.time.Duration;
Expand Down Expand Up @@ -159,6 +160,11 @@ public UnboundedSource.CheckpointMark getCheckpointMark() {
*/
@Override
public long getSplitBacklogBytes() {
// Safety check in case a progress check is made for the start method is called.
if (shardReadersPool == null) {
return UnboundedReader.BACKLOG_UNKNOWN;
}

Instant latestRecordTimestamp = shardReadersPool.getLatestRecordTimestamp();

if (latestRecordTimestamp.equals(BoundedWindow.TIMESTAMP_MIN_VALUE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.util.NoSuchElementException;
import org.apache.beam.sdk.io.UnboundedSource;
import org.apache.beam.sdk.io.UnboundedSource.UnboundedReader;
import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
import org.joda.time.Duration;
import org.joda.time.Instant;
Expand Down Expand Up @@ -150,6 +151,11 @@ public void getSplitBacklogBytesShouldReturnLastSeenValueWhenKinesisExceptionsOc
assertThat(reader.getSplitBacklogBytes()).isEqualTo(20);
}

@Test
public void getSplitBacklogBytesShouldReturnUnknownIfNotStarted() {
assertThat(reader.getSplitBacklogBytes()).isEqualTo(UnboundedReader.BACKLOG_UNKNOWN);
}

@Test
public void getSplitBacklogBytesShouldReturnLastSeenValueWhenCalledFrequently()
throws TransientKinesisException, IOException {
Expand Down