spark-test commented on code in PR #59964:
URL: https://github.com/apache/spark/pull/59964#discussion_r4521303303
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/ui/SQLAppStatusListenerSuite.scala:
##########
@@ -981,6 +981,33 @@ abstract class SQLAppStatusListenerSuite extends
SharedSparkSession with JsonTes
assertJobs(statusStore.execution(executionId), running = Seq(0))
}
+
+ test("SPARK-60756: onJobStart should not force a kvstore write during
history replay") {
+ val store = new ElementTrackingStore(new InMemoryStore, sparkContext.conf)
+ val replayListener = new SQLAppStatusListener(sparkContext.conf, store,
live = false)
+ val executionId = 1L
+ val df = createTestDataFrame
+ replayListener.onOtherEvent(SparkListenerSQLExecutionStart(
+ executionId,
+ Some(executionId),
+ "test",
+ "test",
+ df.queryExecution.toString,
+ SparkPlanInfo.fromSparkPlan(df.queryExecution.executedPlan),
+ System.currentTimeMillis(),
+ Map.empty))
+
+ replayListener.onJobStart(SparkListenerJobStart(
+ jobId = 0,
+ time = System.currentTimeMillis(),
+ stageInfos = Nil,
+ createProperties(executionId)))
+
+ intercept[NoSuchElementException] {
Review Comment:
**Nit (P3):** This intercept is the test's only check, and it covers only
half of the new replay behavior: that a replayed job start no longer writes the
execution record. With `force = live`, the listener's `kvstore.onFlush` hook is
now the only writer of an execution that has started jobs and is still running
when an event log ends (an in-progress, truncated, or crashed application); on
the base branch, the forced job-start write also stored a snapshot of it.
`store.close()` below is `close(closeParent = true)`: it runs the flush and
then clears the `InMemoryStore`, so the flushed record is discarded unread.
Reading the code, if replay-mode `onJobStart` stopped recording the job, or
`onFlush` stopped writing tracked executions, this test would still pass, and
so would every other test: this is the only test that builds a `live = false`
listener, and the only SQL History Server replay test,
`StreamingQueryHistorySuite`, checks only streaming data. The History Server
SQL tab would
then show such executions without their jobs, or not at all. Current behavior
is correct; the gap is only in what this test would catch.
The scenario is already set up, so the test can close the tracking store the
way `FsHistoryProvider.rebuildAppStore` does after replay and then check the
flushed record:
```scala
val inMemoryStore = new InMemoryStore
val store = new ElementTrackingStore(inMemoryStore, sparkContext.conf)
// ... execution start and job start as before ...
intercept[NoSuchElementException] {
store.read(classOf[SQLExecutionUIData], executionId)
}
// Run the onFlush hook as the History Server does after replay, keeping the
store readable.
store.close(false)
val flushed = store.read(classOf[SQLExecutionUIData], executionId)
assertJobs(Some(flushed), running = Seq(0))
assert(flushed.completionTime.isEmpty)
inMemoryStore.close()
```
`inMemoryStore` has to be closed directly, because once the tracking store
is stopped, a second `store.close()` returns without closing it.
**Verification:**
- **Behavior:** With the change applied, the replay-mode test passes: no
execution record exists right after the replayed job start, and after the
tracking store is closed without closing the underlying store, the record
exists with the started job marked as running and no completion time.
- **Regression:** The test fails when replay-mode job-start handling skips
recording the job, when the end-of-replay flush skips writing executions that
are still tracked, and when a replayed job start writes the record immediately
as it does on the base branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]