Copilot commented on code in PR #3719:
URL: https://github.com/apache/celeborn/pull/3719#discussion_r3760030698


##########
master/src/main/scala/org/apache/celeborn/service/deploy/master/tags/TagsManager.scala:
##########
@@ -19,112 +19,64 @@ package org.apache.celeborn.service.deploy.master.tags
 
 import java.util
 import java.util.{Collections, Set => JSet}
-import java.util.concurrent.ConcurrentHashMap
 import java.util.function.Predicate
 import java.util.stream.Collectors
 
-import scala.collection.JavaConverters.{asScalaIteratorConverter, 
mapAsScalaConcurrentMapConverter}
+import scala.collection.JavaConverters._
 
 import org.apache.celeborn.common.identity.UserIdentifier
 import org.apache.celeborn.common.internal.Logging
 import org.apache.celeborn.common.meta.WorkerInfo
-import org.apache.celeborn.common.util.JavaUtils
 import org.apache.celeborn.server.common.service.config.ConfigService
 
 class TagsManager(configService: Option[ConfigService]) extends Logging {
-  private val defaultTagStore = JavaUtils.newConcurrentHashMap[String, 
JSet[String]]()
 
-  private val addNewTagFunc =
-    new util.function.Function[String, ConcurrentHashMap.KeySetView[String, 
java.lang.Boolean]]() {
-      override def apply(t: String): ConcurrentHashMap.KeySetView[String, 
java.lang.Boolean] =
-        ConcurrentHashMap.newKeySet[String]()
-    }
-
-  private def getTagStore: ConcurrentHashMap[String, JSet[String]] = {
+  private def tagStore: Option[util.Map[String, JSet[String]]] = {
     configService match {
-      case Some(cs) =>
-        // TODO: Make configStore.getTags return ConcurrentMap
-        JavaUtils.newConcurrentHashMap(cs.getSystemConfigFromCache.getTags)
-      case _ =>
-        defaultTagStore
+      case Some(cs) => Option(cs.getSystemConfigFromCache.getTags)
+      case _ => None
     }
   }

Review Comment:
   This changed from creating a defensive `ConcurrentHashMap` copy of `getTags` 
to directly using the map returned by the config cache. The removed code 
comment indicated the underlying map is not guaranteed to be concurrent; if 
that map is mutated during refresh, concurrent reads in 
`getTaggedWorkers/getTagsForWorker/getTagsForCluster` can observe torn state or 
throw (e.g., `ConcurrentModificationException`). Recommend restoring a 
thread-safe snapshot/copy per refresh (or having the config cache expose an 
immutable/concurrent view) before iterating/reading from it.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to