Skip to content

test: drain the listener bus before registering Iceberg test listeners - #6809

Merged
viirya merged 1 commit into
apache:mainfrom
viirya:fix-iceberg-write-report-flaky
Oct 9, 2026
Merged

viirya merged 1 commit into
apache:mainfrom
viirya:fix-iceberg-write-report-flaky

Conversation

@viirya

@viirya viirya commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

No issue filed; this fixes a flaky test seen in CI on #6664.

Rationale for this change

CometIcebergWriteActionSuite "write report records which writer ran each Iceberg write" fails intermittently. The failure on #6664 (Spark 4.1, JDK 17 [scans]) was:

ArraySeq("spark", "native", "jvm", "jvm", "spark") did not equal List("native", "jvm", "jvm", "spark")

The extra leading record is ReportedWrite(spark,AppendData,List(),false). #6693 added a setup write right before the listener window on Spark 3.5+, with the split operator disabled, so it plans Spark's AppendData. reportedWrites registers its QueryExecutionListener without draining the listener bus first. These listeners receive events asynchronously from the bus, and the listener manager hands each event to whichever listeners are registered when it is dispatched. So when the bus is behind, the setup write's event can arrive after registration and gets recorded. The helper already drains after the action, but not before registering.

What changes are included in this PR?

Call CometListenerBusUtils.waitUntilEmpty before registering the listener in every Iceberg test helper that captured events without draining first:

  • reportedWrites in CometIcebergWriteActionSuite (the failing test and the other write report tests).
  • capturePlans and captureFailedPlans in CometIcebergTestBase. captureWrite and many other tests go through these, and the setup writes before them could leak plans into the capture in the same way.
  • The task-end listener in "a failed write job deletes the data files of tasks that completed". A leftover task-end event from the seed insert could count down JobAbortGate before the write's own tasks finish.
  • captureSqlPlans in CometIcebergRewriteActionSuite, and capturePlans in CometIcebergWriteBenchmark.

captureWritePlan in CometIcebergWriteDetectionSuite and taskInputMetrics in CometIcebergNativeSuite already drain before registering.

How are these changes tested?

Test-only change. On Spark 4.1, with the target test temporarily repeated 30 times, all iterations pass. The race did not reproduce locally on its own, so to force it I temporarily added a SparkListener that sleeps 300 ms on each SparkListenerSQLExecutionEnd, which makes the shared queue lag behind:

  • Without the new drain in reportedWrites: fails with the same ArraySeq("spark", "native", "jvm", "jvm", "spark") mismatch seen in CI.
  • With it: passes.

CometIcebergWriteActionSuite and CometIcebergRewriteActionSuite pass in full on Spark 4.1.

Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions github-actions Bot added enhancement New feature or request test Testing related area:Iceberg labels Oct 9, 2026
@viirya
viirya requested a review from andygrove October 9, 2026 03:12

@manuzhang manuzhang left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Follow-ups that need not block this PR:

  1. Apply the same pre-registration drain to the three helpers in CometMergeRowsNativeSuiteBase, which carry the identical race.
  2. Decide on a timeout policy for the drain, either catching TimeoutException as captureWritePlan does or passing a longer deadline, and apply it consistently.
  3. Consolidate the idiom into withQueryExecutionListener and withSparkListener helpers on CometListenerBusUtils so new call sites cannot forget the drain.

@viirya
viirya added this pull request to the merge queue Oct 9, 2026
@viirya

viirya commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Thanks @manuzhang

Merged via the queue into apache:main with commit 00a4b42 Oct 9, 2026
42 checks passed
@viirya
viirya deleted the fix-iceberg-write-report-flaky branch October 9, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Iceberg enhancement New feature or request test Testing related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants