Client library for Amazon Kinesis
Find a file
Aravinda Kidambi Srinivasan 16e8404dc4
Fix a race condition between ShardConsumer shutdown and initialization (#1319)
* Fix a race condition between ShardConsumer shutdown and initialization

When Kinesis shards have no data, there can be a race condition where
the shard-end record processing from RecordProcessorThread
interleaves with Scheduler performing initialization.
This leads to ShardConsumer making incorrect state transition
during initialization (moves from PROCESSING -> SHUTTING_DOWN) state
and during shutdown handling it moves from SHUTTING_DOWN -> SHUTDOWN_COMPLETE
without running the ShutdownTask.

This can cause the ShardConsumer to not perform proper shutdown
processing that is required for a child shard processing
to be unblocked. So the child shard could be blocked forever unless the
lease for the parent shard moves to a new worker and that worker does
not run into the race condition.

This patch fixes the race condition as follows:

The intializationComplete invocation is not needed after
needsInitialization has been set to false. Because initializationComplete
is mean to perform initialization in an async manner, but once
its done, the async task is a no-op in happy-path, but it can
perform incorrect state transition during a race condition.
2024-05-02 14:54:59 -07:00
.github Create script to check for backwards compatibility (#1316) 2024-04-19 14:01:04 -07:00
amazon-kinesis-client Fix a race condition between ShardConsumer shutdown and initialization (#1319) 2024-05-02 14:54:59 -07:00
amazon-kinesis-client-multilang Add snapshot to version 2.6.1-SNAPSHOT (#1324) 2024-05-01 17:54:42 -07:00
checkstyle Checkstyle: tightened LineLength restriction from 170 to 150. (#1158) 2023-07-06 10:24:14 -07:00
docs Added doc for leases and the lease lifecycle. (#1218) 2023-11-10 14:56:15 -05:00
formatter Release 2.0.0 of the Amazon Kinesis Client for Java 2018-08-02 12:19:46 -07:00
META-INF Release 2.0.0 of the Amazon Kinesis Client for Java 2018-08-02 12:19:46 -07:00
.gitignore Removed a .swp file, and updated .gitignore. (#1043) 2023-02-27 10:02:36 -08:00
.travis.yml Advance version, and drop Java 7 support (#176) 2017-07-20 12:03:34 -07:00
CHANGELOG.md Preparation for v2.6.0 (#1323) 2024-05-01 17:48:25 -07:00
CODE_OF_CONDUCT.md Adding standard files (#302) 2018-02-26 10:31:55 -08:00
CONTRIBUTING.md Adding standard files (#302) 2018-02-26 10:31:55 -08:00
LICENSE.txt Updating license to Apache License 2.0 (#523) 2019-04-05 15:25:09 -07:00
NOTICE.txt Added Time Based Iterator Support 2016-08-11 09:20:25 -07:00
pom.xml Add snapshot to version 2.6.1-SNAPSHOT (#1324) 2024-05-01 17:54:42 -07:00
README.md Preparation for v2.6.0 (#1323) 2024-05-01 17:48:25 -07:00

Amazon Kinesis Client Library for Java

Build Status

The Amazon Kinesis Client Library for Java (Amazon KCL) enables Java developers to easily consume and process data from Amazon Kinesis.

⚠️ We recommend customers to migrate to 1.14.1 or newer to avoid known bugs in 1.14.0 version

⚠️ It's highly recommended for users of version 2.0 of the Amazon Kinesis Client to upgrade to version 2.0.3 or later. A bug has been identified in versions prior to 2.0.3 that could cause records to be delivered to the wrong record processor.

Amazon Kinesis Client versions 1.x are not impacted.

Please open an issue if you have any questions.

Features

  • Provides an easy-to-use programming model for processing data using Amazon Kinesis
  • Helps with scale-out and fault-tolerant processing

Getting Started

  1. Sign up for AWS — Before you begin, you need an AWS account. For more information about creating an AWS account and retrieving your AWS credentials, see AWS Account and Credentials in the AWS SDK for Java Developer Guide.
  2. Sign up for Amazon Kinesis — Go to the Amazon Kinesis console to sign up for the service and create an Amazon Kinesis stream. For more information, see Create an Amazon Kinesis Stream in the Amazon Kinesis Developer Guide.
  3. Minimum requirements — To use the Amazon Kinesis Client Library, you'll need Java 1.8+. For more information about Amazon Kinesis Client Library requirements, see Before You Begin in the Amazon Kinesis Developer Guide.
  4. Using the Amazon Kinesis Client Library — The best way to get familiar with the Amazon Kinesis Client Library is to read Developing Record Consumer Applications in the Amazon Kinesis Developer Guide.

Building from Source

After you've downloaded the code from GitHub, you can build it using Maven. To disable GPG signing in the build, use this command: mvn clean install -Dgpg.skip=true. Note: This command does not run integration tests.

To disable running unit tests in the build, add the property -Dskip.ut=true.

Running Integration Tests

Note that running integration tests creates AWS resources. Integration tests require valid AWS credentials. This will look for a default AWS profile specified in your local .aws/credentials. To run all integration tests: mvn verify -DskipITs=false. To run one integration tests, specify the integration test class: mvn -Dit.test="BasicStreamConsumerIntegrationTest" -DskipITs=false verify Optionally, you can provide the name of an IAM user/role to run tests with as a string using this command: mvn -DskipITs=false -DawsProfile="<PROFILE_NAME>" verify.

Integration with the Kinesis Producer Library

For producer-side developers using the Kinesis Producer Library (KPL), the KCL integrates without additional effort. When the KCL retrieves an aggregated Amazon Kinesis record consisting of multiple KPL user records, it will automatically invoke the KPL to extract the individual user records before returning them to the user.

Amazon KCL support for other languages

To make it easier for developers to write record processors in other languages, we have implemented a Java based daemon, called MultiLangDaemon that does all the heavy lifting. Our approach has the daemon spawn a sub-process, which in turn runs the record processor, which can be written in any language. The MultiLangDaemon process and the record processor sub-process communicate with each other over STDIN and STDOUT using a defined protocol. There will be a one to one correspondence amongst record processors, child processes, and shards. For Python developers specifically, we have abstracted these implementation details away and expose an interface that enables you to focus on writing record processing logic in Python. This approach enables KCL to be language agnostic, while providing identical features and similar parallel processing model across all languages.

Using the KCL

The recommended way to use the KCL for Java is to consume it from Maven.

Version 2.x

<dependency>
    <groupId>software.amazon.kinesis</groupId>
    <artifactId>amazon-kinesis-client</artifactId>
    <version>2.6.0</version>
</dependency>

Version 1.x

Version 1.x tracking branch

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>amazon-kinesis-client</artifactId>
    <version>1.14.1</version>
</dependency>

Release Notes

KCL Version Changelog
2.x master/CHANGELOG.md
1.x v1.x/CHANGELOG.md