haiyangsun-db commented on a change in pull request #32865:
URL: https://github.com/apache/spark/pull/32865#discussion_r649750350
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
##########
@@ -53,28 +54,60 @@ import org.apache.spark.util.Utils
object SQLConf {
- private[sql] val sqlConfEntries =
- new ConcurrentHashMap[String, ConfigEntry[_]]()
+ private[this] val sqlConfEntriesUpdateLock = new Object
- val staticConfKeys: java.util.Set[String] =
- java.util.Collections.synchronizedSet(new java.util.HashSet[String]())
+ @volatile
+ private[this] var sqlConfEntries: util.Map[String, ConfigEntry[_]] =
util.Collections.emptyMap()
- private def register(entry: ConfigEntry[_]): Unit =
sqlConfEntries.merge(entry.key, entry,
- (existingConfigEntry, newConfigEntry) => {
- require(existingConfigEntry == null,
- s"Duplicate SQLConfigEntry. ${newConfigEntry.key} has been registered")
- newConfigEntry
- }
- )
+ private[this] val staticConfKeysUpdateLock = new Object
Review comment:
These are two different sets of configs, so using two separate locks
should be better.
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
##########
@@ -53,28 +54,60 @@ import org.apache.spark.util.Utils
object SQLConf {
- private[sql] val sqlConfEntries =
- new ConcurrentHashMap[String, ConfigEntry[_]]()
+ private[this] val sqlConfEntriesUpdateLock = new Object
- val staticConfKeys: java.util.Set[String] =
- java.util.Collections.synchronizedSet(new java.util.HashSet[String]())
+ @volatile
+ private[this] var sqlConfEntries: util.Map[String, ConfigEntry[_]] =
util.Collections.emptyMap()
- private def register(entry: ConfigEntry[_]): Unit =
sqlConfEntries.merge(entry.key, entry,
- (existingConfigEntry, newConfigEntry) => {
- require(existingConfigEntry == null,
- s"Duplicate SQLConfigEntry. ${newConfigEntry.key} has been registered")
- newConfigEntry
- }
- )
+ private[this] val staticConfKeysUpdateLock = new Object
+
+ @volatile
+ private[this] var staticConfKeys: java.util.Set[String] =
util.Collections.emptySet()
+
+ private def register(entry: ConfigEntry[_]): Unit =
sqlConfEntriesUpdateLock.synchronized {
+ require(!sqlConfEntries.containsKey(entry.key),
+ s"Duplicate SQLConfigEntry. ${entry.key} has been registered")
+ val updatedMap = new java.util.HashMap[String,
ConfigEntry[_]](sqlConfEntries)
+ updatedMap.put(entry.key, entry)
+ sqlConfEntries = updatedMap
+ }
// For testing only
- private[sql] def unregister(entry: ConfigEntry[_]): Unit =
sqlConfEntries.remove(entry.key)
+ private[sql] def unregister(entry: ConfigEntry[_]): Unit =
sqlConfEntriesUpdateLock.synchronized {
+ val updatedMap = new java.util.HashMap[String,
ConfigEntry[_]](sqlConfEntries)
+ updatedMap.remove(entry.key)
+ sqlConfEntries = updatedMap
+ }
+
+ private[internal] def getConfigEntry(key: String): ConfigEntry[_] = {
+ sqlConfEntries.get(key)
+ }
+
+ private[internal] def getConfigEntries(): util.Collection[ConfigEntry[_]] = {
+ sqlConfEntries.values()
+ }
+
+ private[internal] def containsConfigEntry(entry: ConfigEntry[_]): Boolean = {
+ getConfigEntry(entry.key) == entry
+ }
+ private[sql] def containsConfigKey(key: String): Boolean = {
Review comment:
Fixed, thank you!
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
##########
@@ -53,28 +54,60 @@ import org.apache.spark.util.Utils
object SQLConf {
- private[sql] val sqlConfEntries =
- new ConcurrentHashMap[String, ConfigEntry[_]]()
+ private[this] val sqlConfEntriesUpdateLock = new Object
- val staticConfKeys: java.util.Set[String] =
- java.util.Collections.synchronizedSet(new java.util.HashSet[String]())
+ @volatile
+ private[this] var sqlConfEntries: util.Map[String, ConfigEntry[_]] =
util.Collections.emptyMap()
- private def register(entry: ConfigEntry[_]): Unit =
sqlConfEntries.merge(entry.key, entry,
- (existingConfigEntry, newConfigEntry) => {
- require(existingConfigEntry == null,
- s"Duplicate SQLConfigEntry. ${newConfigEntry.key} has been registered")
- newConfigEntry
- }
- )
+ private[this] val staticConfKeysUpdateLock = new Object
+
+ @volatile
+ private[this] var staticConfKeys: java.util.Set[String] =
util.Collections.emptySet()
+
+ private def register(entry: ConfigEntry[_]): Unit =
sqlConfEntriesUpdateLock.synchronized {
+ require(!sqlConfEntries.containsKey(entry.key),
+ s"Duplicate SQLConfigEntry. ${entry.key} has been registered")
+ val updatedMap = new java.util.HashMap[String,
ConfigEntry[_]](sqlConfEntries)
+ updatedMap.put(entry.key, entry)
+ sqlConfEntries = updatedMap
+ }
// For testing only
- private[sql] def unregister(entry: ConfigEntry[_]): Unit =
sqlConfEntries.remove(entry.key)
+ private[sql] def unregister(entry: ConfigEntry[_]): Unit =
sqlConfEntriesUpdateLock.synchronized {
+ val updatedMap = new java.util.HashMap[String,
ConfigEntry[_]](sqlConfEntries)
+ updatedMap.remove(entry.key)
+ sqlConfEntries = updatedMap
+ }
+
+ private[internal] def getConfigEntry(key: String): ConfigEntry[_] = {
+ sqlConfEntries.get(key)
+ }
+
+ private[internal] def getConfigEntries(): util.Collection[ConfigEntry[_]] = {
+ sqlConfEntries.values()
+ }
+
+ private[internal] def containsConfigEntry(entry: ConfigEntry[_]): Boolean = {
+ getConfigEntry(entry.key) == entry
+ }
+ private[sql] def containsConfigKey(key: String): Boolean = {
+ sqlConfEntries.containsKey(key)
+ }
Review comment:
Fixed, thank you!
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
##########
@@ -53,28 +54,60 @@ import org.apache.spark.util.Utils
object SQLConf {
- private[sql] val sqlConfEntries =
- new ConcurrentHashMap[String, ConfigEntry[_]]()
+ private[this] val sqlConfEntriesUpdateLock = new Object
- val staticConfKeys: java.util.Set[String] =
- java.util.Collections.synchronizedSet(new java.util.HashSet[String]())
+ @volatile
+ private[this] var sqlConfEntries: util.Map[String, ConfigEntry[_]] =
util.Collections.emptyMap()
- private def register(entry: ConfigEntry[_]): Unit =
sqlConfEntries.merge(entry.key, entry,
- (existingConfigEntry, newConfigEntry) => {
- require(existingConfigEntry == null,
- s"Duplicate SQLConfigEntry. ${newConfigEntry.key} has been registered")
- newConfigEntry
- }
- )
+ private[this] val staticConfKeysUpdateLock = new Object
Review comment:
Thank you for your review! I think these are two different sets of
configs, so using two separate locks should be better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]