KAFKA-20404: Replace bulk StreamsPartitionAssignor atomicity exclude with field-level suppressions#22341
Open
Phixsura wants to merge 1 commit into
Conversation
…with field-level suppressions Removes StreamsPartitionAssignor from the bulk Or block for AT_STALE_THREAD_WRITE_OF_PRIMITIVE and adds a targeted suppression for the two fields SpotBugs flags: uniqueField and usedSubscriptionMetadataVersion. Both fields are accessed only from ConsumerPartitionAssignor callbacks (configure, subscriptionUserData, onAssignment) that KafkaConsumer invokes from poll(); poll() in turn is driven by the StreamThread, so the read-modify-write happens on a single thread and the SpotBugs warnings are false positives. Fourth PR in the KAFKA-20404 series after StreamThread (apache#22320), DefaultStateUpdater (apache#22333), and TaskManager (apache#22340).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Background
KAFKA-20404 tracks replacing the bulk SpotBugs atomicity excludes (introduced when SpotBugs was upgraded from 4.8.6 to 4.9.4) with per-field investigations. This PR handles
StreamsPartitionAssignor, the fourth class in the series afterStreamThread(#22320),DefaultStateUpdater(#22333), andTaskManager(#22340).Investigation
After removing
StreamsPartitionAssignorfrom the single bulkAT_STALE_THREAD_WRITE_OF_PRIMITIVEblock it appeared in (trunk line 600), SpotBugs reports two fields with warnings:uniqueFieldatStreamsPartitionAssignor.java:232, flagged at line 266 (configure(Map)) and line 288 (subscriptionUserData(Set)).usedSubscriptionMetadataVersionatStreamsPartitionAssignor.java:223, flagged at line 1432 and line 1447 (both insidemaybeUpdateSubscriptionVersion(int, int)).Walking the call sites:
configure,subscriptionUserData, andonAssignmentare allConsumerPartitionAssignor/Configurableinterface methods. The Kafka consumer invokes them from insidepoll()(e.g.ConsumerCoordinator.java:311callsassignor.subscriptionUserData(...), line 370 callsassignor.onAssignment(...)).maybeUpdateSubscriptionVersionisprotectedand only called frommaybeScheduleFollowupRebalance(line 1544), which is itself reached fromonAssignment.uniqueField()getter is only invoked byStreamsPartitionAssignorTest.KafkaConsumer.poll()is driven by theStreamThread, so both fields are thread-confined and the SpotBugs warnings are false positives.Changes
StreamsPartitionAssignorfrom the bulk<Or>block.<Match>block scoped to the class with an<Or>over both fields, with a rationale comment.Verification
:streams:spotbugsMain --rerun-tasksclean.:streams:spotbugsTest/:streams:checkstyleMain/:streams:checkstyleTestclean.:streams:test --tests "*StreamsPartitionAssignor*"all green.