gaborgsomogyi opened a new pull request, #30259:
URL: https://github.com/apache/flink/pull/30259

   ## What is the purpose of the change
   
   Reading the keys of an operator with several states from a RocksDB or ForSt 
snapshot (State Processor API, SQL state catalog) can return a key more than 
once, without any error: in a reproduction 1,000 keys came back as 1,494 rows. 
`RocksMultiStateKeysIterator` and `ForStMultiStateKeysIterator` merge one 
sorted iterator per state, but compared the heads with `Arrays.compare`, which 
orders bytes as signed, while RocksDB iterates in unsigned order. Once a key 
contains a byte of 0x80 or more, the heads are merged out of order and the 
de-duplication against the previous key misses repeats. The HashMap state 
backend is not affected.
   
   ## Brief change log
   
     - Compare the keys with `Arrays.compareUnsigned` in both iterators.
     - `StateBackendTestBase`: one test for HashMap, RocksDB and ForSt. It 
writes a value, a list and a map state and expects every key once from 
`getKeys`, and once with its key-group from `getKeysAndKeyGroups`, over several 
key profiles, state distributions and key-group prefix sizes.
     - `KeyedStateReadingITCase`: SQL round trip with RocksDB and HashMap that 
expects exactly the rows that were written, by full scan and by key lookup, 
plus a join.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - Without the fix, the new backend test fails on RocksDB and ForSt 
(duplicate keys) and the SQL tests return duplicate rows on RocksDB, for 
example 2,482 instead of 1,000 matches in a join. With the fix they pass. 
HashMap passes either way.
     - The backend test also fails if the de-duplication is removed or the 
key-group prefix is ignored in the ordering.
     - The state processor API module and the HashMap, RocksDB and ForSt state 
backend tests pass.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? not applicable
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code 2.1.322 (Claude Sonnet 5.5)
   


-- 
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