From e40d055f6ecc1f11a7213c0b2a54d4e21fa6e58b Mon Sep 17 00:00:00 2001 From: Roshan Kanwar Date: Fri, 31 May 2024 13:08:10 +0530 Subject: [PATCH] Ensure accurate metadata inconsistency checks (#2609) (#2625) This commit addresses metadata inconsistency checks, ensuring they occur in the appropriate places. Additionally, steps have been added to verify the existence of the inconsistency checker function before performing the metadata checks. Task: BABEL-4139 Signed-off-by: Roshan Kanwar --- .../check-babelfish-inconsistency/action.yml | 34 +++++++++++++++++-- .../setup-base-version/action.yml | 9 ++++- .github/workflows/major-version-upgrade.yml | 5 ++- .../workflows/singledb-version-upgrade.yml | 3 +- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/.github/composite-actions/check-babelfish-inconsistency/action.yml b/.github/composite-actions/check-babelfish-inconsistency/action.yml index 852879a8a7..e4c6215b4f 100644 --- a/.github/composite-actions/check-babelfish-inconsistency/action.yml +++ b/.github/composite-actions/check-babelfish-inconsistency/action.yml @@ -6,6 +6,36 @@ runs: - name: Check Babelfish metadata inconsistency id: check-babelfish-inconsistency run: | - output=$(sqlcmd -S localhost -U jdbc_user -P 12345678 -Q "SELECT 'check_result=',sys.check_for_inconsistent_metadata() GO" | grep 'check_result' | sed 's/[[:blank:]]//g') - echo "$output" >> "$GITHUB_OUTPUT" + # Check if the function exists + function_exists=$(sqlcmd -S localhost -U jdbc_user -P 12345678 -Q " + SELECT CASE WHEN COUNT(*) > 0 THEN 'exists' ELSE 'not_exists' END + FROM pg_proc + WHERE proname = 'check_for_inconsistent_metadata';" | grep -o 'exists\|not_exists') + + echo "::set-output name=function_exists::$function_exists" + echo "Check Babelfish metadata inconsistency function exists: $function_exists" + + # If the function exists, run the metadata inconsistency check + if [[ "$function_exists" == "exists" ]]; then + output=$(sqlcmd -S localhost -U jdbc_user -P 12345678 -Q "SELECT 'check_result=', sys.check_for_inconsistent_metadata() GO" | grep 'check_result' | sed 's/[[:blank:]]//g') + check_result=$(echo "$output" | grep -oP 'check_result=\K.+') + echo "Check Babelfish metadata inconsistency result: $check_result" + + if [[ "$check_result" == "1" ]]; then + echo "Check Babelfish metadata inconsistency failed" + + # Fetch and print the detailed inconsistent rules + inconsistent_rules=$(sqlcmd -S localhost -U jdbc_user -P 12345678 -Q " + SELECT DISTINCT object_type, schema_name, object_name, detail::text + FROM sys.babelfish_inconsistent_metadata();") + + echo "Babelfish Inconsistent Metadata failing rules:" + echo "$inconsistent_rules" + exit 1 + else + echo "Check Babelfish metadata inconsistency succeeded" + fi + else + echo "The function check_for_inconsistent_metadata does not exist, skipping metadata check." + fi shell: bash diff --git a/.github/composite-actions/setup-base-version/action.yml b/.github/composite-actions/setup-base-version/action.yml index fbc6a4d853..508f5d7dd1 100644 --- a/.github/composite-actions/setup-base-version/action.yml +++ b/.github/composite-actions/setup-base-version/action.yml @@ -227,8 +227,15 @@ runs: python3 upgrade_validation.py shell: bash + - name: Run Babelfish metadata inconsistency check + id: check-babelfish-inconsistency + if: always() && steps.run-dependency-check.outcome == 'success' + uses: ./.github/composite-actions/check-babelfish-inconsistency + - name: Upload artifacts - if: always() && steps.run-dependency-check.outcome == 'failure' + if: | + always() && (steps.run-dependency-check.outcome == 'failure' + || steps.check-babelfish-inconsistency.outcome == 'failure') run: | mkdir -p ~/upgrade cp test/python/output/upgrade_validation/* ~/upgrade diff --git a/.github/workflows/major-version-upgrade.yml b/.github/workflows/major-version-upgrade.yml index 42d112c3b1..770462fbd2 100644 --- a/.github/workflows/major-version-upgrade.yml +++ b/.github/workflows/major-version-upgrade.yml @@ -197,9 +197,8 @@ jobs: - name: Run pg_upgrade id: run-pg_upgrade if: | - always() && steps.setup-new-datadir.outcome == 'success' - && steps.check-babelfish-inconsistency.outcome == 'success' - && steps.check-babelfish-inconsistency.outputs.check_result == 0 + always() && steps.setup-new-datadir.outcome == 'success' + && steps.check-babelfish-inconsistency.outcome == 'success' uses: ./.github/composite-actions/run-pg-upgrade - name: Disable TDS fault injection tests in release mode diff --git a/.github/workflows/singledb-version-upgrade.yml b/.github/workflows/singledb-version-upgrade.yml index 0da25fa84f..d523b552ac 100644 --- a/.github/workflows/singledb-version-upgrade.yml +++ b/.github/workflows/singledb-version-upgrade.yml @@ -33,8 +33,7 @@ jobs: id: upgrade-and-verify if: | always() && steps.setup-base-version.outcome == 'success' - && steps.check-babelfish-inconsistency.outcome == 'success' - && steps.check-babelfish-inconsistency.outputs.check_result == 0 + && steps.check-babelfish-inconsistency.outcome == 'success' uses: ./.github/composite-actions/major-version-upgrade-util with: engine_branch: latest