You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "bharos (via GitHub)" <gi...@apache.org> on 2026/01/09 20:25:17 UTC

[PR] [#9666] Fix Iceberg migrate procedure by preserving stageCreate flag and avoiding premature JDBC commits [gravitino]

bharos opened a new pull request, #9667:
URL: https://github.com/apache/gravitino/pull/9667

   
   
   <!--
   1. Title: [#<issue>] <type>(<scope>): <subject>
      Examples:
        - "[#123] feat(operator): support xxx"
        - "[#233] fix: check null before access result in xxx"
        - "[MINOR] refactor: fix typo in variable name"
        - "[MINOR] docs: fix typo in README"
        - "[#255] test: fix flaky test NameOfTheTest"
      Reference: https://www.conventionalcommits.org/en/v1.0.0/
   2. If the PR is unfinished, please mark this PR as draft.
   -->
   
   ### What changes were proposed in this pull request?
   
   This PR fixes the Iceberg system.migrate() procedure for JDBC-backed catalogs by addressing two bugs:
   
   Fix #1: Preserve stageCreate flag in IcebergTableOperationExecutor
   
   Modified IcebergTableOperationExecutor.java to preserve the stageCreate=true flag when rebuilding CreateTableRequest with owner override
   Previously, the flag was lost during request reconstruction, causing the staging protocol to fail
   Fix #2: Implement custom staging for JDBC catalogs
   
   Added stageTableCreateWithoutCommit() method in IcebergCatalogWrapper.java that bypasses Apache Iceberg's CatalogHandlers.stageTableCreate()
   The standard Iceberg implementation incorrectly calls createTransaction() for JDBC catalogs, which immediately commits the table to the database
   Our custom implementation follows the 3-phase staging protocol: (1) stage metadata without catalog registration, (2) client writes data, (3) atomic commit with assert-create
   
   ### Why are the changes needed?
   
   The system.migrate() procedure fails when migrating external Iceberg tables to JDBC-backed catalogs (MySQL, PostgreSQL) with the error:
   ```
   org.apache.iceberg.exceptions.AlreadyExistsException: Table already exists in database
   ```
   
   Root Cause:
   The staging protocol requires 3 distinct phases to safely migrate tables with existing data:
   
   Stage: Create table metadata without registering in the catalog
   Write: Client writes/copies data files to the staged location
   Commit: Atomically register the table with assert-create to prevent race conditions
   JDBC catalogs skip phase 1 and immediately commit the table to the database, causing the migration to fail because the table already exists when phase 3 attempts the final commit.
   
   This is a critical bug that makes it impossible to migrate existing Iceberg tables to Gravitino JDBC catalogs.
   
   (Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, describe the bug.)
   
   Fix: #9666 
   
   ### Does this PR introduce _any_ user-facing change?
   
   No user-facing API changes. This fix enables the system.migrate() procedure to work correctly with JDBC catalogs, which was previously broken.
   
   ### How was this patch tested?
   Manual Testing:
   
   Configured Gravitino with JDBC catalog (MySQL backend)
   Created external Iceberg table in Hive catalog
   Successfully migrated table using CALL system.migrate('catalog.database.table')
   Verified table metadata and data files are correctly staged and committed
   Confirmed migration fails without the fix (table already exists error)


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#9666]fix(iceberg): Fix Iceberg migrate procedure by preserving stageCreate flag [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi merged PR #9667:
URL: https://github.com/apache/gravitino/pull/9667


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#9666]fix(iceberg): Fix Iceberg migrate procedure by preserving stageCreate flag [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on PR #9667:
URL: https://github.com/apache/gravitino/pull/9667#issuecomment-3732178694

   Thanks, merged to branch main & 1.1


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org