diff --git a/.github/workflows/pr_build_linux.yml b/.github/workflows/pr_build_linux.yml index 703cd770b4b..0e056efbee1 100644 --- a/.github/workflows/pr_build_linux.yml +++ b/.github/workflows/pr_build_linux.yml @@ -202,45 +202,14 @@ jobs: restore-keys: | ${{ runner.os }}-java-maven- - # Split a Maven Central hiccup from a real lint violation. When the - # scalafix plugin fails to download (Central has answered 403, 429 and - # 404), Maven stops with "No plugin found for prefix 'scalafix'" and the - # red lint looks exactly like a violation. A scala-compiler jar that did - # not download shows up as "ClassNotFoundException: scala.tools.nsc.Main". - # The scalafix-syntactic job above lints offline after a retried - # download. Maven has no equally safe offline mode here, because the - # build resolves plugin and compiler artifacts as it goes, so this step - # retries the whole build instead, and only when Maven's error names a - # download. A lint violation or a compile error still fails on the first - # attempt. Maven caches a 404 in the local repository and will not ask - # again on its own, so the retries pass -U. Backoff matches - # .github/actions/maven-bootstrap: 10s, 20s, 40s plus 0-4s of jitter. + # Split a Maven Central hiccup from a real lint violation. Maven has no + # offline mode here because the build resolves plugin and compiler + # artifacts as it goes, so retry only on download errors; lint violations + # and compile errors still fail on the first attempt. - name: Run scalafix check - # Bash rather than the container default `sh`: the retry below needs - # pipefail, $RANDOM, and shell arithmetic. - shell: bash run: | - set -o pipefail - log=$(mktemp) - update= - for attempt in 1 2 3 4; do - if ./mvnw -B $update package -DskipTests scalafix:scalafix -Dscalafix.mode=CHECK \ - -Psemanticdb ${{ matrix.profile.maven_opts }} 2>&1 | tee "$log"; then - exit 0 - fi - if ! grep -qE '^\[ERROR\] .*(No plugin found for prefix|could not be resolved|Could not transfer|ClassNotFoundException: scala\.tools\.nsc\.Main)' "$log"; then - echo "::error::Maven failed for a reason other than a download, such as a lint violation or a compile error; not retrying." - exit 1 - fi - if [ "$attempt" -eq 4 ]; then - echo "::error::Maven could not download a plugin or dependency after $attempt attempts; this is not a lint violation." - exit 1 - fi - delay=$((10 * (1 << (attempt - 1)) + RANDOM % 5)) - echo "::warning::Maven failed to download a plugin or dependency (attempt $attempt of 4); retrying in ${delay}s with -U." - sleep "$delay" - update=-U - done + dev/ci/mvn-retry.sh ./mvnw -B package -DskipTests scalafix:scalafix -Dscalafix.mode=CHECK \ + -Psemanticdb ${{ matrix.profile.maven_opts }} - name: Setup Node.js uses: actions/setup-node@v7 @@ -786,14 +755,17 @@ jobs: path: ./tpch key: tpch-${{ hashFiles('.github/workflows/pr_build_linux.yml') }} + # Retry Maven download errors in the build and data-generation steps. In + # cache-refresh-only mode these jobs are the only Maven builds, and a + # failure in either step skips saving the Maven cache. - name: Build project run: | - ./mvnw -B -Prelease install -DskipTests + dev/ci/mvn-retry.sh ./mvnw -B -Prelease install -DskipTests - name: Generate TPC-H data (SF=1) if: steps.cache-tpch.outputs.cache-hit != 'true' run: | - cd spark && MAVEN_OPTS='-Xmx20g' ../mvnw -B -Prelease exec:java -Dexec.mainClass="org.apache.spark.sql.GenTPCHData" -Dexec.classpathScope="test" -Dexec.cleanupDaemonThreads="false" -Dexec.args="--location `pwd`/.. --scaleFactor 1 --numPartitions 1 --overwrite" + cd spark && MAVEN_OPTS='-Xmx20g' ../dev/ci/mvn-retry.sh ../mvnw -B -Prelease exec:java -Dexec.mainClass="org.apache.spark.sql.GenTPCHData" -Dexec.classpathScope="test" -Dexec.cleanupDaemonThreads="false" -Dexec.args="--location `pwd`/.. --scaleFactor 1 --numPartitions 1 --overwrite" - name: Run TPC-H queries if: ${{ !inputs.cache-refresh-only }} @@ -863,7 +835,7 @@ jobs: - name: Build project run: | - ./mvnw -B -Prelease install -DskipTests + dev/ci/mvn-retry.sh ./mvnw -B -Prelease install -DskipTests - name: Checkout tpcds-kit if: steps.cache-tpcds.outputs.cache-hit != 'true' @@ -882,7 +854,7 @@ jobs: - name: Generate TPC-DS data (SF=1) if: steps.cache-tpcds.outputs.cache-hit != 'true' run: | - cd spark && MAVEN_OPTS='-Xmx20g' ../mvnw -B -Prelease exec:java -Dexec.mainClass="org.apache.spark.sql.GenTPCDSData" -Dexec.classpathScope="test" -Dexec.cleanupDaemonThreads="false" -Dexec.args="--dsdgenDir `pwd`/../tpcds-kit/tools --location `pwd`/../tpcds-sf-1 --scaleFactor 1 --numPartitions 1" + cd spark && MAVEN_OPTS='-Xmx20g' ../dev/ci/mvn-retry.sh ../mvnw -B -Prelease exec:java -Dexec.mainClass="org.apache.spark.sql.GenTPCDSData" -Dexec.classpathScope="test" -Dexec.cleanupDaemonThreads="false" -Dexec.args="--dsdgenDir `pwd`/../tpcds-kit/tools --location `pwd`/../tpcds-sf-1 --scaleFactor 1 --numPartitions 1" - name: Run TPC-DS queries (Sort merge join) if: ${{ !inputs.cache-refresh-only }} diff --git a/dev/ci/mvn-retry.sh b/dev/ci/mvn-retry.sh new file mode 100755 index 00000000000..2cdddd6e1f1 --- /dev/null +++ b/dev/ci/mvn-retry.sh @@ -0,0 +1,61 @@ +#!/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. + +# Runs a Maven invocation with bounded retries on Maven Central download +# failures (HTTP 403, 404, 429, transfer errors, missing plugin prefix, or a +# missing scala-compiler jar). Non-download failures such as compile errors or +# lint violations still fail on the first attempt. +# +# Maven caches a 404 in the local repository and will not re-query Central on +# its own, so retries pass -U right after the Maven command. Backoff matches +# .github/actions/maven-bootstrap: 10s, 20s, 40s plus 0-4s of jitter. +# +# The captured log lives in a mktemp file outside the checkout and is removed +# on exit so downstream clean-tree checks stay clean. +# +# Usage: dev/ci/mvn-retry.sh [args...] + +set -euo pipefail + +mvn_cmd="${1:?usage: mvn-retry.sh [args...]}" +shift + +log=$(mktemp) +trap 'rm -f "$log"' EXIT + +retry_pattern='^\[(ERROR|FATAL)\] .*(No plugin found for prefix|could not be resolved|Could not transfer|Could not find artifact|ClassNotFoundException: scala\.tools\.nsc\.Main)' +update=() + +for attempt in 1 2 3 4; do + if "$mvn_cmd" ${update[@]+"${update[@]}"} "$@" 2>&1 | tee "$log"; then + exit 0 + fi + if ! grep -qE "$retry_pattern" "$log"; then + echo "::error::Maven failed for a reason other than a download, such as a compile error or lint violation; not retrying." + exit 1 + fi + if [ "$attempt" -eq 4 ]; then + echo "::error::Maven could not download a plugin or dependency after $attempt attempts." + exit 1 + fi + delay=$((10 * (1 << (attempt - 1)) + RANDOM % 5)) + echo "::warning::Maven failed to download a plugin or dependency (attempt $attempt of 4); retrying in ${delay}s with -U." + sleep "$delay" + update=(-U) +done