Skip to content

KAFKA-20404: Replace bulk DefaultStateUpdater atomicity excludes with field-level suppressions#22333

Open
Phixsura wants to merge 1 commit into
apache:trunkfrom
Phixsura:05-KAFKA-20404-spotbugs-atomicity-default-state-updater
Open

KAFKA-20404: Replace bulk DefaultStateUpdater atomicity excludes with field-level suppressions#22333
Phixsura wants to merge 1 commit into
apache:trunkfrom
Phixsura:05-KAFKA-20404-spotbugs-atomicity-default-state-updater

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 DefaultStateUpdater$StateUpdaterThread, the second class in the series after StreamThread (#22320).

Investigation

After removing DefaultStateUpdater$StateUpdaterThread from the two bulk excludes it appeared in (AT_NONATOMIC_OPERATIONS_ON_SHARED_VARIABLE at line 505 and AT_NONATOMIC_64BIT_PRIMITIVE at line 544 on trunk), SpotBugs reports exactly one field with warnings:

  • totalCheckpointLatency at DefaultStateUpdater.java:100, flagged at line 732 (measureCheckpointLatency) and line 750 (recordMetrics).

Walking the call sites:

  • measureCheckpointLatency is private and only called from within StateUpdaterThread: restoreTasks, pauseTasks, resumeTasks, removeUpdatingTask, maybeCheckpointTasks.
  • recordMetrics is private and only called from StateUpdaterThread.runOnce (line 213).
  • All callers run on the StateUpdaterThread itself (the inner class extends Thread).

So totalCheckpointLatency is thread-confined and the SpotBugs warnings are false positives.

Changes

  • Remove DefaultStateUpdater$StateUpdaterThread from the two bulk <Or> blocks.
  • Add two targeted <Match> blocks scoped to the class plus the totalCheckpointLatency field, each with a rationale comment explaining the thread-confinement, one per bug pattern.

Verification

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

… field-level suppressions

Removes DefaultStateUpdater$StateUpdaterThread from the bulk Or blocks for
AT_NONATOMIC_OPERATIONS_ON_SHARED_VARIABLE and AT_NONATOMIC_64BIT_PRIMITIVE,
and adds two targeted suppressions for the single field SpotBugs actually
flags, totalCheckpointLatency.

totalCheckpointLatency is accumulated in measureCheckpointLatency and reset
in recordMetrics. Both methods are private and only invoked from within
StateUpdaterThread.runOnce, so the read-modify-write is thread-confined and
the SpotBugs warnings are false positives.

Second PR in the KAFKA-20404 series after StreamThread (1/N, apache#22320).
@github-actions github-actions Bot added triage PRs from the community build Gradle build or GitHub Actions small Small PRs labels May 20, 2026
Copy link
Copy Markdown
Collaborator

@smjn smjn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, LGTM

@Phixsura
Copy link
Copy Markdown
Author

Thanks for the PR, LGTM

Thanks! Waiting for one more approval before merging.

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 ci-approved small Small PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants