Skip to content

Commit 7aca75b

Browse files
committed
[KYUUBI #2240][SUB-TASK] Skip add metadata manager if frontend does not support rest
### _Why are the changes needed?_ metadata manager is only used for batch session for rest frontend. metadata manager is a heavy class, it will initialize metadata table and some of thread pool. ### _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 #3134 from ulysses-you/metadata. Closes #2240 12f82fc [ulysses-you] seq de72ed7 [ulysses-you] address comment 5d3eded [ulysses-you] fix 7699852 [ulysses-you] try fix d496a5e [ulysses-you] style 23d22f8 [ulysses-you] fix 8fadb9e [ulysses-you] style f61039a [ulysses-you] fix ea690ef [ulysses-you] address comment 15a25ec [ulysses-you] address comment 9ccdd17 [ulysses-you] Skip add metadata manager if frontend does not support rest Authored-by: ulysses-you <ulyssesyou18@gmail.com> Signed-off-by: ulysses-you <ulyssesyou@apache.org>
1 parent 210d356 commit 7aca75b

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,24 @@ class KyuubiSessionManager private (name: String) extends SessionManager(name) {
4545
// this lazy is must be specified since the conf is null when the class initialization
4646
lazy val sessionConfAdvisor: SessionConfAdvisor = PluginLoader.loadSessionConfAdvisor(conf)
4747
val applicationManager = new KyuubiApplicationManager()
48-
private val metadataManager = new MetadataManager()
48+
private lazy val metadataManager: Option[MetadataManager] = {
49+
// Currently, the metadata manager is used by the REST frontend which provides batch job APIs,
50+
// so we initialize it only when Kyuubi starts with the REST frontend.
51+
if (conf.get(FRONTEND_PROTOCOLS).map(FrontendProtocols.withName)
52+
.contains(FrontendProtocols.REST)) {
53+
Option(new MetadataManager())
54+
} else {
55+
None
56+
}
57+
}
4958

5059
private var limiter: Option[SessionLimiter] = None
5160

5261
override def initialize(conf: KyuubiConf): Unit = {
62+
this.conf = conf
5363
addService(applicationManager)
5464
addService(credentialsManager)
55-
addService(metadataManager)
65+
metadataManager.foreach(addService)
5666
initSessionLimiter(conf)
5767
super.initialize(conf)
5868
}
@@ -166,23 +176,23 @@ class KyuubiSessionManager private (name: String) extends SessionManager(name) {
166176
}
167177

168178
def insertMetadata(metadata: Metadata): Unit = {
169-
metadataManager.insertMetadata(metadata)
179+
metadataManager.foreach(_.insertMetadata(metadata))
170180
}
171181

172182
def updateMetadata(metadata: Metadata): Unit = {
173-
metadataManager.updateMetadata(metadata)
183+
metadataManager.foreach(_.updateMetadata(metadata))
174184
}
175185

176186
def getMetadataRequestsRetryRef(identifier: String): Option[MetadataRequestsRetryRef] = {
177-
Option(metadataManager.getMetadataRequestsRetryRef(identifier))
187+
Option(metadataManager.map(_.getMetadataRequestsRetryRef(identifier)).orNull)
178188
}
179189

180190
def deRegisterMetadataRequestsRetryRef(identifier: String): Unit = {
181-
metadataManager.deRegisterRequestsRetryRef(identifier)
191+
metadataManager.foreach(_.deRegisterRequestsRetryRef(identifier))
182192
}
183193

184194
def getBatchFromMetadataStore(batchId: String): Batch = {
185-
metadataManager.getBatch(batchId)
195+
metadataManager.map(_.getBatch(batchId)).orNull
186196
}
187197

188198
def getBatchesFromMetadataStore(
@@ -193,16 +203,18 @@ class KyuubiSessionManager private (name: String) extends SessionManager(name) {
193203
endTime: Long,
194204
from: Int,
195205
size: Int): Seq[Batch] = {
196-
metadataManager.getBatches(batchType, batchUser, batchState, createTime, endTime, from, size)
206+
metadataManager.map(
207+
_.getBatches(batchType, batchUser, batchState, createTime, endTime, from, size))
208+
.getOrElse(Seq.empty)
197209
}
198210

199211
def getBatchMetadata(batchId: String): Metadata = {
200-
metadataManager.getBatchSessionMetadata(batchId)
212+
metadataManager.map(_.getBatchSessionMetadata(batchId)).orNull
201213
}
202214

203215
@VisibleForTesting
204216
def cleanupMetadata(identifier: String): Unit = {
205-
metadataManager.cleanupMetadataById(identifier)
217+
metadataManager.foreach(_.cleanupMetadataById(identifier))
206218
}
207219

208220
override def start(): Unit = synchronized {
@@ -216,7 +228,7 @@ class KyuubiSessionManager private (name: String) extends SessionManager(name) {
216228

217229
def getBatchSessionsToRecover(kyuubiInstance: String): Seq[KyuubiBatchSessionImpl] = {
218230
Seq(OperationState.PENDING, OperationState.RUNNING).flatMap { stateToRecover =>
219-
metadataManager.getBatchesRecoveryMetadata(
231+
metadataManager.map(_.getBatchesRecoveryMetadata(
220232
stateToRecover.toString,
221233
kyuubiInstance,
222234
0,
@@ -236,17 +248,17 @@ class KyuubiSessionManager private (name: String) extends SessionManager(name) {
236248
metadata.requestConf,
237249
batchRequest,
238250
Some(metadata))
239-
}
251+
}).getOrElse(Seq.empty)
240252
}
241253
}
242254

243255
def getPeerInstanceClosedBatchSessions(kyuubiInstance: String): Seq[Metadata] = {
244256
Seq(OperationState.PENDING, OperationState.RUNNING).flatMap { stateToKill =>
245-
metadataManager.getPeerInstanceClosedBatchesMetadata(
257+
metadataManager.map(_.getPeerInstanceClosedBatchesMetadata(
246258
stateToKill.toString,
247259
kyuubiInstance,
248260
0,
249-
Int.MaxValue)
261+
Int.MaxValue)).getOrElse(Seq.empty)
250262
}
251263
}
252264

0 commit comments

Comments
 (0)