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

   ### Version
   main branch, commit bb634defdc5663a8124be5fca1c8d9e52ac096ac (2.0.0-SNAPSHOT)
   
   ### Describe what's wrong
   In a `lakehouse-iceberg` catalog, a user renames table `a` to `b` while `b` 
already exists in the same schema. The user expects a 409 
`TableAlreadyExistsException`, which is how Gravitino reports this conflict for 
filesets, models, policies, catalogs, metalakes and managed tables since 
#14039. Instead the request fails with a 500 `RuntimeException`. Both tables 
stay unchanged. Every losing request gets the same 500 when several tables are 
renamed to one new name at the same time.
   
   The cause is in Gravitino's Iceberg catalog. 
`IcebergCatalogOperations.renameTable` 
(`catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java:489-517`)
 calls `backend.wrapper().renameTable(...)` at `:511` but only catches 
`org.apache.iceberg.exceptions.NoSuchTableException` (`:514`). The Iceberg 
backend raises `org.apache.iceberg.exceptions.AlreadyExistsException`, which is 
not translated to Gravitino's `TableAlreadyExistsException` (as `createTable` 
does at `:615-616`). `TableExceptionHandler` 
(`server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java:324-325`)
 only maps `TableAlreadyExistsException` to 409, so the untranslated exception 
falls to the generic handler at `:336-337` and becomes a 500.
   
   ### Error message and/or stacktrace
   ```
   PUT /api/metalakes/ml/catalogs/cat/schemas/s/tables/a  
{"updates":[{"@type":"rename","newName":"b"}]}
   500 {"code":1002,"type":"RuntimeException","message":"Failed to operate 
object [a] operation [ALTER] under [s], reason [Cannot rename s.a to s.b. Table 
already exists]","stack":[
     "org.apache.iceberg.exceptions.AlreadyExistsException: Cannot rename s.a 
to s.b. Table already exists",
     "at 
org.apache.iceberg.inmemory.InMemoryCatalog.renameTable(InMemoryCatalog.java:181)",
     "at 
org.apache.iceberg.rest.CatalogHandlers.renameTable(CatalogHandlers.java:575)",
     "at 
org.apache.gravitino.iceberg.common.ops.IcebergCatalogWrapper.renameTable(IcebergCatalogWrapper.java:348)",
     "at 
org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogOperations.renameTable(IcebergCatalogOperations.java:511)",
     "at 
org.apache.gravitino.catalog.lakehouse.iceberg.IcebergCatalogOperations.alterTable(IcebergCatalogOperations.java:458)",
 ...
   ```
   
   ### How to reproduce
   1. Create a metalake, an Iceberg catalog, a schema and two tables:
      ```
      H='-u admin:x -H Content-Type:application/json -H 
Accept:application/vnd.gravitino.v1+json'
      curl $H -X POST http://127.0.0.1:8090/api/metalakes -d 
'{"name":"ml","comment":"","properties":{}}'
      curl $H -X POST http://127.0.0.1:8090/api/metalakes/ml/catalogs -d 
'{"name":"cat","type":"RELATIONAL","provider":"lakehouse-iceberg","comment":"","properties":{"catalog-backend":"memory","uri":"memory","warehouse":"/tmp/ml_cat"}}'
      curl $H -X POST 
http://127.0.0.1:8090/api/metalakes/ml/catalogs/cat/schemas -d 
'{"name":"s","comment":"","properties":{}}'
      for t in a b; do curl $H -X POST 
http://127.0.0.1:8090/api/metalakes/ml/catalogs/cat/schemas/s/tables -d 
"{\"name\":\"$t\",\"comment\":\"\",\"columns\":[{\"name\":\"id\",\"type\":\"long\",\"nullable\":true}],\"properties\":{}}";
 done
      ```
   2. Rename `a` to `b`:
      ```
      curl $H -X PUT 
http://127.0.0.1:8090/api/metalakes/ml/catalogs/cat/schemas/s/tables/a -d 
'{"updates":[{"@type":"rename","newName":"b"}]}'
      ```
      The response is the 500 above.
   
   ### Additional context
   Related: #14039 (same symptom for other object types, closed). The 2.0 OSS 
test suite checks `test_rename_onto_an_existing_name_is_a_conflict[table]` and 
`test_concurrent_renames_onto_one_target_name` found it. The Iceberg library 
correctly raises `AlreadyExistsException`; the missing translation is in 
Gravitino's catalog code.


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