[GitHub] [kafka] cmccabe commented on a change in pull request #10066: KAFKA-12278; Ensure exposed api versions are consistent within listener scopes

2021-02-18 Thread GitBox


cmccabe commented on a change in pull request #10066:
URL: https://github.com/apache/kafka/pull/10066#discussion_r578826004



##
File path: checkstyle/import-control.xml
##
@@ -99,6 +100,7 @@
   
   
   
+  

Review comment:
   Hmm.  Let's revisit this after 2.8.





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.

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




[GitHub] [kafka] cmccabe commented on a change in pull request #10066: KAFKA-12278; Ensure exposed api versions are consistent within listener scopes

2021-02-18 Thread GitBox


cmccabe commented on a change in pull request #10066:
URL: https://github.com/apache/kafka/pull/10066#discussion_r578825895



##
File path: core/src/main/scala/kafka/server/ApiVersionManager.scala
##
@@ -0,0 +1,126 @@
+/*
+ * 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 kafka.server
+
+import kafka.api.ApiVersion
+import kafka.network
+import kafka.network.RequestChannel
+import org.apache.kafka.common.message.ApiMessageType.ListenerType
+import org.apache.kafka.common.message.ApiVersionsResponseData
+import org.apache.kafka.common.protocol.ApiKeys
+import org.apache.kafka.common.requests.ApiVersionsResponse
+
+import scala.jdk.CollectionConverters._
+
+trait ApiVersionManager {
+  def listenerType: ListenerType
+  def enabledApis: collection.Set[ApiKeys]
+  def apiVersionResponse(throttleTimeMs: Int): ApiVersionsResponse
+  def isApiEnabled(apiKey: ApiKeys): Boolean = enabledApis.contains(apiKey)
+  def newRequestMetrics: RequestChannel.Metrics = new 
network.RequestChannel.Metrics(enabledApis)
+}
+
+object ApiVersionManager {
+  def apply(
+listenerType: ListenerType,
+config: KafkaConfig,
+forwardingManager: Option[ForwardingManager],

Review comment:
   ok





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.

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




[GitHub] [kafka] cmccabe commented on a change in pull request #10066: KAFKA-12278; Ensure exposed api versions are consistent within listener scopes

2021-02-18 Thread GitBox


cmccabe commented on a change in pull request #10066:
URL: https://github.com/apache/kafka/pull/10066#discussion_r578711547



##
File path: checkstyle/import-control.xml
##
@@ -99,6 +100,7 @@
   
   
   
+  

Review comment:
   > I guess I would say that the dependency is there regardless of how we 
choose to hide it since we have to go through ChannelBuilders to build the 
authenticator, and the authenticator does depend on the request APIs.
   
   Yeah, the API versions response is pretty special in the protocol. 
Fortunately or unfortunately, it's not treated as a generic response.  I tried 
to think of some ways to avoid this dependency but they all ended up being kind 
of like obfuscation.
   
   > Could we make it work by changing the supplier to something more generic?
   
   Maybe I'm misinterpreting the suggestion, but if we choose to make this a 
`Supplier`, that's still in the requests package





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.

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




[GitHub] [kafka] cmccabe commented on a change in pull request #10066: KAFKA-12278; Ensure exposed api versions are consistent within listener scopes

2021-02-18 Thread GitBox


cmccabe commented on a change in pull request #10066:
URL: https://github.com/apache/kafka/pull/10066#discussion_r578711547



##
File path: checkstyle/import-control.xml
##
@@ -99,6 +100,7 @@
   
   
   
+  

Review comment:
   Yeah, the API versions response is pretty special in the protocol. 
Fortunately or unfortunately, it's not treated as a generic response.  I tried 
to think of some ways to avoid this dependency but they all ended up being kind 
of like obfuscation.
   
   > Could we make it work by changing the supplier to something more generic?
   
   Maybe I'm misinterpreting the suggestion, but if we chose to make this a 
`Supplier`, that's still in the requests package





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.

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




[GitHub] [kafka] cmccabe commented on a change in pull request #10066: KAFKA-12278; Ensure exposed api versions are consistent within listener scopes

2021-02-18 Thread GitBox


cmccabe commented on a change in pull request #10066:
URL: https://github.com/apache/kafka/pull/10066#discussion_r578711547



##
File path: checkstyle/import-control.xml
##
@@ -99,6 +100,7 @@
   
   
   
+  

Review comment:
   Yeah, the API versions response is pretty special in the protocol. 
Fortunately or unfortunately, it's not treated as a generic response.  I tried 
to think of some ways to avoid this dependency but they all ended up being kind 
of like obfuscation.
   
   Even if we chose to make this a `Supplier`, that's still 
in the requests package





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.

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




[GitHub] [kafka] cmccabe commented on a change in pull request #10066: KAFKA-12278; Ensure exposed api versions are consistent within listener scopes

2021-02-18 Thread GitBox


cmccabe commented on a change in pull request #10066:
URL: https://github.com/apache/kafka/pull/10066#discussion_r578705716



##
File path: core/src/main/scala/kafka/server/ApiVersionManager.scala
##
@@ -0,0 +1,126 @@
+/*
+ * 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 kafka.server
+
+import kafka.api.ApiVersion
+import kafka.network
+import kafka.network.RequestChannel
+import org.apache.kafka.common.message.ApiMessageType.ListenerType
+import org.apache.kafka.common.message.ApiVersionsResponseData
+import org.apache.kafka.common.protocol.ApiKeys
+import org.apache.kafka.common.requests.ApiVersionsResponse
+
+import scala.jdk.CollectionConverters._
+
+trait ApiVersionManager {
+  def listenerType: ListenerType
+  def enabledApis: collection.Set[ApiKeys]
+  def apiVersionResponse(throttleTimeMs: Int): ApiVersionsResponse
+  def isApiEnabled(apiKey: ApiKeys): Boolean = enabledApis.contains(apiKey)
+  def newRequestMetrics: RequestChannel.Metrics = new 
network.RequestChannel.Metrics(enabledApis)
+}
+
+object ApiVersionManager {
+  def apply(
+listenerType: ListenerType,
+config: KafkaConfig,
+forwardingManager: Option[ForwardingManager],

Review comment:
   I would really prefer not to have all this `ForwardingManager` stuff in 
here.  The `ControllerServer` has been committed to trunk and does handle 
`ENVELOPE_REQUEST` so I think this is out of date.
   
   It should be as simple as controllers handle envelope requests, brokers 
don't, right?





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.

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




[GitHub] [kafka] cmccabe commented on a change in pull request #10066: KAFKA-12278; Ensure exposed api versions are consistent within listener scopes

2021-02-18 Thread GitBox


cmccabe commented on a change in pull request #10066:
URL: https://github.com/apache/kafka/pull/10066#discussion_r578701957



##
File path: clients/src/main/java/org/apache/kafka/common/protocol/ApiKeys.java
##
@@ -246,10 +250,15 @@ public void visit(Type field) {
 return hasBuffer.get();
 }
 
-public static List brokerApis() {
-return Arrays.stream(values())
-.filter(api -> !api.isControllerOnlyApi)
+public static EnumSet zkBrokerApis() {
+return apisForListener(ApiMessageType.ListenerType.ZK_BROKER);
+}
+
+public static EnumSet apisForListener(ApiMessageType.ListenerType 
listener) {

Review comment:
   given that these `EnumSets` are used so much throughout the code, we 
should just calculate them once and reuse them, rather than recalculating each 
time.  There are only 3 listener types so it could just be in a static map or 
something.





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.

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




[GitHub] [kafka] cmccabe commented on a change in pull request #10066: KAFKA-12278; Ensure exposed api versions are consistent within listener scopes

2021-02-18 Thread GitBox


cmccabe commented on a change in pull request #10066:
URL: https://github.com/apache/kafka/pull/10066#discussion_r578701957



##
File path: clients/src/main/java/org/apache/kafka/common/protocol/ApiKeys.java
##
@@ -246,10 +250,15 @@ public void visit(Type field) {
 return hasBuffer.get();
 }
 
-public static List brokerApis() {
-return Arrays.stream(values())
-.filter(api -> !api.isControllerOnlyApi)
+public static EnumSet zkBrokerApis() {
+return apisForListener(ApiMessageType.ListenerType.ZK_BROKER);
+}
+
+public static EnumSet apisForListener(ApiMessageType.ListenerType 
listener) {

Review comment:
   given that these `EnumSets` are used so much throughout the code, we 
should just calculate them once and reuse them.  There are only 3 listener 
types so it could just be in a static map or something.





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.

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




[GitHub] [kafka] cmccabe commented on a change in pull request #10066: KAFKA-12278; Ensure exposed api versions are consistent within listener scopes

2021-02-08 Thread GitBox


cmccabe commented on a change in pull request #10066:
URL: https://github.com/apache/kafka/pull/10066#discussion_r572443431



##
File path: generator/src/main/java/org/apache/kafka/message/RequestApiScope.java
##
@@ -0,0 +1,33 @@
+/*
+ * 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.message;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public enum RequestApiScope {
+@JsonProperty("zkBroker")
+ZK_BROKER,
+
+@JsonProperty("broker")
+BROKER,
+
+@JsonProperty("controller")
+CONTROLLER,
+
+@JsonProperty("raft")
+RAFT;

Review comment:
   @ijuma : unfortunately we don't have a clear separation between clients 
and brokers at the protocol level.  As you know, if a random node connects to 
the broker and asks for ApiVersions, the broker doesn't (yet) know if the other 
node is another broker or if it's a client.  So it wouldn't help to label APIs 
as CLIENT vs. BROKER, since the broker has to send back both anyway.
   
   On the other hand, we can definitely put APIs into "zk broker", "kip-500 
zk", and "kip500 controller" and use those buckets to figure out what to send 
in the ApiVersionsRequest.
   
   @hachikuji : The "raft" scope seems a little weird since all the other 
scopes map to listeners on servers.  The TestRaftServer is just an internal 
junit thing, right?  So it's probably fine if it just uses the Controller scope 
and returns `UnsupportedVersionException` for things it doesn't support.  I 
don't think we should have a separate scope for this unless it somehow impacts 
the real servers.





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.

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