yuqi1129 commented on issue #12519:
URL: https://github.com/apache/gravitino/issues/12519#issuecomment-6823692122

   This is useful work, but it is not a high priority for the current 
iteration. We can plan it for the next iteration.
   
   The scope should cover both version tracking and migration execution. A 
version table alone would not address the current Helm behavior: selecting only 
the latest applicable upgrade script, tolerating its failure, and then running 
the full schema script.
   
   Proposed plan:
   
   1. **Add database-level migration metadata.** Track the last successfully 
applied schema version, the migration target and execution state, and a stable 
migration ID/checksum. Keep the required database schema version separate from 
the application version. Do not reuse the entity-level 
`metalake_meta.schema_version` field.
   2. **Handle existing databases explicitly.** For an existing database 
without version records, require an operator-supplied baseline and validate its 
structure before recording it. Initialize a fresh database only after 
confirming that it is uninitialized. Do not infer the database version from the 
running binary or stamp it as current after an unsuccessful migration.
   3. **Implement one shared migration runner.** Reuse the existing SQL scripts 
for MySQL, PostgreSQL and H2. Follow a complete migration chain, with each 
step's source version equal to the current database version, and advance the 
recorded version only after successful execution and validation. An 
already-current database should be a no-op. Reject missing migration paths, 
unknown versions, checksum mismatches and downgrades. This belongs in the 
upgrade tooling and does not require extending `JDBCBackend` or other 
business/storage interfaces.
   4. **Make failures and recovery explicit.** Stop on SQL errors, remove the 
fallback from a failed upgrade to a full schema script, and enable PostgreSQL 
`ON_ERROR_STOP`. Preserve in-progress/failed state across interruptions. MySQL 
DDL can commit implicitly, so retain retry-safe SQL and provide a controlled 
resume/repair procedure rather than assuming the whole migration can be rolled 
back or blindly marking it successful.
   5. **Integrate deployment entry points.** Use the same runner for manual 
deployments and Helm. Serialize migrations for the same metadata 
database/schema, and require old instances to be stopped before schema changes. 
A pre-upgrade Job does not itself stop old pods. Pod init containers should 
validate the required schema version instead of independently performing 
upgrades; bundled-database startup ordering also needs to be handled.
   6. **Add validation and documentation.** Cover fresh initialization, 
valid/invalid legacy baselines, multi-hop upgrades, repeated no-op runs, 
partial failures and process interruption, concurrent runners, and unsupported 
versions/downgrades across all three backends. Verify resulting tables, 
columns, indexes and existing data, not just the version record. Document 
backup, maintenance, baseline and recovery procedures.
   
   Related work:
   - #13689 already improves retryability of the 1.3.0-to-2.0.0 scripts; it 
does not provide database version tracking.
   - #13673 introduces a Helm migration Job, but currently retains the existing 
best-effort script-selection/execution behavior. We should coordinate with that 
PR and have it use the shared runner rather than introduce another copy of the 
migration logic.
   
   A server-side, read-only schema compatibility check can be considered 
separately after this migration protocol is established. The first 
implementation should stay focused on reliable, observable upgrade execution.
   


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