xjrk58 opened a new pull request, #24272:
URL: https://github.com/apache/kafka/pull/24272

   …s under EOS (#24204)
   
   https://issues.apache.org/jira/browse/KAFKA-21492
   
   A segmented store (window and session stores) keeps its changelog offsets in 
its segments. Without a segment, `AbstractSegments#commit` has nothing to write 
to and `AbstractSegments#committedOffset` returns `null`, while opening the 
store has already created its directory.
   
   Under exactly-once, `ProcessorStateManager#initializeStoreOffsets` then 
treats the task as corrupted every time it is initialized on an instance that 
has its task directory (after a restart, a rebalance, or a switch between 
active and standby). The whole task is wiped and restored, and the restore 
creates the same empty store directory again, so it repeats. A corrupted active 
task also triggers a rebalance. A store has no segment when it was never 
written.
   
   This patch reports the offset of a segmented store without segments as 
`OFFSET_UNKNOWN`, which is what a key-value store commits when it has no offset 
and what `ProcessorStateManager` already accepts. There is no local data in 
that state, so nothing can be uncommitted. A store that has a segment but no 
offset still reports none, and its task is still wiped.
   
   `GlobalStateManagerImpl` reads the same offset for global stores and would 
seek to the sentinel, so it now ignores it and restores from the beginning.
   
   Testing:
   - `SegmentedStoreWithoutSegmentsTest` (new) covers the behaviour end to end 
with `TopologyTestDriver`: a task whose window or session store left its empty 
directory behind is initialized under exactly-once, and a store with a segment 
and no offset is still treated as corrupted. The store directory is created by 
hand because `TopologyTestDriver#close` deletes the state directory.
   - `KeyValueSegmentsTest` covers the changed method: no segments reports 
`OFFSET_UNKNOWN`, a segment without offsets reports `null`.
   - `GlobalStateManagerImplTest` covers the global path: a store reporting 
`OFFSET_UNKNOWN` is restored from the beginning.
   - The two initialization tests and the two unit tests fail without the 
change.
   
   Seen on 4.3.2 in a 4-instance application with `exactly_once_v2` and one 
standby replica, where a never-written window store kept its sub-topology's 
tasks being wiped at every probing rebalance.
   
   Locally, `checkstyleMain`, `checkstyleTest` and `spotlessCheck` pass for 
`:streams`, and so does `./gradlew :streams:test --tests 
'org.apache.kafka.streams.state.*' --tests
   'org.apache.kafka.streams.processor.internals.*'` (7,294 tests). I did not 
run the integration or system tests.
   
   Alternatives I considered: keeping the offsets of a segmented store 
somewhere that does not depend on a segment, or relaxing the check in 
`ProcessorStateManager`. Both are larger changes.
   
   This change was prepared with AI assistance (see the commit trailer); I have 
reviewed it and take responsibility for it.
   
   Reviewers: Nick Telford <[email protected]>, Bill Bejeck
    <[email protected]>
   
   ---------
   
   
   (cherry picked from commit 7e0ebdf74f30cab1ded2a462cc9d45cefdf86c2a)
   
   Delete this text and replace it with a detailed description of your change. 
The 
   PR title and body will become the squashed commit message.
   
   If you would like to tag individuals, add some commentary, upload images, or
   include other supplemental information that should not be part of the 
eventual
   commit message, please use a separate comment.
   
   If applicable, please include a summary of the testing strategy (including 
   rationale) for the proposed change. Unit and/or integration tests are 
expected
   for any behavior change and system tests should be considered for larger
   changes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to