Skip to content

KAFKA-20404: Replace bulk TaskManager atomicity exclude with a field-level suppression#22340

Open
Phixsura wants to merge 1 commit into
apache:trunkfrom
Phixsura:06-KAFKA-20404-spotbugs-atomicity-task-manager
Open

KAFKA-20404: Replace bulk TaskManager atomicity exclude with a field-level suppression#22340
Phixsura wants to merge 1 commit into
apache:trunkfrom
Phixsura:06-KAFKA-20404-spotbugs-atomicity-task-manager

Conversation

@Phixsura
Copy link
Copy Markdown

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 TaskManager, the third class in the series after StreamThread (#22320) and DefaultStateUpdater (#22333).

Investigation

After removing TaskManager from the single bulk AT_STALE_THREAD_WRITE_OF_PRIMITIVE block it appeared in (trunk line 602), SpotBugs reports exactly one field with warnings:

  • rebalanceInProgress at TaskManager.java:102, flagged at line 191 (handleRebalanceStart) and line 208 (handleRebalanceComplete).

Walking the call sites:

  • Writes (handleRebalanceStart / handleRebalanceComplete) are invoked from StreamsPartitionAssignor and DefaultStreamsRebalanceListener — both are ConsumerRebalanceListener callbacks fired from inside KafkaConsumer.poll(), which is driven by the StreamThread.
  • Reads via the rebalanceInProgress() getter happen at StreamThread.runLoop (lines 938 and 962).
  • Direct field reads at TaskManager.java:1883 (maybeCommitActiveTasksPerUserRequested) and TaskManager.java:1897 (commitTasksAndMaybeUpdateCommittableOffsets) are reached only from TaskManager.commit(...) / StreamThread.runOnce*, which also run on the StreamThread.

So rebalanceInProgress is thread-confined to the StreamThread, and the SpotBugs warning is a false positive.

Changes

  • Remove TaskManager from the bulk <Or> block.
  • Add a targeted <Match> block scoped to the class plus the rebalanceInProgress field, with a rationale comment explaining the thread-confinement.

Verification

  • :streams:spotbugsMain --rerun-tasks clean.
  • :streams:spotbugsTest / :streams:checkstyleMain / :streams:checkstyleTest clean.
  • :streams:test --tests "*TaskManager*" all green.

…level suppression

Removes TaskManager from the bulk Or block for AT_STALE_THREAD_WRITE_OF_PRIMITIVE
and adds a targeted suppression for the single field SpotBugs flags,
rebalanceInProgress.

rebalanceInProgress is written from the ConsumerRebalanceListener callbacks
(handleRebalanceStart / handleRebalanceComplete, invoked from KafkaConsumer.poll())
and read from StreamThread.runLoop and TaskManager's commit paths. All of these
run on the StreamThread, so a stale cross-thread write cannot occur and the
SpotBugs warning is a false positive.

Third PR in the KAFKA-20404 series after StreamThread (apache#22320) and
DefaultStateUpdater (apache#22333).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Gradle build or GitHub Actions small Small PRs triage PRs from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant