Copilot commented on code in PR #22511:
URL: https://github.com/apache/kafka/pull/22511#discussion_r3375606629


##########
server/src/main/java/org/apache/kafka/server/streams/InMemoryTopologyDescriptionPlugin.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.kafka.server.streams;
+
+import 
org.apache.kafka.coordinator.group.api.streams.StreamsGroupTopologyDescription;
+import 
org.apache.kafka.coordinator.group.api.streams.StreamsGroupTopologyDescriptionPlugin;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Reference {@link StreamsGroupTopologyDescriptionPlugin} that stores 
topology descriptions
+ * in an in-memory map. Intended for testing and as a starting point for real 
implementations;
+ * not suitable for production because its state is lost on broker restart and 
is not shared
+ * across brokers.
+ *
+ * <p>Stores at most one description per group, identified by its topology 
epoch. A
+ * {@code setTopology} call overwrites any previously stored description for 
that group;
+ * {@code getTopology} returns the stored description only when the requested 
topology epoch
+ * matches the stored epoch, and {@code null} otherwise.
+ */
+public class InMemoryTopologyDescriptionPlugin implements 
StreamsGroupTopologyDescriptionPlugin {
+
+    private record Entry(int topologyEpoch, StreamsGroupTopologyDescription 
description) { }
+
+    private final ConcurrentHashMap<String, Entry> store = new 
ConcurrentHashMap<>();
+
+    @Override
+    public void configure(Map<String, ?> configs) {
+        // No-op.
+    }
+
+    @Override
+    public CompletableFuture<Void> setTopology(String groupId, int 
topologyEpoch, StreamsGroupTopologyDescription description) {
+        store.put(groupId, new Entry(topologyEpoch, description));
+        return CompletableFuture.completedFuture(null);
+    }

Review Comment:
   `StreamsGroupTopologyDescriptionPlugin` javadoc explicitly says 
implementations must not throw synchronously; `ConcurrentHashMap` operations 
(e.g. null `groupId` / `description`) will currently throw and violate that 
contract. Wrap the body and return a failed future instead so failures are 
always signaled via future completion.



##########
server/src/main/java/org/apache/kafka/server/streams/InMemoryTopologyDescriptionPlugin.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.kafka.server.streams;
+
+import 
org.apache.kafka.coordinator.group.api.streams.StreamsGroupTopologyDescription;
+import 
org.apache.kafka.coordinator.group.api.streams.StreamsGroupTopologyDescriptionPlugin;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Reference {@link StreamsGroupTopologyDescriptionPlugin} that stores 
topology descriptions
+ * in an in-memory map. Intended for testing and as a starting point for real 
implementations;
+ * not suitable for production because its state is lost on broker restart and 
is not shared
+ * across brokers.
+ *
+ * <p>Stores at most one description per group, identified by its topology 
epoch. A
+ * {@code setTopology} call overwrites any previously stored description for 
that group;
+ * {@code getTopology} returns the stored description only when the requested 
topology epoch
+ * matches the stored epoch, and {@code null} otherwise.
+ */
+public class InMemoryTopologyDescriptionPlugin implements 
StreamsGroupTopologyDescriptionPlugin {
+
+    private record Entry(int topologyEpoch, StreamsGroupTopologyDescription 
description) { }
+
+    private final ConcurrentHashMap<String, Entry> store = new 
ConcurrentHashMap<>();
+
+    @Override
+    public void configure(Map<String, ?> configs) {
+        // No-op.
+    }
+
+    @Override
+    public CompletableFuture<Void> setTopology(String groupId, int 
topologyEpoch, StreamsGroupTopologyDescription description) {
+        store.put(groupId, new Entry(topologyEpoch, description));
+        return CompletableFuture.completedFuture(null);
+    }
+
+    @Override
+    public CompletableFuture<Void> deleteTopology(String groupId) {
+        store.remove(groupId);
+        return CompletableFuture.completedFuture(null);
+    }
+
+    @Override
+    public CompletableFuture<StreamsGroupTopologyDescription> 
getTopology(String groupId, int topologyEpoch) {
+        Entry entry = store.get(groupId);
+        if (entry == null || entry.topologyEpoch() != topologyEpoch) {
+            return CompletableFuture.completedFuture(null);
+        }
+        return CompletableFuture.completedFuture(entry.description());
+    }

Review Comment:
   `StreamsGroupTopologyDescriptionPlugin` contract says implementations must 
not throw synchronously; `store.get(groupId)` will throw synchronously for a 
null key. Wrap in try/catch and complete the returned future exceptionally 
instead.



##########
group-coordinator/group-coordinator-api/src/main/java/org/apache/kafka/coordinator/group/api/streams/StreamsGroupTopologyDescription.java:
##########
@@ -0,0 +1,286 @@
+/*
+ * 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.kafka.coordinator.group.api.streams;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * Broker-side description of a Kafka Streams topology, as pushed by clients 
via
+ * {@code StreamsGroupTopologyDescriptionUpdate} and consumed by
+ * {@link StreamsGroupTopologyDescriptionPlugin} implementations.
+ *
+ * <p>This type mirrors {@code org.apache.kafka.streams.TopologyDescription} 
in shape
+ * but lives in {@code group-coordinator-api} so plugin implementations do not 
need
+ * to depend on {@code kafka-streams}. The wire schema only carries the 
successor
+ * relation; plugins that need both directions reconstruct predecessors in a 
single
+ * pass over the nodes.
+ */
+public class StreamsGroupTopologyDescription {
+
+    /**
+     * A processing node in the topology. Predecessor nodes can be inferred 
from
+     * the {@link #successors()} relation.
+     */
+    public sealed interface Node {
+        String name();
+        Set<String> successors();
+    }
+
+    public static final class Source implements Node {
+        private final String name;
+        private final Set<String> topics;
+        private final Set<String> successors;
+
+        public Source(String name, Set<String> topics, Set<String> successors) 
{
+            this.name = Objects.requireNonNull(name, "name");
+            this.topics = Set.copyOf(Objects.requireNonNull(topics, "topics"));
+            this.successors = Set.copyOf(Objects.requireNonNull(successors, 
"successors"));
+        }
+
+        @Override
+        public String name() {
+            return name;
+        }
+
+        public Set<String> topics() {
+            return topics;
+        }
+
+        @Override
+        public Set<String> successors() {
+            return successors;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (!(o instanceof Source other)) return false;
+            return name.equals(other.name)
+                && topics.equals(other.topics)
+                && successors.equals(other.successors);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(name, topics, successors);
+        }
+
+        @Override
+        public String toString() {
+            return "Source(name=" + name + ", topics=" + topics + ", 
successors=" + successors + ")";
+        }
+    }
+
+    public static final class Processor implements Node {
+        private final String name;
+        private final Set<String> stores;
+        private final Set<String> successors;
+
+        public Processor(String name, Set<String> stores, Set<String> 
successors) {
+            this.name = Objects.requireNonNull(name, "name");
+            this.stores = Set.copyOf(Objects.requireNonNull(stores, "stores"));
+            this.successors = Set.copyOf(Objects.requireNonNull(successors, 
"successors"));
+        }
+
+        @Override
+        public String name() {
+            return name;
+        }
+
+        public Set<String> stores() {
+            return stores;
+        }
+
+        @Override
+        public Set<String> successors() {
+            return successors;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (!(o instanceof Processor other)) return false;
+            return name.equals(other.name)
+                && stores.equals(other.stores)
+                && successors.equals(other.successors);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(name, stores, successors);
+        }
+
+        @Override
+        public String toString() {
+            return "Processor(name=" + name + ", stores=" + stores + ", 
successors=" + successors + ")";
+        }
+    }
+
+    public static final class Sink implements Node {
+        private final String name;
+        private final Optional<String> topic;
+        private final Set<String> successors;
+
+        public Sink(String name, Optional<String> topic, Set<String> 
successors) {
+            this.name = Objects.requireNonNull(name, "name");
+            this.topic = Objects.requireNonNull(topic, "topic");
+            this.successors = Set.copyOf(Objects.requireNonNull(successors, 
"successors"));
+        }
+
+        @Override
+        public String name() {
+            return name;
+        }
+
+        public Optional<String> topic() {
+            return topic;
+        }
+
+        @Override
+        public Set<String> successors() {
+            return successors;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (!(o instanceof Sink other)) return false;
+            return name.equals(other.name)
+                && topic.equals(other.topic)
+                && successors.equals(other.successors);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(name, topic, successors);
+        }
+
+        @Override
+        public String toString() {
+            return "Sink(name=" + name + ", topic=" + topic + ", successors=" 
+ successors + ")";
+        }
+    }
+
+    public static final class Subtopology {
+        private final String id;
+        private final Collection<Node> nodes;
+
+        public Subtopology(String id, Collection<Node> nodes) {

Review Comment:
   `Subtopology` accepts/returns a `Collection<Node>` but immediately copies it 
with `List.copyOf(...)`, and `equals`/`hashCode` become order-sensitive as a 
result. If ordering is semantically meaningful, consider using `List<Node>` in 
the API; if not, consider storing as a `Set` (or otherwise making equality 
order-insensitive) to avoid surprising inequality when callers provide the same 
elements with a different iteration order.



##########
server/src/main/java/org/apache/kafka/server/streams/InMemoryTopologyDescriptionPlugin.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.kafka.server.streams;
+
+import 
org.apache.kafka.coordinator.group.api.streams.StreamsGroupTopologyDescription;
+import 
org.apache.kafka.coordinator.group.api.streams.StreamsGroupTopologyDescriptionPlugin;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Reference {@link StreamsGroupTopologyDescriptionPlugin} that stores 
topology descriptions
+ * in an in-memory map. Intended for testing and as a starting point for real 
implementations;
+ * not suitable for production because its state is lost on broker restart and 
is not shared
+ * across brokers.
+ *
+ * <p>Stores at most one description per group, identified by its topology 
epoch. A
+ * {@code setTopology} call overwrites any previously stored description for 
that group;
+ * {@code getTopology} returns the stored description only when the requested 
topology epoch
+ * matches the stored epoch, and {@code null} otherwise.
+ */
+public class InMemoryTopologyDescriptionPlugin implements 
StreamsGroupTopologyDescriptionPlugin {
+
+    private record Entry(int topologyEpoch, StreamsGroupTopologyDescription 
description) { }
+
+    private final ConcurrentHashMap<String, Entry> store = new 
ConcurrentHashMap<>();
+
+    @Override
+    public void configure(Map<String, ?> configs) {
+        // No-op.
+    }
+
+    @Override
+    public CompletableFuture<Void> setTopology(String groupId, int 
topologyEpoch, StreamsGroupTopologyDescription description) {
+        store.put(groupId, new Entry(topologyEpoch, description));
+        return CompletableFuture.completedFuture(null);
+    }
+
+    @Override
+    public CompletableFuture<Void> deleteTopology(String groupId) {
+        store.remove(groupId);
+        return CompletableFuture.completedFuture(null);
+    }

Review Comment:
   `StreamsGroupTopologyDescriptionPlugin` requires asynchronous failure 
signalling; `store.remove(groupId)` will throw synchronously for null 
`groupId`. Return a failed future instead of throwing.



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