This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/master/pr-19928-6981bed9d5233642e07e104709fb093a89be4f22 in repository https://gitbox.apache.org/repos/asf/hudi.git
commit 97a8eb895ca37175976d5acda94778823fa82d0b Author: voonhous <[email protected]> AuthorDate: Wed Nov 25 05:58:39 2026 +0000 test(spark): run SQL suites two at a time on three shards (#19928) * test(spark): run SQL suites two at a time on three shards Add hudi.scalatest.parallel (default false) and hudi.scalatest.threads (default 0), mapped to the scalatest plugin's parallel and threadCount parameters: suites run concurrently in one JVM, tests within a suite stay sequential. Set to true and 2 on the three Java 17 Scala shards that already share one SparkContext (dml-1, dml-2, other-1). Two fixes the local two-thread loop exposed: the per-test cleanup owns a table only by the suite's generateTableName prefix or as a session temp view, since the earlier "not a generated name" clause let one suite drop another's derived names mid-test; and two test helpers that sorted log file paths as strings now sort by the log file comparator, because the write token precedes the instant in the file name and stage ids compare as text (latent on master). Supersedes the proof of concept in #19925, where the dml shard at two threads measured 27:58, 35:27 and 35:32 against 41 to 56 minutes serial, with the same 326 tests each time. * test(spark): four suites at a time on SQL shards Phase 4a measurement: the three shards ran two suites at a time with both threads busy 87 to 92 percent of the wall clock, so the thread count goes to four to see whether the shards still scale on a 4 vCPU runner. Same three shards, same flags. * test(spark): back to two suites at a time Four threads were measured twice on the three shards: dml-1 17:20 and 13:35 against 19:36 to 20:19 at two threads, dml-2 and other-1 inside their two-thread spread, all green. The gain is on a shard that does not set the run's wall clock, and every suite runs about 60 percent longer under four-way contention on the 4 vCPU runner, so two threads stays the default. Four is a measured, safe setting for a shard that becomes the critical path. This reverts commit b8abd450c3c4. * test(spark): narrow the cleanup's ignored failures and test table ownership Per-test cleanup propagates every failure in per-suite mode and, in shared mode, ignores only a database or table another suite dropped meanwhile. Add a suite checking that the cleanup drops this suite's tables and temp views and leaves another session's alone. Restore master's log file sort in validateDeleteLogBlockPrecombineNullOrZero, where order does not matter. --- .github/workflows/bot.yml | 18 +++---- .../sql/hudi/common/HoodieSparkSqlTestBase.scala | 41 ++++++++++------ .../hudi/ddl/TestSharedSessionTableCleanup.scala | 55 ++++++++++++++++++++++ pom.xml | 5 ++ 4 files changed, 95 insertions(+), 24 deletions(-) diff --git a/.github/workflows/bot.yml b/.github/workflows/bot.yml index 8dbbf0849a9b..ce8f3a2514b9 100644 --- a/.github/workflows/bot.yml +++ b/.github/workflows/bot.yml @@ -1105,7 +1105,7 @@ jobs: flags: spark-java-tests token: ${{ secrets.CODECOV_TOKEN }} - # sharedSession: this shard holds only HoodieSparkSqlTestBase suites, which share one SparkContext + # sharedSession + parallel: this shard holds only HoodieSparkSqlTestBase suites, which share one SparkContext and run two at a time test-spark-java17-scala-dml-1: if: *route needs: changes @@ -1150,14 +1150,14 @@ jobs: SPARK_PROFILE: ${{ matrix.sparkProfile }} SPARK_MODULES: ${{ matrix.sparkModules }} run: - mvn test -Punit-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_DML1_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "hudi-common,$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true + mvn test -Punit-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_DML1_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "hudi-common,$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true -Dhudi.scalatest.parallel=true -Dhudi.scalatest.threads=2 - name: Scala FT - Spark (dml.others) env: SCALA_PROFILE: ${{ matrix.scalaProfile }} SPARK_PROFILE: ${{ matrix.sparkProfile }} SPARK_MODULES: ${{ matrix.sparkModules }} run: - mvn test -Pfunctional-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_DML1_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true + mvn test -Pfunctional-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_DML1_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true -Dhudi.scalatest.parallel=true -Dhudi.scalatest.threads=2 - name: Test timing summary if: always() run: python3 scripts/ci/test_timing_summary.py --title "${{ github.job }}" @@ -1171,7 +1171,7 @@ jobs: flags: spark-scala-tests token: ${{ secrets.CODECOV_TOKEN }} - # sharedSession: this shard holds only HoodieSparkSqlTestBase suites, which share one SparkContext + # sharedSession + parallel: this shard holds only HoodieSparkSqlTestBase suites, which share one SparkContext and run two at a time test-spark-java17-scala-dml-2: if: *route needs: changes @@ -1216,14 +1216,14 @@ jobs: SPARK_PROFILE: ${{ matrix.sparkProfile }} SPARK_MODULES: ${{ matrix.sparkModules }} run: - mvn test -Punit-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_DML2_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "hudi-common,$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true + mvn test -Punit-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_DML2_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "hudi-common,$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true -Dhudi.scalatest.parallel=true -Dhudi.scalatest.threads=2 - name: Scala FT - Spark (dml.insert, dml.schema) env: SCALA_PROFILE: ${{ matrix.scalaProfile }} SPARK_PROFILE: ${{ matrix.sparkProfile }} SPARK_MODULES: ${{ matrix.sparkModules }} run: - mvn test -Pfunctional-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_DML2_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true + mvn test -Pfunctional-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_DML2_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true -Dhudi.scalatest.parallel=true -Dhudi.scalatest.threads=2 - name: Test timing summary if: always() run: python3 scripts/ci/test_timing_summary.py --title "${{ github.job }}" @@ -1273,7 +1273,7 @@ jobs: if-no-files-found: ignore - # sharedSession: this shard holds only HoodieSparkSqlTestBase suites, which share one SparkContext + # sharedSession + parallel: this shard holds only HoodieSparkSqlTestBase suites, which share one SparkContext and run two at a time test-spark-java17-scala-other-1: if: *route needs: changes @@ -1318,14 +1318,14 @@ jobs: SPARK_PROFILE: ${{ matrix.sparkProfile }} SPARK_MODULES: ${{ matrix.sparkModules }} run: - mvn test -Punit-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_OTHERS1_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "hudi-common,$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true + mvn test -Punit-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_OTHERS1_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "hudi-common,$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true -Dhudi.scalatest.parallel=true -Dhudi.scalatest.threads=2 - name: Scala FT - Spark (procedure, ddl) env: SCALA_PROFILE: ${{ matrix.scalaProfile }} SPARK_PROFILE: ${{ matrix.sparkProfile }} SPARK_MODULES: ${{ matrix.sparkModules }} run: - mvn test -Pfunctional-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_OTHERS1_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true + mvn test -Pfunctional-tests -Pjava17 -D"$SCALA_PROFILE" -D"$SPARK_PROFILE" -Dtest=skipJavaTests $SCALA_TEST_OTHERS1_FILTER -Dsurefire.failIfNoSpecifiedTests=false -pl "$SPARK_COMMON_MODULES,$SPARK_MODULES" $MVN_ARGS -Djacoco.skip=false -Dhudi.spark.test.sharedSession=true -Dhudi.scalatest.parallel=true -Dhudi.scalatest.threads=2 - name: Test timing summary if: always() run: python3 scripts/ci/test_timing_summary.py --title "${{ github.job }}" diff --git a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/common/HoodieSparkSqlTestBase.scala b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/common/HoodieSparkSqlTestBase.scala index 8b4b6eb3bfd8..3ad84e0bc11b 100644 --- a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/common/HoodieSparkSqlTestBase.scala +++ b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/common/HoodieSparkSqlTestBase.scala @@ -39,6 +39,9 @@ import org.apache.hudi.testutils.HoodieClientTestUtils.{createMetaClient, getSpa import org.apache.hadoop.fs.Path import org.apache.spark.SparkConf import org.apache.spark.sql.{Row, SparkSession} +import org.apache.spark.sql.catalyst.TableIdentifier +import org.apache.spark.sql.catalyst.analysis.{NoSuchDatabaseException, NoSuchTableException} +import org.apache.spark.sql.catalyst.catalog.SessionCatalog import org.apache.spark.sql.catalyst.util.DateTimeUtils import org.apache.spark.sql.connector.catalog.CatalogManager import org.apache.spark.sql.hudi.catalog.HoodieCatalog @@ -237,22 +240,21 @@ class HoodieSparkSqlTestBase extends FunSuite with BeforeAndAfterAll { /** * Drops the tables a test left behind. Per-suite mode owns the whole catalog. Shared mode shares the - * external catalog with every other suite in the JVM, so it drops only this suite's generateTableName - * tables plus any table whose name is not of that form (fixed names and temp views); under serial - * execution those can only come from the test that just ran. Fixed names are renamed in a later step. + * external catalog with every other suite in the JVM and those suites may be mid-test, so it drops + * only the tables whose name carries this suite's generateTableName prefix, plus its own temp views. */ - private def dropSuiteTables(): Unit = { + protected def dropSuiteTables(): Unit = { val catalog = spark.sessionState.catalog catalog.listDatabases().foreach { db => - val tables = catalog.listTables(db) - val toDrop = if (sharedSessionEnabled) tables.filter(table => ownsTable(table.table)) else tables + val tables = ignoringConcurrentDrops(Seq.empty[TableIdentifier])(catalog.listTables(db)) + val toDrop = if (sharedSessionEnabled) tables.filter(table => ownsTable(catalog, table)) else tables toDrop.foreach { table => if (sharedSessionEnabled && !catalog.isTempView(table)) { // Shared mode keeps one index map per table; drop this table's entry with the table. Try(new StoragePath(catalog.getTableMetadata(table).location)) .foreach(path => HoodieInMemoryHashIndex.clear(path)) } - catalog.dropTable(table, true, true) + ignoringConcurrentDrops(())(catalog.dropTable(table, true, true)) } } if (sharedSessionEnabled) { @@ -264,12 +266,24 @@ class HoodieSparkSqlTestBase extends FunSuite with BeforeAndAfterAll { } /** - * Shared mode: a table is this suite's if its name starts with this suite's prefix, or if it does not start with - * any suite's generated name. A prefix match, not a full one, so a name built from a generated one - * (`${tableName}_ro`, `${generateTableName}_timestamp_type`) stays with the suite that generated it. + * Shared mode: another suite may drop its own database between this suite listing it and using it, so + * a missing database or table yields the fallback. Any other failure, and every failure in per-suite + * mode, propagates. */ - private def ownsTable(name: String): Boolean = { - name.startsWith(tableNamePrefix) || !HoodieSparkSqlTestBase.GENERATED_TABLE_NAME.matcher(name).lookingAt() + private def ignoringConcurrentDrops[T](fallback: => T)(body: => T): T = { + try { + body + } catch { + case _: NoSuchDatabaseException | _: NoSuchTableException if sharedSessionEnabled => fallback + } + } + + /** + * Shared mode: a table is this suite's if generateTableName produced its name (derived names such as + * `s"${generateTableName}_pt"` keep the prefix), or if it is a temp view, which is session-scoped. + */ + private def ownsTable(catalog: SessionCatalog, table: TableIdentifier): Boolean = { + catalog.isTempView(table) || table.table.startsWith(tableNamePrefix) } protected lazy val tableNamePrefix: String = s"h${getClass.getSimpleName.toLowerCase}_" @@ -598,9 +612,6 @@ object HoodieSparkSqlTestBase { // Read side held by every suite for its whole run, write side by an ExclusiveSuite for its whole run. val suiteLock = new ReentrantReadWriteLock(true) - // Table names produced by generateTableName (without a database prefix); names built from one start with it. - private[common] val GENERATED_TABLE_NAME: Pattern = Pattern.compile("h[a-z0-9]+_[0-9]+") - private[common] lazy val sharedWarehouse: File = { val dir = Utils.createTempDir() Utils.deleteRecursively(dir) diff --git a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/ddl/TestSharedSessionTableCleanup.scala b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/ddl/TestSharedSessionTableCleanup.scala new file mode 100644 index 000000000000..19cefea1c86b --- /dev/null +++ b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/ddl/TestSharedSessionTableCleanup.scala @@ -0,0 +1,55 @@ +/* + * 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. + */ + +package org.apache.spark.sql.hudi.ddl + +import org.apache.spark.sql.catalyst.TableIdentifier +import org.apache.spark.sql.hudi.common.HoodieSparkSqlTestBase + +class TestSharedSessionTableCleanup extends HoodieSparkSqlTestBase { + + test("Test cleanup drops this suite's tables and temp views, not another suite's") { + assume(HoodieSparkSqlTestBase.sharedSessionEnabled, "per-suite mode owns the whole catalog") + // Stands in for a suite running at the same time: its own session on the shared catalog. + val otherSuite = spark.newSession() + val otherTable = "shared_session_cleanup_other_suite_tbl" + val otherView = "shared_session_cleanup_other_suite_view" + val ownTable = generateTableName + val ownDerivedTable = s"${generateTableName}_pt" + val ownView = "shared_session_cleanup_own_view" + try { + otherSuite.sql(s"create table $otherTable (id int) using parquet") + otherSuite.range(1).createOrReplaceTempView(otherView) + spark.sql(s"create table $ownTable (id int) using parquet") + spark.sql(s"create table $ownDerivedTable (id int) using parquet") + spark.range(1).createOrReplaceTempView(ownView) + + dropSuiteTables() + + val catalog = spark.sessionState.catalog + assert(!catalog.tableExists(TableIdentifier(ownTable))) + assert(!catalog.tableExists(TableIdentifier(ownDerivedTable))) + assert(!catalog.isTempView(TableIdentifier(ownView))) + assert(catalog.tableExists(TableIdentifier(otherTable))) + assert(otherSuite.sessionState.catalog.isTempView(TableIdentifier(otherView))) + } finally { + otherSuite.sql(s"drop table if exists $otherTable") + } + } +} diff --git a/pom.xml b/pom.xml index 259b6a146325..c50b0db9860e 100644 --- a/pom.xml +++ b/pom.xml @@ -278,6 +278,9 @@ <lance.skip.tests>false</lance.skip.tests> <!-- Scala SQL suites: one shared SparkContext per JVM with a child session per suite (see HoodieSparkSqlTestBase) --> <hudi.spark.test.sharedSession>false</hudi.spark.test.sharedSession> + <!-- Run scalatest suites concurrently (needs hudi.spark.test.sharedSession=true); 0 threads = scalatest's default --> + <hudi.scalatest.parallel>false</hudi.scalatest.parallel> + <hudi.scalatest.threads>0</hudi.scalatest.threads> <vortex.version>0.76.0</vortex.version> <vortex.spark.artifact>vortex-spark_${scala.binary.version}</vortex.spark.artifact> <vortex.skip.tests>false</vortex.skip.tests> @@ -628,6 +631,8 @@ <vortex.skip.tests>${vortex.skip.tests}</vortex.skip.tests> <hudi.spark.test.sharedSession>${hudi.spark.test.sharedSession}</hudi.spark.test.sharedSession> </systemProperties> + <parallel>${hudi.scalatest.parallel}</parallel> + <threadCount>${hudi.scalatest.threads}</threadCount> </configuration> <executions> <execution>
