cmccabe commented on code in PR #13280:
URL: https://github.com/apache/kafka/pull/13280#discussion_r1162107641


##########
metadata/src/main/java/org/apache/kafka/image/TopicsImage.java:
##########
@@ -21,41 +21,48 @@
 import org.apache.kafka.image.writer.ImageWriter;
 import org.apache.kafka.image.writer.ImageWriterOptions;
 import org.apache.kafka.metadata.PartitionRegistration;
+import org.apache.kafka.server.immutable.ImmutableMap;
+import org.apache.kafka.server.immutable.ImmutableMapSetFactory;
 import org.apache.kafka.server.util.TranslatedValueMapView;
 
-import java.util.Collections;
 import java.util.Map;
 import java.util.Objects;
 import java.util.stream.Collectors;
 
-
 /**
  * Represents the topics in the metadata image.
  *
  * This class is thread-safe.
  */
 public final class TopicsImage {
-    public static final TopicsImage EMPTY =
-        new TopicsImage(Collections.emptyMap(), Collections.emptyMap());
+    private static final ImmutableMapSetFactory FACTORY = 
ImmutableMapSetFactory.PCOLLECTIONS_FACTORY;
+
+    public static final TopicsImage EMPTY =  new 
TopicsImage(FACTORY.emptyMap(), FACTORY.emptyMap());
 
-    private final Map<Uuid, TopicImage> topicsById;
-    private final Map<String, TopicImage> topicsByName;
+    final ImmutableMap<Uuid, TopicImage> topicsById;

Review Comment:
   I realize that this is immutable and very unlikely to ever be computed on 
the fly, but I would still really like to avoid direct field access. If we 
start doing stuff like this, people will tend to copy the pattern where it can 
cause harm (for example, where the map is mutable, or where we might want to 
compute the value on the fly). And there is no benefit here, so let's avoid 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: jira-unsubscr...@kafka.apache.org

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

Reply via email to