danhuawang commented on code in PR #15001:
URL: https://github.com/apache/gravitino/pull/15001#discussion_r4613107964
##########
dev/charts/gravitino/templates/schema-migrate-job.yaml:
##########
@@ -0,0 +1,189 @@
+{{- /*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */}}
+
+{{- if eq (include "gravitino.schemaMigrateEnabled" . | trim) "true" }}
+{{- $_ := include "gravitino.schemaMigrateSslValidate" . }}
+{{- $engine := include "gravitino.schemaMigrateEngine" . | trim }}
+{{- $dbHost := include "gravitino.schemaMigrateHost" . | trim }}
+{{- $dbPort := include "gravitino.schemaMigratePort" . | trim }}
+{{- $dbName := include "gravitino.schemaMigrateDatabase" . | trim }}
+{{- $pgSchema := include "gravitino.schemaMigrateCurrentSchema" . | trim }}
+{{- $pgSslMode := include "gravitino.schemaMigrateSslMode" . | trim }}
+{{- $sslCaSecret := include "gravitino.schemaMigrateSslCaSecretName" . | trim
}}
+{{- $hookWeight := .Values.schema.migrate.hookWeight | default "1" | toString
}}
+apiVersion: batch/v1
+kind: Job
+metadata:
+ name: {{ printf "%s-schema-migrate-r%d" .Release.Name .Release.Revision |
trunc 63 | trimSuffix "-" }}
+ namespace: {{ include "gravitino.namespace" . }}
+ labels:
+ {{- include "gravitino.labels" . | nindent 4 }}
+ app.kubernetes.io/component: schema-migrate
+ annotations:
+ helm.sh/hook: pre-install,pre-upgrade
Review Comment:
Addressed earlier: migration now runs as a regular Job (no Helm
pre-install/pre-upgrade hook), so ConfigMap / bundled DB dependencies are
created in the same revision. Deployment wait-init gates app startup on the
recorded schema version.
##########
dev/charts/gravitino/resources/scripts/schema-migrate.sh:
##########
@@ -0,0 +1,112 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Entity-store schema init for the Helm schema-migrate hook Job.
+set -euo pipefail
+
+: "${DB_ENGINE:?DB_ENGINE must be mysql or postgresql}"
+: "${DB_HOST:?DB_HOST is required}"
+: "${GRAVITINO_DB:?GRAVITINO_DB is required}"
+: "${SCRIPTS_DIR:=/scripts}"
+
+if [ "$DB_ENGINE" != mysql ] && [ "$DB_ENGINE" != postgresql ]; then
+ echo "ERROR: DB_ENGINE must be mysql or postgresql (got ${DB_ENGINE})" >&2
+ exit 1
+fi
+
+DB_PORT="${DB_PORT:-}"
+PG_CURRENT_SCHEMA="${PG_CURRENT_SCHEMA:-}"
+
+wait_for_db() {
+ echo "Waiting for ${DB_ENGINE} at ${DB_HOST}..."
+ if [ "$DB_ENGINE" = mysql ]; then
+ until mysql -h "$DB_HOST" "${mysql_extra[@]}" -u "$MYSQL_USER" -e "SELECT
1" >/dev/null 2>&1; do
+ echo "Waiting for MySQL to be ready..."
+ sleep 2
+ done
+ else
+ until PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$DB_HOST" -U
"$POSTGRES_USER" -d "$GRAVITINO_DB" -c "SELECT 1" >/dev/null 2>&1; do
+ echo "Waiting for PostgreSQL to be ready..."
+ sleep 2
+ done
+ fi
+}
+
+mysql_extra=()
+if [ -n "$DB_PORT" ]; then
+ mysql_extra+=(-P "$DB_PORT")
+fi
+
+apply_migrations() {
+ local version dir schema_file upgrade_file
+ version=$(cat "${SCRIPTS_DIR}/version.txt")
+ if [ -z "$version" ]; then
+ echo "ERROR: version.txt is empty" >&2
+ exit 1
+ fi
+ dir="${SCRIPTS_DIR}/${DB_ENGINE}"
+ schema_file=$(ls "$dir"/schema-*-"${DB_ENGINE}".sql | sort -V | awk -F'-' -v
ver="$version" '$2 <= ver {print $0}' | tail -n 1)
+ if [ ! -f "$schema_file" ]; then
+ echo "ERROR: Failed to find schema file under $dir for version $version"
>&2
+ exit 1
+ fi
+ upgrade_file=$(ls "$dir"/upgrade-*-to-*-"${DB_ENGINE}".sql | sort -V | awk
-F'-' -v ver="$version" '$4 <= ver {print $0}' | tail -n 1)
Review Comment:
Addressed earlier with the upgrade-chain rewrite, and tightened further:
inference now uses upgrade ADD COLUMN markers so ambiguous snapshots (1.3.0 vs
2.0.0) no longer skip required upgrades. Cross-version live coverage includes
1.2.0 (explicit baseline) and 1.3.0 (inference without baseline).
--
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]