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

Phasers on stun: Unnecessary but fun concurrency synchronisation for KCL v3 #57

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rtyley
Copy link
Member

@rtyley rtyley commented Jan 28, 2025

I wrote this code when working on #56 - the slightly ambiguous wording in the migration notes for KCL v3 suggested to me that this concurrency synchronisation might be necessary, but later I grew uncertain and performed a bunch of tests that confirmed it was indeed not necessary - so this code is redundant, but also quite cool, because pew-pew - it uses Phasers! 🔫

These aren't Star Trek phasers, sadly. These Phasers are a Java concurrency primitive, like Semaphore or CountDownLatch.

Why did I think this synchronisation might be necessary?

KCL v3 Migration Step 4 regards "Graceful lease handoff", and says:

If you are performing any asynchronous processing, make sure that all delivered records to the downstream were processed before invoking checkpointing.

I wasn't sure how to interpret this, but I thought it was possible for a call to processRecords() (invoked by software.amazon.kinesis.lifecycle.ProcessTask) to be ongoing while shutdownRequested() is called (invoked by software.amazon.kinesis.lifecycle.ShutdownNotificationTask).

If that were the case, we would want to make sure we've finished our processing work in processRecords() before we checkpoint in shutdownRequested(), while being conscious that it could be occurring in a different thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant