Skip to content

Commit 6c96ff8

Browse files
turboFeiclaude
andcommitted
[KYUUBI #7XXX] Always update engineError to clear pending reasons
### Why are the changes needed? In the previous commit [KYUUBI #7313], when a k8s application is pending, we audit the app diagnostics to record the pending reason. This information is eventually updated to the `engineError` field in the metadata store via the `updateMetadata` method. However, when the application transitions from pending to finished successfully, if there is no error (i.e., `engineError` is `None`), the old pending reason remains in the metadata, causing confusion. ### What are the changes? Modified `JDBCMetadataStore.updateMetadata()` to always update the `engineError` field: - Previously: Only updated when `engineError` was `Some(error)` - Now: Always updates, setting to `null` when `engineError` is `None` This ensures that pending reasons are properly cleared when the application state changes. ### How was this patch tested? - Added unit test `update engineError to null when it becomes None` in `JDBCMetadataStoreSuite` - The test verifies that: 1. Setting engineError to a pending reason works correctly 2. Updating engineError to None clears the value in the database 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2037881 commit 6c96ff8

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

kyuubi-server/src/main/scala/org/apache/kyuubi/server/metadata/jdbc/JDBCMetadataStore.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,9 @@ class JDBCMetadataStore(conf: KyuubiConf) extends MetadataStore with Logging {
376376
setClauses += "engine_state = ?"
377377
params += metadata.engineState
378378
}
379-
metadata.engineError.foreach { error =>
380-
setClauses += "engine_error = ?"
381-
params += error
382-
}
379+
// Always update engineError to clear pending reasons when state changes
380+
setClauses += "engine_error = ?"
381+
params += metadata.engineError.orNull
383382
if (metadata.peerInstanceClosed) {
384383
setClauses += "peer_instance_closed = ?"
385384
params += metadata.peerInstanceClosed

kyuubi-server/src/test/scala/org/apache/kyuubi/server/metadata/jdbc/JDBCMetadataStoreSuite.scala

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,50 @@ class JDBCMetadataStoreSuite extends KyuubiFunSuite {
271271
assert(jdbcMetadataStore.getLatestSchemaUrl(Seq(url1, url2, url3, url4, url5)).get === url5)
272272
}
273273

274+
test("update engineError to null when it becomes None") {
275+
val batchId = UUID.randomUUID().toString
276+
val kyuubiInstance = "localhost:10099"
277+
val batchMetadata = Metadata(
278+
identifier = batchId,
279+
sessionType = SessionType.BATCH,
280+
realUser = "kyuubi",
281+
username = "kyuubi",
282+
ipAddress = "127.0.0.1",
283+
kyuubiInstance = kyuubiInstance,
284+
state = "PENDING",
285+
resource = "intern",
286+
className = "org.apache.kyuubi.SparkWC",
287+
requestName = "kyuubi_batch",
288+
requestConf = Map("spark.master" -> "local"),
289+
requestArgs = Seq("100"),
290+
createTime = System.currentTimeMillis(),
291+
engineType = "spark",
292+
clusterManager = Some("local"))
293+
294+
jdbcMetadataStore.insertMetadata(batchMetadata)
295+
296+
// Simulate k8s app pending with error message
297+
val pendingMetadata = batchMetadata.copy(
298+
state = "PENDING",
299+
engineError = Some("Pod pending: Insufficient CPU"))
300+
jdbcMetadataStore.updateMetadata(pendingMetadata)
301+
302+
var retrievedMetadata = jdbcMetadataStore.getMetadata(batchId)
303+
assert(retrievedMetadata.engineError == Some("Pod pending: Insufficient CPU"))
304+
305+
// When app transitions to success, engineError should be cleared to None/null
306+
val runningMetadata = pendingMetadata.copy(
307+
state = "RUNNING",
308+
engineError = None)
309+
jdbcMetadataStore.updateMetadata(runningMetadata)
310+
311+
retrievedMetadata = jdbcMetadataStore.getMetadata(batchId)
312+
assert(retrievedMetadata.engineError == None)
313+
314+
// Clean up
315+
jdbcMetadataStore.cleanupMetadataByIdentifier(batchId)
316+
}
317+
274318
test("kubernetes engine info") {
275319
val tag = UUID.randomUUID().toString
276320
val metadata = KubernetesEngineInfo(

0 commit comments

Comments
 (0)