forked from apache/kyuubi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KYUUBI apache#6265]Resource isolation in Spark Scala mode
- Loading branch information
wangjunbo
committed
Apr 18, 2024
1 parent
1591157
commit 7804fa9
Showing
5 changed files
with
157 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...uubi-spark-sql-engine/src/main/scala/org/apache/spark/kyuubi/SparkJobArtifactHelper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.spark.kyuubi | ||
|
||
import org.apache.spark.{JobArtifactSet, JobArtifactState} | ||
|
||
import org.apache.kyuubi.session.SessionHandle | ||
|
||
object SparkJobArtifactHelper { | ||
|
||
def withActiveJobArtifactState(handler: SessionHandle)(f: => Unit): Unit = { | ||
val state = JobArtifactState(handler.identifier.toString, None) | ||
JobArtifactSet.withActiveJobArtifactState(state) { | ||
f | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...s/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/sql/hive/HiveClientHelper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.spark.sql.hive | ||
|
||
import java.net.URL | ||
|
||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.internal.SessionResourceLoader | ||
import org.apache.spark.sql.internal.StaticSQLConf.CATALOG_IMPLEMENTATION | ||
|
||
object HiveClientHelper { | ||
|
||
type HiveClientImpl = org.apache.spark.sql.hive.client.HiveClientImpl | ||
|
||
def getLoadedClasses(spark: SparkSession): Array[URL] = { | ||
if (spark.conf.get(CATALOG_IMPLEMENTATION).equals("hive")) { | ||
val loader = spark.sessionState.resourceLoader | ||
getHiveLoadedClasses(loader) | ||
} else { | ||
spark.sharedState.jarClassLoader.getURLs | ||
} | ||
} | ||
|
||
private def getHiveLoadedClasses(loader: SessionResourceLoader): Array[URL] = { | ||
if (loader != null) { | ||
val field = classOf[HiveSessionResourceLoader].getDeclaredField("client") | ||
field.setAccessible(true) | ||
val client = field.get(loader).asInstanceOf[HiveClientImpl] | ||
if (client != null) { | ||
client.clientLoader.classLoader.getURLs | ||
} else { | ||
Array.empty | ||
} | ||
} else { | ||
Array.empty | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters