dajac commented on code in PR #17285:
URL: https://github.com/apache/kafka/pull/17285#discussion_r1777534739


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/modern/TopicIds.java:
##########
@@ -21,25 +21,169 @@
 import org.apache.kafka.image.TopicsImage;
 
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Objects;
 import java.util.Set;
 
 /**
  * TopicIds is initialized with topic names (String) but exposes a Set of 
topic ids (Uuid) to the
- * user and performs the conversion lazily with TopicsImage.
+ * user and performs the conversion lazily with a TopicResolver backed by a 
TopicsImage.
  */
 public class TopicIds implements Set<Uuid> {
+    /**
+     * Converts between topic ids (Uuids) and topic names (Strings).
+     */
+    public interface TopicResolver {
+        /**
+         * @return The TopicsImage used by the resolver.
+         */
+        TopicsImage image();
+
+        /**
+         * Converts a topic id to a topic name.
+         *
+         * @param id The topic id.
+         * @return The topic name for the given topic id, or null if the topic 
does not exist.
+         */
+        String name(Uuid id);
+
+        /**
+         * Converts a topic name to a topic id.
+         *
+         * @param name The topic name.
+         * @return The topic id for the given topic name, or null if the topic 
does not exist.
+         */
+        Uuid id(String name);
+
+        /**
+         * Clears any cached data.
+         *
+         * Used for benchmarking purposes.
+         */
+        void clear();
+    }
+
+    /**
+     * A base implementation of TopicResolver.
+     *
+     * Provides an implementation of equals and hashCode based on the 
underlying TopicsImage.
+     */
+    public abstract static class BaseTopicResolver implements TopicResolver {

Review Comment:
   nit: Should we keep it private?



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/modern/TopicIds.java:
##########
@@ -164,20 +308,20 @@ public boolean equals(Object o) {
         TopicIds uuids = (TopicIds) o;
 
         if (!Objects.equals(topicNames, uuids.topicNames)) return false;
-        return Objects.equals(image, uuids.image);
+        return Objects.equals(resolver, uuids.resolver);
     }
 
     @Override
     public int hashCode() {
         int result = topicNames.hashCode();
-        result = 31 * result + image.hashCode();
+        result = 31 * result + resolver.hashCode();
         return result;
     }
 
     @Override
     public String toString() {
         return "TopicIds(topicNames=" + topicNames +
-            ", image=" + image +
+            ", resolver=" + resolver +

Review Comment:
   nit: If we toString it here, should we add toString methods to the resolvers 
too?



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to