[KYUUBI #3950][FOLLOWUP] Check whether the state is INITIALIZED instead of builder process launched

### _Why are the changes needed?_

Check the whether the state is INITIALIZED instead of builder process launched

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #3964 from turboFei/batch_op_close.

Closes #3950

d841086b [fwang12] comments
e51f4920 [fwang12] comment
d64c88de [fwang12] check INITIALIZED
81aae3ce [fwang12] check background handle
30dda80c [fwang12] check state

Authored-by: fwang12 <fwang12@ebay.com>
Signed-off-by: ulysses-you <ulyssesyou@apache.org>
This commit is contained in:
fwang12 2022-12-13 17:59:05 +08:00 committed by ulysses-you
parent 36a2d33250
commit eb98f1e233
No known key found for this signature in database
GPG Key ID: 4C500BC62D576766

View File

@ -298,16 +298,6 @@ class BatchJobSubmission(
MetricsSystem.tracing(_.decCount(MetricRegistry.name(OPERATION_OPEN, opType)))
if (!builder.processLaunched) {
builder.close()
if (recoveryMetadata.isDefined) {
killMessage = killBatchApplication()
}
setState(OperationState.CANCELED)
updateBatchMetadata()
return
}
// fast fail
if (isTerminalState(state)) {
killMessage = (false, s"batch $batchId is already terminal so can not kill it.")
@ -319,16 +309,23 @@ class BatchJobSubmission(
killMessage = killBatchApplication()
builder.close()
} finally {
if (killMessage._1 && !isTerminalState(state)) {
// kill success and we can change state safely
// note that, the batch operation state should never be closed
if (state == OperationState.INITIALIZED) {
// if state is INITIALIZED, it means that the batch submission has not started to run, set
// the state to CANCELED manually and regardless of kill result
setState(OperationState.CANCELED)
updateBatchMetadata()
} else if (killMessage._1) {
// we can not change state safely
killMessage = (false, s"batch $batchId is already terminal so can not kill it.")
} else if (!isTerminalState(state)) {
// failed to kill, the kill message is enough
} else {
if (killMessage._1 && !isTerminalState(state)) {
// kill success and we can change state safely
// note that, the batch operation state should never be closed
setState(OperationState.CANCELED)
updateBatchMetadata()
} else if (killMessage._1) {
// we can not change state safely
killMessage = (false, s"batch $batchId is already terminal so can not kill it.")
} else if (!isTerminalState(state)) {
// failed to kill, the kill message is enough
}
}
}
}