yujun777 opened a new pull request, #71392:
URL: https://github.com/apache/doris/pull/71392

   ### What problem does this PR solve?
   
   Issue Number: None
   
   Problem Summary:
   When an OLAP table stream (used either directly by a user stream or 
internally by an IVM materialized view) has already caught up on a partition 
and that partition receives no further writes for longer than 
`changelog.ttl_seconds`, its consumed offset ages past the changelog TTL 
cutoff. Subsequent stream reads or incremental refreshes then treat the 
partition as expired and fail or fall back to full rebuild even though no 
changes occurred after the consumed offset.
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [x] Regression test
       - [x] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   
   - Behavior changed:
       - [x] No.
       - [ ] Yes. <!-- Explain the behavior change -->
   
   - Does this need documentation?
       - [x] No.
       - [ ] Yes. <!-- Add document PR link here. eg: 
https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should 
merge into -->
   
   ### Details
   
   - **Per-partition keep-alive state (`OlapTableStream`)**:
     - Adds an optional `PartitionKeepAlive` (`o` = proven consumed offset, `k` 
= proven safe keep-alive TSO) to `PartitionStreamState` 
(`@SerializedName("ka")`) and `effectiveOffset()` returning `max(offset, 
keepAliveTso)` only when `keepAlive.offset == offset`.
     - Any subsequent offset advancement or reset naturally invalidates stale 
keep-alive entries without changing consumption semantics.
   - **Standalone generic daemon (`StreamKeepAliveDaemon`)**:
     - Runs as a Master-only daemon polling `Config.enable_stream_keepalive` 
and `Config.stream_keepalive_interval_second`, waiting for `TSOService` 
initialization before advancing its schedule timer.
     - Enumerates all `OlapTableStream` instances directly via 
`TableStreamManager.copyDbStreamMap()`, applying uniformly to both user streams 
and IVM streams without coupling to `MTMV`.
   - **Local & Cloud safe keep-alive (`TableStreamManager`, 
`TableStreamCleanupInfo`)**:
     - **Local mode**: verifies under table/stream locks that the partition has 
already been consumed (`offset > 0`), remaining TTL is below half of 
`changelog.ttl_seconds`, no in-flight committed transactions exist on the base 
table, and `maxWriteTso <= offset`; then records a keep-alive TSO bounded by 
`TSOService.getSafeReadTso()` via `OP_CLEANUP_TABLE_STREAM` 
(`TableStreamCleanupInfo.ofKeepAlive`).
     - **Cloud mode**: advances a single `advanceTsoFence(committedTso)` 
watermark via MetaService (so any concurrent transaction that starts afterward 
receives a strictly higher TSO), batch-reads per-partition `lastWriteTso` with 
bounded chunking / wide-stream slicing, and persists keep-alive TSOs only for 
idle partitions with `lastWriteTso <= offset`.
   - **Planner integration (`OlapTableStreamWrapper`, 
`NormalizeOlapTableStreamScan`)**:
     - Captures `keepAlives` in `OlapTableStreamWrapper` (preserved across 
`installCloudReadStates()`) and applies 
`TSOTimestamp.toExclusiveBound(keepAliveTso)` in `applyChangelogTtl()` when 
evaluating TTL expiration.
   
   ### Testing
   
   - FE Checkstyle + FE Unit Tests:
     - `mvn test -pl fe-core -am -DfailIfNoTests=false 
-Dtest="StreamKeepAliveTest,TableStreamManagerCleanupTest,OlapTableStreamConsumptionTest,OlapTableStreamSnapshotReadTest,OlapTableStreamUpdateTest,ExplainTableStreamPlanTest"`
 (59/59 passed)
   - Local 1FE+1BE Regression Tests:
     - `test_stream_keepalive` (verifies both user `STREAM` and strict `REFRESH 
MATERIALIZED VIEW ... INCREMENTAL` survive an idle period longer than 
`changelog.ttl_seconds` and still consume subsequent writes incrementally)
     - `test_olap_table_stream_history_consumption`
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to