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

   ### What problem does this PR solve?
   
   Issue Number: N/A
   
   Problem Summary:
   
   Two concurrent `CREATE TABLE IF NOT EXISTS ... AS SELECT` statements can 
both pass the initial table-existence check. Only one registers its table; the 
other receives the atomic registration result indicating that the table already 
exists. However, `InternalCatalog.createOlapTable` leaves its returned 
`tableHasExist` flag false, so both CTAS statements continue into INSERT and 
append their rows to the same table. For example, two concurrent `CREATE TABLE 
IF NOT EXISTS t AS SELECT 1 AS k` statements can leave two rows instead of one.
   
   Propagate the existing-table result from `Database.createTableWithoutLock` 
while holding the existing database write lock. The losing creator still 
completes its existing tablet/colocate cleanup, then returns true so the 
existing CTAS early-return branch skips INSERT. The shared catalog 
implementation also covers `CloudInternalCatalog`.
   
   The new tests deterministically simulate a stale initial existence probe 
against a real database, exercise the actual atomic registration and cleanup, 
and check that the winner's table and tablet metadata survive. They also cover 
sequential IF NOT EXISTS and the duplicate-registration error without IF NOT 
EXISTS.
   
   ### Release note
   
   Fix duplicate rows when concurrent CREATE TABLE IF NOT EXISTS AS SELECT 
statements target the same internal table.
   
   ### Check List (For Author)
   
   - Test
       - [x] Unit Test
       - [ ] Regression test
       - [ ] Manual test (add detailed scripts or steps below)
   - Behavior changed:
       - [ ] No.
       - [x] Yes. A CTAS statement that loses concurrent table registration 
skips INSERT as required by IF NOT EXISTS.
   - Does this need documentation?
       - [x] No.
       - [ ] Yes.
   
   Validation (JDK 17):
   
   - `bash run-fe-ut.sh --run 
'org.apache.doris.catalog.CreateTableTest,org.apache.doris.nereids.trees.plans.commands.CreateTableCommandTest'`:
 23 tests passed.
   - Negative control: removing only the production fix makes 
`testCreateTableReturnsExistingAfterRegistrationRace` fail with `expected: 
<true> but was: <false>`; restoring the fix passes.
   - `cd fe && mvn checkstyle:check -pl fe-core`: passed.
   - `git diff --check`: passed.
   
   Post-fix local validation covers FE unit tests; a full-cluster regression 
has not been run with the fix. Please backport to branch-4.1.
   
   ### 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