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

   ### What problem does this PR solve?
   
   Issue Number: N/A
   
   Related PR: N/A
   
   Problem Summary:
   
   MTMV snapshots for non-PCT base tables compare `(tableId, tableVersion)`.
   `TRUNCATE` keeps the table ID but reset the non-Cloud table version to 1,
   so later writes could reuse a previously recorded snapshot and cause AUTO
   refresh to miss changed data.
   
   **Root cause:** `InternalCatalog.truncateTableInternal()` replaced the old
   partitions and then called `OlapTable.resetVisibleVersion()`. A sequence such
   as version 3 -> TRUNCATE to 1 -> two writes to version 3 creates an ABA
   collision for table-level snapshot consumers.
   
   **Change Summary:**
   
   | File | Change Description |
   |------|--------------------|
   | `InternalCatalog.java` | Increment the non-Cloud table version once after 
whole-table or partition TRUNCATE; Cloud remains Meta Service-managed |
   | `OlapTable.java`, `TableAttributes.java` | Remove the TRUNCATE-only 
version reset helpers |
   | `TruncateTableCommandTest.java` | Verify whole-table and partition 
TRUNCATE each advance the table version once |
   | `test_truncate_table_mtmv.groovy` | Reproduce the non-PCT table snapshot 
ABA while preserving the existing expected output |
   | `truncate_version_reset.groovy` | Keep the SimpleAggCache regression 
description consistent with monotonic versions |
   
   **Design Rationale:** The table version represents table-level data changes,
   while PCT refresh separately compares partition ID and partition version.
   Reusing the existing table version avoids new persisted flags or 
MTMV-specific
   invalidation state. Live execution and journal replay use the same locked 
path.
   Cloud is skipped locally because `commit_partition` already advances and
   returns the Meta Service table version.
   
   ```mermaid
   flowchart LR
       A[TRUNCATE] --> B[Replace partitions]
       B --> C{Cloud mode}
       C -->|No| D[Increment FE table version once]
       C -->|Yes| E[Use Meta Service table version]
       D --> F[MTMV table snapshot changes]
       E --> F
   ```
   
   The MTMV regression is included but has not been run locally because it
   requires an owner-built FE and manual service restart.
   
   ### Release note
   
   Fixed an issue where AUTO materialized view refresh could miss changes after
   a non-PCT base table was truncated.
   
   ### Check List (For Author)
   
   - Test
       - [ ] 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
   
   - Behavior changed:
       - [ ] No.
       - [x] Yes. Non-Cloud TRUNCATE increments the table version instead of 
resetting it to 1; Cloud remains Meta Service-managed.
   
   - Does this need documentation?
       - [x] No.
       - [ ] Yes.
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label


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