ricky2129 opened a new issue, #12806:
URL: https://github.com/apache/seatunnel/issues/12806

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22bug%22)
 and found no similar issues.
   
   ### What happened
   
   With `enable_upsert = false`, the JDBC sink silently drops a row that is 
inserted and then updated within the same flush.
   
   `BufferReducedBatchStatementExecutor` keeps only the last change per primary 
key. For an `INSERT` followed by an `UPDATE_AFTER` of the same key, the buffer 
keeps the `UPDATE_AFTER`. `InsertOrUpdateBatchStatementExecutor` then picks the 
statement from the row kind, so it runs `UPDATE ... WHERE pk = ?` against a row 
that does not exist yet: 0 rows are affected, the row is never inserted, and no 
error is raised. Later updates of that row are lost the same way.
   
   The reverse case breaks too: a `DELETE` followed by an `INSERT` of the same 
key is reduced to an `INSERT` of a row that is still in the table, which fails 
with a duplicate key.
   
   With `is_exactly_once = true`, the buffer is flushed only at each 
checkpoint, so every row created and changed within one checkpoint interval is 
lost.
   
   Reproduced end to end on 2.3.12; 
`BufferReducedBatchStatementExecutor.addToBatch` and 
`InsertOrUpdateBatchStatementExecutor.existRow` are the same on dev (MySQL-CDC 
→ JDBC, MySQL 8.4, config below):
   
   ```sql
   INSERT INTO s.t1 VALUES (99001, ...); UPDATE s.t1 SET amount = 2 WHERE id = 
99001;  -- same flush: row never reaches the target
   INSERT INTO s.t1 VALUES (99002, ...);  -- wait for a checkpoint
   UPDATE s.t1 SET amount = 2 WHERE id = 99002;  -- next flush: correct
   ```
   
   Under a mixed insert/update load on 8 tables (about 2,600 operations), 50 of 
960 rows were missing from the target with no restarts at all.
   
   ### SeaTunnel Version
   
   2.3.12 and dev (c37823b9a)
   
   ### SeaTunnel Config
   
   ```conf
   sink {
     Jdbc {
       url = "jdbc:mysql://mysql:3306/m3"
       driver = "com.mysql.cj.jdbc.Driver"
       username = "st", password = "stpw"
       database = "m3"
       table = "${table_name}"
       generate_sink_sql = true
       enable_upsert = false
     }
   }
   ```
   
   ### Running Command
   
   ```shell
   ./bin/seatunnel.sh -c job.conf --async
   ```
   
   ### Error Exception
   
   ```log
   No exception. The row is missing from the target table.
   ```
   
   ### Zeta or Flink or Spark Version
   
   Zeta
   
   ### Java or Scala Version
   
   1.8
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


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