From 2097286d18f2fa654d670b772c46861850ee2e11 Mon Sep 17 00:00:00 2001 From: liuheng Date: Fri, 6 Dec 2024 11:40:27 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=95=B0=E6=8D=AE=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=B8=8D=E4=B8=BA=E7=A9=BA=EF=BC=8C=E4=B9=9F=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit acf0e8a9ff7189bb6def8646729a004f18325350) --- opengauss-server.spec | 59 +++++++++++++++++++++++++++++-------------- upgrade.sh | 34 +++++++++++++++---------- 2 files changed, 60 insertions(+), 33 deletions(-) diff --git a/opengauss-server.spec b/opengauss-server.spec index bc45e00..9e927a7 100755 --- a/opengauss-server.spec +++ b/opengauss-server.spec @@ -13,7 +13,7 @@ Name: opengauss Version: 6.0.0 -Release: 18 +Release: 19 Summary: openGauss is an open source relational database management system License: MulanPSL-2.0 and MIT and BSD and zlib and TCL and Apache-2.0 and BSL-1.0 URL: https://gitee.com/opengauss/openGauss-server @@ -275,37 +275,49 @@ install -m 644 %{SOURCE28} %{buildroot}%{tmppath}/upgrade.sh popd %pre +# add opengauss user /usr/sbin/groupadd -r opengauss >/dev/null 2>&1 || : /usr/sbin/useradd -M -N -g opengauss -r -d %{datapath} -s /bin/bash -c "openGauss Server" opengauss >/dev/null 2>&1 || : # for install step # 1:install 2:upgrade -if [ $1 -gt 1 ]; then - echo "upgrade pre" -else +if [ $1 -eq 1 ]; then + echo "Preparing for install" portinfo=$(lsof -i:%{port}) if [ "${portinfo}" != "" ]; then echo "The port[%{port}] is occupied. Please use command 'lsof -i:%{port} to check it.'" exit 1 fi -fi - -%post -start_opengauss(){ - process_id=$(ps -ef | grep /var/lib/opengauss/data | grep -v grep | awk '{print $2}') - if [ "$process_id" != "" ]; then - echo "A process of opengauss already exists. Use command (ps -ef | grep /var/lib/opengauss/data) to confirm." - echo "Please kill the process and reinstall opengauss." + if [ -d /var/lib/opengauss/data ]; then + if [ "`ls -A /var/lib/opengauss/data`" != "" ]; then + echo "Datanode dir(/var/lib/opengauss/data) is not empty." + echo "Please delete dir and reinstall opengauss." + exit 1 + fi + process_id=$(ps -ef | grep /var/lib/opengauss/data | grep -v grep | awk '{print $2}') + if [ "$process_id" != "" ]; then + echo "A process of opengauss already exists. Use command (ps -ef | grep /var/lib/opengauss/data) to confirm." + echo "Please kill the process and reinstall opengauss." + exit 1 + fi + fi + +elif [ $1 -eq 2 ]; then + echo "Preparing for upgrade" + old_version=$(rpm -qi opengauss | grep -i version | awk -F':' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//') + if [ "$(printf '%s\n' "%{version}" "$old_version" | sort -V | head -n1)" == "$old_version" ]; then + echo "Error: New version (${version}) must be greater than the old version ($old_version)." exit 1 fi - - if [ "`ls -A /var/lib/opengauss/data`" != "" ]; then - echo "Datanode dir(/var/lib/opengauss/data) is not empty." - echo "Please delete dir and reinstall opengauss." + if [[ "${old_version}" == "2.1.0" && %{version} == "6.0.0" ]]; then + echo "The opengauss do not support upgrade from 2.1.0 to 6.0.0." exit 1 fi - +fi + +%post +start_opengauss(){ result=$(su - opengauss -c "source ~/.bash_profile; gs_initdb -D /var/lib/opengauss/data -U opengauss --nodename=single_node") if [ $? -ne 0 ]; then echo "Init openGauss database failed." @@ -426,12 +438,18 @@ else rm -rf /usr/local/opengauss fi mkdir -p /usr/local/opengauss - cp -rf /var/lib/opengauss/opengauss_upgrade/pkg_%{version}/* /usr/local/opengauss + upgrade_result=$(cat /var/lib/opengauss/opengauss_upgrade/tmp/upgrade_result.txt) + if [ $upgrade_result == "success" ]; then + echo "opengauss upgrade successfully" + cp -rf /var/lib/opengauss/opengauss_upgrade/pkg_%{version}/* /usr/local/opengauss + else: + echo "opengauss upgrade failed, rollback in progress" + cp -rf /var/lib/opengauss/opengauss_upgrade/bak/* /usr/local/opengauss + fi chown -R opengauss:opengauss /usr/local/opengauss chmod -R 755 /usr/local/opengauss chmod -R 700 /var/lib/opengauss/data systemctl restart opengauss.service - echo "opengauss upgrade successfully" fi @@ -445,6 +463,9 @@ fi %changelog +* Tue Dec 10 2024 liuheng - 6.0.0-19 +- Fix bugs: #IBAAVY + * Thu Dec 5 2024 xiaofan - 6.0.0-18 - Support riscv64 diff --git a/upgrade.sh b/upgrade.sh index 00d436b..1738a3a 100644 --- a/upgrade.sh +++ b/upgrade.sh @@ -17,10 +17,11 @@ version=6.0.0 GAUSS_BASE_PATH="/usr/local/opengauss" GAUSS_UPGRADE_BASE_PATH="/var/lib/opengauss/opengauss_upgrade/pkg_${version}" GAUSS_BACKUP_BASE_PATH="/var/lib/opengauss/opengauss_upgrade/bak" -GAUSS_TMP_PATH="${GAUSS_UPGRADE_BASE_PATH}/tmp" -GAUSS_LOG_FILE="${GAUSS_UPGRADE_BASE_PATH}/opengauss_upgrade.log" +GAUSS_TMP_PATH="/var/lib/opengauss/opengauss_upgrade/tmp" +GAUSS_LOG_FILE="/var/lib/opengauss/opengauss_upgrade/opengauss_upgrade.log" new_opengauss_dir=/var/lib/opengauss/pkg_${version} GAUSS_LISTEN_PORT=7654 +GAUSS_UPGRADE_RESULT_FILE=${GAUSS_TMP_PATH}/upgrade_result.txt function create_dir() { rm -rf ${GAUSS_BACKUP_BASE_PATH} @@ -318,6 +319,7 @@ function prepare_sql_all() { function pre_exec_sql() { if exec_sql "$GAUSS_TMP_PATH"/temp_sql/temp_upgrade_maindb.sql maindb && exec_sql "$GAUSS_TMP_PATH"/temp_sql/temp_upgrade_otherdb.sql otherdb; then debug "exec pre sql successfully" + return 0 else log "exec pre sql failed" return 1 @@ -535,20 +537,21 @@ function delete_tmp_files() { } function add_pg_proc_index() { - add_index="start transaction; set isinplaceupgrade=on; + version=$(gaussdb -V) + if [[ ! $version =~ "V500R002C00" && ! $version =~ "2.1.0" ]]; then + return 0 + fi + add_index_cmd="start transaction; set isinplaceupgrade=on; ALTER INDEX pg_proc_proname_args_nsp_index unusable; SET LOCAL inplace_upgrade_next_system_object_oids = IUO_CATALOG, false, true, 0, 0, 0, 9666; CREATE INDEX pg_catalog.pg_proc_proname_all_args_nsp_index on pg_catalog.pg_proc USING BTREE(proname name_ops, pronamespace oid_ops, propackageid oid_ops); SET LOCAL inplace_upgrade_next_system_object_oids = IUO_CATALOG, false, true, 0, 0, 0, 0; commit;" - version=$(gaussdb -V) - if [[ $version =~ "V500R002C00" || $version =~ "2.1.0" ]]; then - sqlbegin="gsql -p $GAUSS_LISTEN_PORT -X -t -A " - result=$(${sqlbegin} -d postgres -c "${add_index}") - if [ $? -ne 0 ]; then - log "Exec sql to get databases failed." - return 1 - fi + sqlbegin="gsql -p $GAUSS_LISTEN_PORT -X -t -A " + result=$(${sqlbegin} -d postgres -c "${add_index_cmd}") + if [ $? -ne 0 ]; then + log "Exec sql to get databases failed." + return 1 fi } @@ -569,6 +572,7 @@ function upgrade_pre() { pre_exec_sql if [ $? -ne 0 ]; then rollback_pre_sql + exit 1 fi } @@ -607,7 +611,8 @@ function upgrade_post() { debug "upgrade post sql successfully" else log "upgrade post sql failed" - return 1 + rollback_post + exit 1 fi } @@ -617,12 +622,12 @@ function upgrade_commit() { die "set upgrade_mode to 0 failed" ${err_upgrade_commit} fi # 2.删除临时文件 - delete_tmp_files + # delete_tmp_files } function cp_bak() { cp -rf ${GAUSS_BASE_PATH}/* ${GAUSS_BACKUP_BASE_PATH} - rm -rf ${GAUSS_BASE_PATH}/* + # rm -rf ${GAUSS_BASE_PATH}/* } function cp_new() { @@ -635,6 +640,7 @@ function main() { upgrade_post upgrade_commit stop_dbnode + echo "success" > $GAUSS_UPGRADE_RESULT_FILE # cp_bak # cp_new # remove_path ${GAUSS_UPGRADE_BASE_PATH}/bin -- Gitee