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

fixes #419 NoSuchElementException during race condition in PartitionState #422

Merged
merged 6 commits into from
Sep 30, 2022

Conversation

astubbs
Copy link
Contributor

@astubbs astubbs commented Sep 29, 2022

In busy situations, there is a race condition in PartitionState due to it being edited by the Controller, and read by the BrokerPoller.

Because the check and subsequent read of the incompleteOffsets collection are two different operations, it can initially appear as though it has elements, but when we try to retrieve an element, it can then be empty, which throws a NoSuchElementException.

Thanks to a very elegant fix suggested by @shaileshkulkarni, we can combine the check and retrieval by using the thread safe #ceiling method, which can either returns the #first element, or null if empty.

This is as opposed to the more brute force solution which would require using locks.

This, among other things, will be made redundant once #200 (a shared nothing architecture) is merged.

Description...

Checklist

  • Changelog

…ition in PartitionState

In busy situations, there is a race condition in PartitionState due to it being edited by the Controller, and read by the BrokerPoller.

Because the check and subsequent read of the incompleteOffsets collection are two different operations, it can initially appear as though it has elements, but when we try to retrieve an element, it can then be empty, which throws a NoSuchElementException.

Thanks to a very elegant fix suggested by @shaileshkulkarni, we can combine the check and retrieval by using the thread safe #ceiling method, which can either returns the #first element, or null if empty.

This is as opposed to the more brute force solution which would require using locks.

This, among other things, will be made redundant once confluentinc#200 (a shared nothing architecture) is merged.
@astubbs astubbs linked an issue Sep 29, 2022 that may be closed by this pull request
@astubbs astubbs marked this pull request as ready for review September 30, 2022 13:16
@astubbs astubbs merged commit dd492df into confluentinc:master Sep 30, 2022
@astubbs astubbs deleted the fixes/partition-state-race-null branch September 30, 2022 14:09
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.

Consumer closes with an exception NoSuchElementException
1 participant