danhuawang commented on PR #13673:
URL: https://github.com/apache/gravitino/pull/13673#issuecomment-6818803698

   ### Design follow-up (merged PR): one migration path for in-cluster and 
external databases
   
   When you combine #13673 and #13674, please align the chart design so 
**bundled and external relational backends share the same migration 
implementation**, not two copies of the same shell (hook Job vs `init-mysql` / 
`init-postgresql`).
   
   A pattern that has worked well in production Helm charts for Gravitino looks 
like this:
   
   1. **Single migrate script** — One maintained shell script (shipped with the 
chart, e.g. mounted from a ConfigMap) implements wait-for-DB, version detection 
from the server image, fresh-vs-existing detection, upgrade-chain selection, 
and SQL application. The script is the only place that chooses `upgrade-*` vs 
`schema-*` files.
   
   2. **Single migrate Job** — A `batch/v1` Job runs that script against the 
resolved JDBC target. Host, port, database name, engine, credentials, and 
optional TLS come from **helpers** that branch on `mysql.enabled` / 
`postgresql.enabled` vs `entity.jdbcUrl`, not from separate inline bash in 
multiple templates.
   
   3. **Deployment init containers stop doing DDL** — Keep the `sqlfile` init 
(stage scripts + `version.txt`) if needed, but replace `init-mysql` / 
`init-postgresql` **SQL execution** with **wait-only** init containers that 
poll until the database records the expected schema version (via a small 
metadata table or equivalent). That removes rolling-update races (#11099) for 
bundled DBs as well as external ones.
   
   4. **Hook ordering** — For **external** databases, a `pre-install` / 
`pre-upgrade` hook Job is safe because the DB already exists. For **bundled** 
databases, a `pre-install` hook that waits on the subchart Service can deadlock 
on first install (your design doc already documents this). The usual split is: 
hook Job (or hook scale-down + migrate) for external; **non-hook** migrate Job 
for bundled that can start once the in-cluster database is reachable, while 
Gravitino Pods wait on the version gate before becoming Ready.
   
   5. **Upgrade semantics in the script** — Prefer chaining `upgrade-A-to-B` 
scripts to the image version, skipping full `schema-*.sql` on non-empty 
catalogs, and failing fast when intermediate scripts are missing—rather than 
“one highest upgrade + always re-apply schema,” which matches today’s init 
containers but does not match `how-to-upgrade.md`.
   
   The merged PR should **not** leave bundled init containers and the external 
hook Job as two divergent copies of `awk`/`mysql`/`psql` blocks.
   
   ### CI: add upgrade coverage to chart-test
   
   `helm unittest` and `ct install` alone are not enough for schema migration 
changes. Please extend **`.github/workflows/chart-test.yaml`** (or a dedicated 
workflow under `dev/ci`) with at least one **in-place upgrade** scenario on 
kind, for example:
   
   - **In-cluster MySQL or PostgreSQL** — `helm install` at chart/app version 
*A* (or image tag *A*) with bundled DB enabled, create a minimal metalake (or 
assert core tables), then `helm upgrade` to version *B*, wait for the migrate 
Job, assert Job success and Gravitino Pods Ready.
   - **External JDBC** (stretch or follow-up) — PostgreSQL or MySQL reachable 
from the cluster (sidecar DB or a small Deployment in kind), `entity.jdbcUrl` 
pointing at it, same install → upgrade → assert migrate Job path.
   
   Document expected before/after schema behavior in the workflow (even if the 
community chart does not yet ship `gravitino_schema_migration`, assert 
something deterministic: Job completion, server `/api/version`, or a 
table/version probe). This should run on PRs that touch 
`dev/charts/gravitino/**` migration templates or the shared migrate script.
   
   Please fold these into the single combined PR so reviewers can see design + 
CI together.


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