Skip to content

KAFKA-20893: Avoid reporting incorrect task-offsets to Kafka Streams assignor - #23082

Merged
mjsax merged 1 commit into
apache:trunkfrom
mjsax:kafka-20893-exclude-in-memory-store-offsets
Aug 5, 2026
Merged

KAFKA-20893: Avoid reporting incorrect task-offsets to Kafka Streams assignor#23082
mjsax merged 1 commit into
apache:trunkfrom
mjsax:kafka-20893-exclude-in-memory-store-offsets

Conversation

@mjsax

@mjsax mjsax commented Aug 5, 2026

Copy link
Copy Markdown
Member

The StateDirectory offset cache should only contain data for
persistent state store. This PR avoids the offset from in-memory state
stores are added to the cache, and ensure that the read path fills in
missing information for other state stores (in particular in-memory
ones) on the fly.

Reviewers: Nick Telford nick.telford@gmail.com, Bill Bejeck
bbejeck@apache.org

…assignor

The `StateDirectory` offet cache should only contain data for persitent
state store. This PR avoids the offset from in-memory state stores are
added to the cache, and ensure that the read path fills in missing
inforamtion for other state stores (in particular in-memory ones) on the
fly.
@mjsax

mjsax commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

4.3 branch will also need a fix; however, we cannot just cherry-pick because this PR contains KIP-1071 related changes which don't apply to 4.3. Thus, we need to do a proper back-port of this fix instead.

@nicktelford nicktelford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. My only comments are requests for clarification.

Comment on lines 1337 to 1338
if (task.isActive() && task.state() == State.RUNNING && !task.changelogPartitions().isEmpty()) {
taskOffsetSums.put(task.id(), Task.LATEST_OFFSET);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this branch was already unconditionally using LATEST_OFFSET for all running active tasks (with changelogs), this should narrow the scope of the bug to only tasks with in-memory stores that are currently assigned as standbys, or as actives that are not currently running (i.e. restoring state).

Still worth fixing, but I wanted to clarify the scope of the bug here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The main point of the fix is actually dormant tasks, ie, not owned any longer. For persistent stores, we still have the state in the state directory, so if the state-directory caches them that's correct. However, for in-memory stores, when a task is revoked we don't have any local state left, but the state-store cache still reported these offsets.

For assigned in-memory tasks (active or standby) it's ok if we report offsets, and not much changes for them with this PR -- before the change, the in-memory offsets are pushed into the cache and read from the cache for reporting. With the change, we won't add these offset into the cache any longer, and thus need to add them back on the read path for reporting.

The point is, that we don't report offset of dormet/previously assigned tasks with in-memory offsets any longer -- they don't make it into the cache any more, and on-read we only go over assigned tasks.

Comment on lines +1286 to +1290
} else if (task.state() != State.CREATED && task.state() != State.CLOSED) {
final Map<TopicPartition, Long> changelogOffsets = task.changelogOffsets();
if (!changelogOffsets.isEmpty()) {
offsetSums.put(task.id(), StateDirectory.sumOfChangelogOffsets(task.id(), changelogOffsets));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If I'm reading this right, I think this branch is actually fixing a slightly different bug: a failure to include offsets for standby tasks, or active tasks that are not yet running (i.e. restoring). Is that right, or did I miss how this relates to the in-memory stores issue?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, both of these were already included in the state-directory cache previously. -- So technically, we could limit this branch to only all offsets from in-memory stores (which we don't get from the state-directory cache any longer), but we just include all owned stores for the benefit of getting slightly more up-to-date offsets (compare to what we got from the state-directory cache). The main benefit is really simpler code/logic: we just go over tasks, and don't need to check if state stores are persistent or in-memory.

@bbejeck bbejeck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @mjsax LGTM

@bbejeck

bbejeck commented Aug 5, 2026

Copy link
Copy Markdown
Member

4.3 branch will also need a fix; however, we cannot just cherry-pick because this PR contains KIP-1071 related changes which don't apply to 4.3. Thus, we need to do a proper back-port of this fix instead.

Since KIP-1035 reverted the guard was originally added by KAFKA-10249 #8996 I don't think that will be too difficult

@bbejeck

bbejeck commented Aug 5, 2026

Copy link
Copy Markdown
Member

Kicked off a system test run - will post results once it completes

@bbejeck

bbejeck commented Aug 5, 2026

Copy link
Copy Markdown
Member

Passing system test results

@mjsax
mjsax merged commit 588e6db into apache:trunk Aug 5, 2026
27 checks passed
@mjsax

mjsax commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

Back-port to 4.3 branch: #23089

@mjsax
mjsax deleted the kafka-20893-exclude-in-memory-store-offsets branch August 5, 2026 19:43
mjsax added a commit that referenced this pull request Aug 5, 2026
…assignor (#23082) (#23089)

The `StateDirectory` offset cache should only contain data for
persistent state store. This PR avoids the offset from in-memory state
stores are added to the cache, and ensure that the read path fills in
missing information for other state stores (in particular in-memory
ones) on the fly.

Reviewers: Nick Telford <nick.telford@gmail.com>, Bill Bejeck
 <bbejeck@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants