KAFKA-20699: TopologyTestDriver.getStateStore must not reset the record context#22590
Open
SouquieresAdam wants to merge 1 commit into
Open
KAFKA-20699: TopologyTestDriver.getStateStore must not reset the record context#22590SouquieresAdam wants to merge 1 commit into
SouquieresAdam wants to merge 1 commit into
Conversation
…rd context KAFKA-19638 moved the dummy ProcessorRecordContext initialization out of task construction and into TopologyTestDriver#getStateStore, but set it unconditionally. As a result every store lookup overwrites the task's live record context (null topic, -1 offset/partition, timestamp 0) and never restores it, so a store handle fetched while a record's context is active wipes the in-flight RecordMetadata: recordMetadata().topic() returns null and a subsequent direct write is logged to the changelog at timestamp 0. The normal process() path masks this because doProcess rebuilds the context per record, so it surfaces on direct store writes after a lookup, and on any context read not preceded by a fresh process(). Only materialize the dummy context when none exists yet (before any record has been processed); never overwrite a live one. This keeps direct store access working while leaving an in-flight record's context intact.
Author
|
Hi @mjsax & @eduwercamacaro. Migrating to 4.2 raised this issue on our side. First PR for a bug, feel free to educate me on the process. |
mjsax
reviewed
Jun 16, 2026
| // the direct write should be logged at the live stream-time (5000), not epoch 0 | ||
| final KeyValueStore<String, Long> handle = testDriver.getKeyValueStore(storeName); | ||
| handle.put("seeded", 2L); | ||
| testDriver.advanceWallClockTime(Duration.ZERO); |
Member
There was a problem hiding this comment.
Why do we call this and pass in ZERO? Looks like a no-op?
Author
There was a problem hiding this comment.
It's on purpose here: this line force the changelog topic to be flushed and allow to test the output. I chose 0 to explicitly use a time neutral value. Same result with 1ms.
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.
Summary
KAFKA-20699. A
regression introduced by KAFKA-19638 (#20403):
TopologyTestDriver#getStateStorenow sets a dummyProcessorRecordContext(nulltopic,-1offset/partition, timestamp0) unconditionally and never restores it. Before KAFKA-19638 thedummy context was set once at task construction and
getStateStorewasread-only.
As a result, a store lookup mutates the task's live record context as a
side effect. When a store handle is fetched while a record's context is
active — an interactive query interleaved with processing, or a test
seam that resolves a store handle through TTD from production code — the
in-flight record's
RecordMetadatais wiped:recordMetadata().topic()returns
nulland offset/partition become-1. Code buildingprovenance from
recordMetadata().topic()then fails, and direct storewrites capture timestamp
0.The normal
process()path masks this becausedoProcessrebuilds thecontext per record, so it surfaces on direct store writes after a lookup
and on any context read not preceded by a fresh
process().Fix
Only materialize the dummy context when none exists yet (before any
record has been processed); never overwrite a live one. Direct store
access still works, while an in-flight record's context is left intact.
Testing
Added
shouldNotResetRecordContextWhenAccessingStateStoretoTopologyTestDriverTest(runs under both at-least-once and EOS). Itprocesses a record at stream-time 5000, then grabs the store handle and
writes directly to it; the write must be logged to the changelog at
5000. Fails before the fix (
expected: <5000> but was: <0>), passesafter. Full
:streams:test-utils:test+ checkstyle + spotbugs pass.Reviewers: Matthias J. Sax matthias@confluent.io