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

   ### Describe the subtask
   
   Relation tables (`owner_meta`, `tag_relation_meta`, `policy_relation_meta`, 
`statistic_meta`, `role_meta_securable_object`) reference an entity via a plain 
`metadata_object_id (+ type)` column with no foreign key. The normal delete 
path already cascades these in one transaction (e.g. 
`TableMetaService.deleteTable`), but rows can still be orphaned when an entity 
row is lost out-of-band or re-imported under a new id (see #12153). Nothing 
actively removes such orphaned relations today.
   
   Pre-existing data-hygiene gap, independent of the TreeLock work.
   
   ### How to fix
   
   Add a pass to `RelationalGarbageCollector` that soft-deletes relation rows 
whose `metadata_object_id` has no live entity of that type — one statement per 
relation table, e.g.:
   
   ```sql
   UPDATE owner_meta SET deleted_at = ?
   WHERE deleted_at = 0 AND metadata_object_type = 'TABLE'
     AND NOT EXISTS (SELECT 1 FROM table_meta WHERE table_id = 
metadata_object_id AND deleted_at = 0);
   ```
   
   - Iterate over each relation table and each metadata object type.
   - Run on the existing GC schedule; keep it idempotent and rate-limited.
   - Tests: orphaned owner/tag/policy/statistic rows are collected; live 
relations are untouched.
   
   ### Parent issue
   
   https://github.com/apache/gravitino/issues/10238
   


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