apache / kyuubi

Apache Kyuubi is a distributed and multi-tenant gateway to provide serverless SQL on data warehouses and lakehouses.
https://kyuubi.apache.org/
Apache License 2.0
2.11k stars 915 forks source link

Fix AppState when Engine connection is terminated #6722

Open joaopamaral opened 1 month ago

joaopamaral commented 1 month ago

:mag: Description

Issue References πŸ”—

This issue was noticed a few times when the batch state was set to ERROR, but the appState kept the non-terminal state forever (e.g. RUNNING), even if the application was finished (in this case Yarn Application).

{
"id": "********",
"user": "****",
"batchType": "SPARK",
"name": "*********",
"appStartTime": 0,
"appId": "********",
"appUrl": "********",
"appState": "RUNNING",
"appDiagnostic": "",
"kyuubiInstance": "*********",
"state": "ERROR",
"createTime": 1725343207318,
"endTime": 1725343300986,
"batchInfo": {}
}

It seems that this happens when there is some intermittent failure during the monitoring step and the batch ends with ERROR, leaving the application metadata without an update. This can lead to some misinterpretation that the application is still running. We need to set this to UNKNOWN state to avoid errors.

Describe Your Solution πŸ”§

This is a simple fix that only checks if the batch state is ERROR and the appState is not in a terminal state and changes the appState to UNKNOWN, in these cases (during the batch metadata update).

Types of changes :bookmark:

Test Plan πŸ§ͺ

Behavior Without This Pull Request :coffin:

If there is some error between the Kyuubi and the Application request (e.g. YARN client), the batch is finished with ERROR state and the application keeps the last know state (e.g. RUNNING).

Behavior With This Pull Request :tada:

If there is some error between the Kyuubi and the Application request (e.g. YARN client), the batch is finished with ERRORstate and the application has a non-terminal state, it is forced to UNKNOWN state.

Related Unit Tests

I've tried to implement a unit test to replicate this behavior but I didn't make it. We need to force an exception in the Engine Request (e.g. YarnClient.getApplication) but we need to wait for the application to be in the RUNNING state before raising this exception, or maybe block the connection between kyuubi and the engine.


Checklist πŸ“

Be nice. Be informative.

pan3793 commented 1 month ago

@joaopamaral please fix the code style. (simply run dev/reformat if you are using Linux or macOS)