Skip to content

Commit

Permalink
Fix the issue of ExtraPlugins loading multiple times (#12077)
Browse files Browse the repository at this point in the history
Fixes #12076

The PR is about to fix the multiple loading problem which is due to the
duplicated URL paths for single extra plugin.

---------

Signed-off-by: sperlingxx <[email protected]>
  • Loading branch information
sperlingxx authored Feb 8, 2025
1 parent b8b180a commit 0e7096f
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions sql-plugin/src/main/scala/com/nvidia/spark/rapids/Plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import java.util.Properties
import java.util.concurrent.ConcurrentHashMap

import scala.collection.JavaConverters._
import scala.collection.mutable
import scala.sys.process._
import scala.util.Try

Expand Down Expand Up @@ -353,20 +354,29 @@ object RapidsPluginUtils extends Logging {
val resourceName = "spark-rapids-extra-plugins"
val classLoader = RapidsPluginUtils.getClass.getClassLoader
val resourceUrls = classLoader.getResources(resourceName)
val resourceUrlArray = resourceUrls.asScala.toArray
// Somehow, it is possible that the definition of same Plugin occurs multiple times in the
// resourceUrls. Therefore, deduplication work is essential in case of loading some plugins
// repeatedly.
val distinctResources = mutable.HashSet.empty[URL]
while (resourceUrls.hasMoreElements) {
val url = resourceUrls.nextElement()
if (distinctResources.contains(url)) {
logWarning(s"Found duplicated definition of ExtraPlugin: $url! Discarded it.")
} else {
distinctResources.add(url)
}
}

if (resourceUrlArray.isEmpty) {
if (distinctResources.isEmpty) {
logDebug(s"Could not find file $resourceName in the classpath, not loading extra plugins")
Seq.empty
} else {
val plugins = scala.collection.mutable.ListBuffer[SparkPlugin]()
for (resourceUrl <- resourceUrlArray) {
distinctResources.iterator.flatMap { resourceUrl =>
val source = scala.io.Source.fromURL(resourceUrl)
val pluginClasses = source.getLines().toList
source.close()
plugins ++= loadExtensions(classOf[SparkPlugin], pluginClasses)
}
plugins.toSeq
loadExtensions(classOf[SparkPlugin], pluginClasses)
}.toList
}
}

Expand Down

0 comments on commit 0e7096f

Please sign in to comment.