K1taIkuyo0421 opened a new issue, #20867:
URL: https://github.com/apache/hudi/issues/20867

   ### Bug Description
   
   **What happened**
   
   After restoring a Flink COW UPSERT job from a completed checkpoint, a new 
batch can flush before the previous Hudi instant is recommitted. When both 
batches update the same existing file group, the new batch can merge against 
the older committed Parquet file. Both Hudi commits then succeed, but the 
latest snapshot drops rows that were added by the recovered batch.
   
   In a real Flink run with one writer and no rescaling, Spark time travel 
returned the following results:
   
   | Hudi snapshot | Total rows | IDs first visible in T3 |
   | --- | ---: | ---: |
   | T2, last commit before recovery | 22,400 | 0 |
   | T3, recommitted during recovery | 34,400 | 12,000 |
   | T4, first commit after recovery | 31,800 | 0 |
   | T5, next commit after recovery | 41,300 | 0 |
   
   The source generated each primary key once. I took the set difference 
between the T3 and T2 snapshots and checked those 12,000 keys against T4 and 
the latest snapshot. All 12,000 were absent in both. In a controlled local 
test, forcing the same order made the T4 merge use the T2 base file. Letting T3 
complete before the first flush made T4 use the T3 base file and preserved all 
rows.
   
   **What you expected**
   
   After restoring a completed checkpoint, the first new COW UPSERT must merge 
against the recovered base file once its instant is committed. The latest 
snapshot should contain the rows from both batches.
   
   **Steps to reproduce**
   
   1. Write a bounded Datagen stream with 60,000 distinct keys at 100 rows/s 
and a 512-character payload. Use one partition, one SIMPLE bucket, one writer, 
and a 2-minute checkpoint interval. Let the first two checkpoints commit 
normally.
   2. In a test build, pause the coordinator in `notifyCheckpointComplete()` 
before committing checkpoint 3 to Hudi. Once Flink has completed checkpoint 3, 
cancel the job and keep that checkpoint. Suppress the close-time commit in the 
test so that the Hudi instant T3 stays inflight.
   3. Restore from checkpoint 3 with the same parallelism and a fresh 
coordinator. Delay `handleBootstrapEvent()` on the JM metadata executor for 90 
seconds before it registers the recovered T3 event. Let the TM continue 
processing so the 1 MiB batch limit triggers an eager flush for T4 during that 
delay.
   4. Allow recovery and subsequent commits to finish. In Spark SQL, query T2, 
T3, T4, and the latest snapshot. Compute `IDs(T3) EXCEPT IDs(T2)` and check 
which of those IDs remain visible after T4.
   
   **Why the instant gate can miss this**
   
   The bootstrap event and the instant request are processed on separate 
coordinator executors. If restored coordinator state has no entry for T3, the 
instant request can pass `getPendingInstantsBefore()` before the bootstrap 
handler registers T3. Commit order can still be correct while the T4 Parquet 
file was already built using T2. [Coordinator event dispatch and instant 
gate](https://github.com/apache/hudi/blob/f9d6260c9113fcf3960362825e4dbb454b5a52b1/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/StreamWriteOperatorCoordinator.java#L365-L447)
   
   The empty-buffer recovery window was also raised during #20389 for the EAGER 
rollback path. Here the failed-writes policy is LAZY, and the symptom is 
missing rows after both instants complete. [Review 
comment](https://github.com/apache/hudi/pull/20389#issuecomment-6281087324)
   
   ### Environment
   
   **Hudi version** 1.1-based build with the test delays above. The coordinator 
gate was also checked in Apache master at `f9d6260` by source inspection. The 
end-to-end run used the 1.1-based build.
   
   **Engines** Flink streaming writer and Spark SQL snapshot/time-travel reads.
   
   **Relevant configuration**
   
   ```properties
   table.type = COPY_ON_WRITE
   write.operation = upsert
   hoodie.write.table.version = 5
   index.type = BUCKET
   hoodie.bucket.index.num.buckets = 1
   write.tasks = 1
   write.batch.size = 1
   hoodie.clean.failed.writes.policy = LAZY
   ```
   
   ### Logs and Stack Trace
   
   In the timeline, T4 entered inflight while T3 was still pending. T3 then 
completed, followed by T4. Both commits succeeded. The snapshot checks above 
show that the rows first visible in T3 disappear when T4 becomes visible.


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