Phasers on stun: Unnecessary but fun concurrency synchronisation for KCL v3 #57
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
I wasn't sure how to interpret this, but I thought it was possible for a call to
processRecords()
(invoked bysoftware.amazon.kinesis.lifecycle.ProcessTask
) to be ongoing whileshutdownRequested()
is called (invoked bysoftware.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 inshutdownRequested()
, while being conscious that it could be occurring in a different thread.