yuqi1129 opened a new issue, #13502:
URL: https://github.com/apache/gravitino/issues/13502

   ### Describe the subtask
   
   When a table's registration is left in the store (for example the table was 
dropped outside Gravitino) and a table with the same name is created again, 
`TableOperationDispatcher.internalCreateTable` calls `store.put(entity, true)` 
with a new table id. `TableMetaService.insertTable(overwrite = true)` then 
upserts over the stale row:
   
   - **MySQL/H2:** `ON DUPLICATE KEY UPDATE` matches the `(schema_id, 
table_name, deleted_at)` unique key and keeps the stale `table_id`. The new 
table inherits the old table's tags, owner, privileges and statistics, and its 
stored id no longer matches the id written into the catalog's table properties.
   - **PostgreSQL:** `ON CONFLICT (table_id)` doesn't cover the name key, so 
the insert fails with a unique violation. The create is logged and swallowed, 
and the table can't be loaded consistently afterwards.
   
   The import path (`importTable`) goes through the same upsert and has the 
same problem when a different id holds the name.
   
   Proposed fix:
   
   - In `insertTable(overwrite = true)`, inside the same schema-locked 
transaction, look up the row stored under the name. If it has a different id, 
delete it and its dependents (columns, version, tag/owner/securable relations, 
statistics) before the upsert. An overwrite with the same id (e.g. re-import 
after an out-of-band rename) is unchanged.
   - In `importTable`, overwrite only when the id comes from the table's 
properties. A generated id identifies nothing, so a concurrent import of the 
same table must keep its row: the plain insert conflicts and `loadTable` 
reloads it, as today.
   - Add tests that fail without the fix, including on H2, MySQL and PostgreSQL.
   
   Schema, topic and view creates use the same `put(overwrite)` pattern and are 
tracked as follow-ups in #13303.
   
   Target: `main`, backport to `branch-1.3`.
   
   ### Parent issue
   
   #13303
   


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