-
Notifications
You must be signed in to change notification settings - Fork 972
[KYUUBI #5797] Support to describe engine and restart engine with command in current session #5871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0d05e3d
326cdda
651bf5f
f81110d
ade1bae
5711866
4207828
2808013
cd8bf66
8b04bb7
34b429e
9c40671
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,11 @@ | |
| package org.apache.kyuubi.session | ||
|
|
||
| import java.util.Base64 | ||
| import java.util.concurrent.locks.ReentrantReadWriteLock | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import org.apache.kyuubi.KyuubiSQLException | ||
| import org.apache.kyuubi.{KyuubiSQLException, Utils} | ||
| import org.apache.kyuubi.client.KyuubiSyncThriftClient | ||
| import org.apache.kyuubi.config.KyuubiConf | ||
| import org.apache.kyuubi.config.KyuubiConf._ | ||
|
|
@@ -80,7 +81,7 @@ class KyuubiSessionImpl( | |
| handle.identifier.toString, | ||
| sessionManager.applicationManager, | ||
| sessionManager.engineStartupProcessSemaphore) | ||
| private[kyuubi] val launchEngineOp = sessionManager.operationManager | ||
| @volatile private[kyuubi] var launchEngineOp = sessionManager.operationManager | ||
| .newLaunchEngineOperation(this, sessionConf.get(SESSION_ENGINE_LAUNCH_ASYNC)) | ||
|
|
||
| private lazy val sessionUserSignBase64: String = | ||
|
|
@@ -101,7 +102,18 @@ class KyuubiSessionImpl( | |
| } | ||
|
|
||
| @volatile private var _client: KyuubiSyncThriftClient = _ | ||
| def client: KyuubiSyncThriftClient = _client | ||
|
|
||
| private val lock = new ReentrantReadWriteLock() | ||
|
|
||
| private def withReadLockAcquired[T](block: => T): T = Utils.withLockRequired(lock.readLock()) { | ||
| block | ||
| } | ||
|
|
||
| private def withWriteLockAcquired[T](block: => T): T = Utils.withLockRequired(lock.writeLock()) { | ||
| block | ||
| } | ||
|
|
||
| def client: KyuubiSyncThriftClient = withReadLockAcquired { _client } | ||
|
|
||
| @volatile private var _engineSessionHandle: SessionHandle = _ | ||
|
|
||
|
|
@@ -119,6 +131,17 @@ class KyuubiSessionImpl( | |
| engineLastAlive = System.currentTimeMillis() | ||
| } | ||
|
|
||
| def reLaunchEngine(): Unit = handleSessionException { | ||
| engineLaunched = false | ||
| withDiscoveryClient(sessionConf) { discoveryClient => | ||
| engine.deregister(discoveryClient, (_client.getHost, _client.getPort)) | ||
| } | ||
| launchEngineOp = sessionManager.operationManager | ||
| .newLaunchEngineOperation(this, sessionConf.get(SESSION_ENGINE_LAUNCH_ASYNC)) | ||
| runOperation(launchEngineOp) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will re-execute
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shall need to wrap this method with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in case that other operations access the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may not be able to use the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This seems difficult to avoid
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or we need to add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
submit |
||
| engineLastAlive = System.currentTimeMillis() | ||
| } | ||
|
|
||
| private[kyuubi] def openEngineSession(extraEngineLog: Option[OperationLog] = None): Unit = | ||
| handleSessionException { | ||
| withDiscoveryClient(sessionConf) { discoveryClient => | ||
|
|
@@ -158,17 +181,22 @@ class KyuubiSessionImpl( | |
| } | ||
|
|
||
| try { | ||
| val passwd = | ||
| val passwd = { | ||
| if (sessionManager.getConf.get(ENGINE_SECURITY_ENABLED)) { | ||
| InternalSecurityAccessor.get().issueToken() | ||
| } else { | ||
| Option(password).filter(_.nonEmpty).getOrElse("anonymous") | ||
| } | ||
| _client = KyuubiSyncThriftClient.createClient(user, passwd, host, port, sessionConf) | ||
| _engineSessionHandle = | ||
| _client.openSession(protocol, user, passwd, openEngineSessionConf) | ||
| logSessionInfo(s"Connected to engine [$host:$port]/[${client.engineId.getOrElse("")}]" + | ||
| s" with ${_engineSessionHandle}]") | ||
| } | ||
| withWriteLockAcquired{ | ||
| if (_client != null) _client.closeSession() | ||
| _client = KyuubiSyncThriftClient.createClient(user, passwd, host, port, sessionConf) | ||
| _engineSessionHandle = | ||
| _client.openSession(protocol, user, passwd, openEngineSessionConf) | ||
| logSessionInfo( | ||
| s"Connected to engine [$host:$port]/[${client.engineId.getOrElse("")}]" + | ||
| s" with ${_engineSessionHandle}]") | ||
| } | ||
| shouldRetry = false | ||
| } catch { | ||
| case e: TTransportException | ||
|
|
@@ -199,7 +227,7 @@ class KyuubiSessionImpl( | |
| attempt += 1 | ||
| if (shouldRetry && _client != null) { | ||
| try { | ||
| _client.closeSession() | ||
| withWriteLockAcquired{ _client.closeSession() } | ||
| } catch { | ||
| case e: Throwable => | ||
| warn( | ||
|
|
@@ -269,7 +297,9 @@ class KyuubiSessionImpl( | |
| super.close() | ||
| sessionManager.credentialsManager.removeSessionCredentialsEpoch(handle.identifier.toString) | ||
| try { | ||
| if (_client != null) _client.closeSession() | ||
| if (_client != null) { | ||
| withWriteLockAcquired { _client.closeSession() } | ||
| } | ||
| } finally { | ||
| openSessionError.foreach { _ => if (engine != null) engine.close() } | ||
| sessionEvent.endTime = System.currentTimeMillis() | ||
|
|
@@ -314,6 +344,7 @@ class KyuubiSessionImpl( | |
|
|
||
| def checkEngineConnectionAlive(): Boolean = { | ||
| try { | ||
| if (!engineLaunched) return true | ||
| if (Option(client).exists(_.engineConnectionClosed)) return false | ||
| if (!aliveProbeEnabled) return true | ||
| getInfo(TGetInfoType.CLI_DBMS_VER) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.kyuubi.sql.plan.command | ||
|
|
||
| import scala.collection.mutable.ListBuffer | ||
|
|
||
| import org.apache.kyuubi.operation.IterableFetchIterator | ||
| import org.apache.kyuubi.session.{KyuubiSession, KyuubiSessionImpl} | ||
| import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TTypeId | ||
| import org.apache.kyuubi.sql.schema.{Column, Row, Schema} | ||
|
|
||
| /** | ||
| * A runnable node for description the current session. | ||
| * | ||
| * The syntax of using this command in SQL is: | ||
| * {{{ | ||
| * [DESC|DESCRIBE] ENGINE; | ||
| * }}} | ||
| */ | ||
| case class DescribeEngine() extends RunnableCommand { | ||
|
|
||
| override def run(kyuubiSession: KyuubiSession): Unit = { | ||
| val rows = Seq(kyuubiSession).map { session => | ||
| val client = session.asInstanceOf[KyuubiSessionImpl].client | ||
| val values = new ListBuffer[String]() | ||
| values += client.engineId.getOrElse("") | ||
| values += client.engineName.getOrElse("") | ||
| values += client.engineUrl.getOrElse("") | ||
| Row(values.toList) | ||
| } | ||
| iter = new IterableFetchIterator(rows) | ||
| } | ||
|
|
||
| override def resultSchema: Schema = { | ||
| Schema(DescribeEngine.outputCols().toList) | ||
| } | ||
|
|
||
| override def name(): String = "Describe Engine Node" | ||
| } | ||
|
|
||
| object DescribeEngine { | ||
|
|
||
| def outputCols(): Seq[Column] = { | ||
| Seq( | ||
| Column("ENGINE_ID", TTypeId.STRING_TYPE, Some("Kyuubi engine identify")), | ||
| Column("ENGINE_NAME", TTypeId.STRING_TYPE, Some("Kyuubi engine name")), | ||
| Column("ENGINE_URL", TTypeId.STRING_TYPE, Some("Kyuubi engine url"))) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.kyuubi.sql.plan.command | ||
|
|
||
| import scala.collection.mutable.ListBuffer | ||
|
|
||
| import org.apache.kyuubi.operation.IterableFetchIterator | ||
| import org.apache.kyuubi.session.{KyuubiSession, KyuubiSessionImpl} | ||
| import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TTypeId | ||
| import org.apache.kyuubi.sql.schema.{Column, Row, Schema} | ||
|
|
||
| /** | ||
| * A runnable node for description the current session. | ||
| * | ||
| * The syntax of using this command in SQL is: | ||
| * {{{ | ||
| * RESTART ENGINE; | ||
| * }}} | ||
| */ | ||
| case class RestartEngine() extends RunnableCommand { | ||
|
|
||
| override def run(kyuubiSession: KyuubiSession): Unit = { | ||
| val rows = Seq(kyuubiSession.asInstanceOf[KyuubiSessionImpl]).map { session => | ||
| session.reLaunchEngine() | ||
| val client = session.client | ||
| val values = new ListBuffer[String]() | ||
| values += client.engineId.getOrElse("") | ||
| values += client.engineName.getOrElse("") | ||
| values += client.engineUrl.getOrElse("") | ||
| Row(values.toList) | ||
| } | ||
| iter = new IterableFetchIterator(rows) | ||
| } | ||
|
|
||
| override def resultSchema: Schema = { | ||
| Schema(RestartEngine.outputCols().toList) | ||
| } | ||
|
|
||
| override def name(): String = "Restart Session Engine Node" | ||
| } | ||
|
|
||
| object RestartEngine { | ||
| def outputCols(): Seq[Column] = { | ||
| Seq( | ||
| Column("ENGINE_ID", TTypeId.STRING_TYPE, Some("Kyuubi engine identify")), | ||
| Column("ENGINE_NAME", TTypeId.STRING_TYPE, Some("Kyuubi engine name")), | ||
| Column("ENGINE_URL", TTypeId.STRING_TYPE, Some("Kyuubi engine url"))) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.kyuubi.operation.parser | ||
|
|
||
| class DescribeEngineSuite extends ExecutedCommandExecSuite { | ||
|
|
||
| test("desc/describe kyuubi engine") { | ||
| Seq("DESC", "DESCRIBE").foreach { desc => | ||
| withJdbcStatement() { statement => | ||
| val resultSet = statement.executeQuery(s"KYUUBI $desc ENGINE") | ||
| assert(resultSet.next()) | ||
|
|
||
| assert(resultSet.getMetaData.getColumnCount == 3) | ||
| assert(resultSet.getMetaData.getColumnName(1) == "ENGINE_ID") | ||
| assert(resultSet.getMetaData.getColumnName(2) == "ENGINE_NAME") | ||
| assert(resultSet.getMetaData.getColumnName(3) == "ENGINE_URL") | ||
| } | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.