junrao commented on code in PR #17519:
URL: https://github.com/apache/kafka/pull/17519#discussion_r1809211995


##########
clients/src/main/java/org/apache/kafka/common/network/ServerConnectionId.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.common.network;
+
+import java.net.Socket;
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * ServerConnectionId is used to uniquely identify a connection on server for 
the client. The
+ *  connection id is in the format of 
"localHost:localPort-remoteHost:remotePort-processorId-index".
+ *  The processorId is the id of the processor that will handle this 
connection and the index is
+ *  used to ensure uniqueness.
+ */
+public class ServerConnectionId {
+
+    private static final Pattern URI_PARSE_EXP = 
Pattern.compile("\\[?([0-9a-zA-Z\\-%._:]*)]?:([0-9]+)");

Review Comment:
   A couple of things.
   1. `Utils.HOST_PORT_PATTERN` is more general than this. We could just reuse 
the former instead.
   2. It seems that we have an existing bug. `InetAddress.getHostAddress()` 
doesn't contain brackets. When we generate a parsable string for host:port, we 
need to add brackets for the host part since it can contain colon. For example, 
we need to do that for bootstrap.servers. However, in Processor, when 
generating a connection string, we just concatenate the host and the port 
without adding the brackets. This means that when we try to convert the 
connection string back to ConnectionId, we can't parse the hostname properly if 
it's IPV6. To fix this, it seems that we need to add brackets to the hostname 
when generating the connection string.



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