Skip to content

Commit 93f13ef

Browse files
wForgetulysses-you
authored andcommitted
[KYUUBI #2419] Release engine during closing kyuubi server session if share level is connection
### _Why are the changes needed?_ close #2419 We need to clean up the ProcBuilder process and engine application when the session is closed. ### _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 - [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #2482 from wForget/KYUUBI-2419. Closes #2419 2690b5d [wforget] comment ae8be05 [wforget] revert BatchJobSubmission 4fe3c2f [wforget] [KYUUBI-2419] Destroy the ProcBuilder process and call killApplication during closing session Authored-by: wforget <643348094@qq.com> Signed-off-by: ulysses-you <ulyssesyou@apache.org>
1 parent af162b1 commit 93f13ef

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/EngineRef.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ private[kyuubi] class EngineRef(
7171

7272
private val clientPoolName: String = conf.get(ENGINE_POOL_NAME)
7373

74+
private var builder: ProcBuilder = _
75+
7476
@VisibleForTesting
7577
private[kyuubi] val subdomain: String = conf.get(ENGINE_SHARE_LEVEL_SUBDOMAIN) match {
7678
case Some(_subdomain) => _subdomain
@@ -162,7 +164,7 @@ private[kyuubi] class EngineRef(
162164
conf.set(HA_ZK_ENGINE_REF_ID, engineRefId)
163165
val started = System.currentTimeMillis()
164166
conf.set(KYUUBI_ENGINE_SUBMIT_TIME_KEY, String.valueOf(started))
165-
val builder = engineType match {
167+
builder = engineType match {
166168
case SPARK_SQL =>
167169
conf.setIfMissing(SparkProcessBuilder.APP_KEY, defaultEngineName)
168170
new SparkProcessBuilder(appUser, conf, extraEngineLog)
@@ -230,4 +232,17 @@ private[kyuubi] class EngineRef(
230232
create(discoveryClient, extraEngineLog)
231233
}
232234
}
235+
236+
def close(): Unit = {
237+
if (shareLevel == CONNECTION && builder != null) {
238+
try {
239+
val clusterManager = builder.clusterManager()
240+
builder.close(true)
241+
engineManager.killApplication(clusterManager, engineRefId)
242+
} catch {
243+
case e: Exception =>
244+
warn(s"Error closing engine builder, engineRefId: $engineRefId", e)
245+
}
246+
}
247+
}
233248
}

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/ProcBuilder.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ trait ProcBuilder {
237237
process
238238
}
239239

240-
def close(): Unit = synchronized {
240+
def close(destroyProcess: Boolean = !waitCompletion): Unit = synchronized {
241241
if (logCaptureThread != null) {
242242
logCaptureThread.interrupt()
243243
logCaptureThread = null
244244
}
245-
if (!waitCompletion && process != null) {
245+
if (destroyProcess && process != null) {
246246
info("Destroy the process, since waitCompletion is false.")
247247
process.destroyForcibly()
248248
process = null

kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class KyuubiSessionImpl(
160160
try {
161161
if (_client != null) _client.closeSession()
162162
} finally {
163+
if (engine != null) engine.close()
163164
sessionEvent.endTime = System.currentTimeMillis()
164165
EventBus.post(sessionEvent)
165166
MetricsSystem.tracing(_.decCount(MetricRegistry.name(CONN_OPEN, user)))

0 commit comments

Comments
 (0)