w-yfan opened a new pull request, #30081:
URL: https://github.com/apache/flink/pull/30081

   ## What is the purpose of the change
   
   Fix [FLINK-41640](https://issues.apache.org/jira/browse/FLINK-41640). With 
`NeverReturnExpired`, synchronous `MapState.isEmpty()` can return `false` after 
every mapping has expired. Reading the last mapping with `get()` returns `null` 
and removes it, so a second `isEmpty()` can return `true`. This also affects 
PyFlink's `MapState.is_empty()` in thread mode.
   
   ## Brief change log
   
   - Reuse the TTL-aware entry scan for `NeverReturnExpired`. It stops at the 
first visible mapping and checks timestamps without refreshing them.
   - Keep the backend's emptiness check for `ReturnExpiredIfNotCleanedUp`, 
where retained expired mappings remain visible.
   - Skip reading map keys during the scan when the exclusion set is empty. 
This avoids deserializing keys on backends that load them on demand.
   
   ## Verifying this change
   
   Two regression tests in `TtlStateTestBase` use a controlled clock and 
disable background cleanup. The first checks a mixture of live and expired 
mappings, advances the clock until the final mapping expires, and checks 
emptiness before and after reading that mapping. It also checks that 
`isEmpty()` does not extend a live mapping's TTL under `OnReadAndWrite`. The 
second checks that a retained expired mapping remains visible under 
`ReturnExpiredIfNotCleanedUp` until a read removes it.
   
   The strict-visibility regression failed on the original implementation in 
the heap and mock suites. Both new tests passed on the patched implementation 
in all five suites below. The relevant Maven reactor completed successfully 
with Java 17.
   
   ```sh
   ./mvnw -pl 
flink-runtime,flink-state-backends/flink-statebackend-rocksdb,flink-state-backends/flink-statebackend-forst
 -am \
     
-Dtest=HeapAsyncSnapshotTtlStateTest,MockTtlStateTest,IncSnapshotRocksDbTtlStateTest,FullSnapshotRocksDbTtlStateTest,ForStSyncTtlStateTest
 \
     -Dsurefire.failIfNoSpecifiedTests=false -DskipITs test
   ```
   
   ## Does this pull request potentially affect one of the following parts?
   
   - Dependencies — No
   - Public API signatures — No
   - Serializers — No
   - Runtime per-record code paths — Yes. With `NeverReturnExpired`, the call 
may examine all retained mappings if all have expired. With 
`ReturnExpiredIfNotCleanedUp`, it keeps the existing backend cost.
   - Deployment or recovery — No
   - S3 file system connector — No
   
   ## Documentation
   
   This fixes the behavior of an existing API. The Jira issue includes a 
release note.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes
   
   Generated-by: OpenAI Codex CLI 0.171.0-alpha.13 (GPT-6)
   


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