FMX commented on code in PR #2739: URL: https://github.com/apache/celeborn/pull/2739#discussion_r1766295036
########## master/src/main/scala/org/apache/celeborn/service/deploy/master/tags/TagsManager.scala: ########## @@ -0,0 +1,90 @@ +/* + * 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.celeborn.service.deploy.master.tags + +import java.util +import java.util.{Set => JSet} +import java.util.concurrent.ConcurrentHashMap + +import scala.collection.JavaConverters.{asScalaIteratorConverter, mapAsScalaConcurrentMapConverter} + +import org.apache.celeborn.common.internal.Logging +import org.apache.celeborn.common.meta.WorkerInfo +import org.apache.celeborn.service.deploy.master.tags.TagsManager.{Tag, TagsStore, WorkerId} + +object TagsManager { + type Tag = String Review Comment: I think these three types alias are not needed. These types are not complex. This won't help others to understand this code. ########## master/src/main/scala/org/apache/celeborn/service/deploy/master/tags/TagsManager.scala: ########## @@ -0,0 +1,90 @@ +/* + * 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.celeborn.service.deploy.master.tags + +import java.util +import java.util.{Set => JSet} +import java.util.concurrent.ConcurrentHashMap + +import scala.collection.JavaConverters.{asScalaIteratorConverter, mapAsScalaConcurrentMapConverter} + +import org.apache.celeborn.common.internal.Logging +import org.apache.celeborn.common.meta.WorkerInfo +import org.apache.celeborn.service.deploy.master.tags.TagsManager.{Tag, TagsStore, WorkerId} + +object TagsManager { + type Tag = String + type WorkerId = String + + type TagsStore = ConcurrentHashMap[Tag, JSet[WorkerId]] Review Comment: The value type of the "JSet" should be WorkerInfo. ########## master/src/main/scala/org/apache/celeborn/service/deploy/master/tags/TagsManager.scala: ########## @@ -0,0 +1,90 @@ +/* + * 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.celeborn.service.deploy.master.tags + +import java.util +import java.util.{Set => JSet} +import java.util.concurrent.ConcurrentHashMap + +import scala.collection.JavaConverters.{asScalaIteratorConverter, mapAsScalaConcurrentMapConverter} + +import org.apache.celeborn.common.internal.Logging +import org.apache.celeborn.common.meta.WorkerInfo +import org.apache.celeborn.service.deploy.master.tags.TagsManager.{Tag, TagsStore, WorkerId} + +object TagsManager { + type Tag = String + type WorkerId = String + + type TagsStore = ConcurrentHashMap[Tag, JSet[WorkerId]] +} + +class TagsManager extends Logging { + private val tagStore = new TagsStore() + + private val addNewTagFunc = + new util.function.Function[Tag, ConcurrentHashMap.KeySetView[WorkerId, java.lang.Boolean]]() { + override def apply(t: Tag): ConcurrentHashMap.KeySetView[WorkerId, java.lang.Boolean] = + ConcurrentHashMap.newKeySet[WorkerId]() + } + + def getTaggedWorkers(tag: Tag, workers: List[WorkerInfo]): List[WorkerInfo] = { + val workersForTag = tagStore.get(tag) + if (workersForTag == null) { + logWarning(s"Tag $tag not found in cluster") + return List.empty + } + workers.filter(worker => workersForTag.contains(worker.host)) + } + + def addTagToWorker(tag: Tag, worker: WorkerInfo): Unit = { + val workerId = worker.host + val workers = tagStore.computeIfAbsent(tag, addNewTagFunc) + logInfo(s"Adding Tag $tag to worker $workerId") + workers.add(workerId) Review Comment: You have already got the worker, just storing the worker will be better. The worker info had override equals methods, it can be put into a set. -- 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]
