chia7712 commented on code in PR #16893:
URL: https://github.com/apache/kafka/pull/16893#discussion_r1723220386


##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -2529,8 +2529,8 @@ class KafkaApis(val requestChannel: RequestChannel,
   }
 
   def ensureInterBrokerVersion(version: MetadataVersion): Unit = {
-    if (config.interBrokerProtocolVersion.isLessThan(version))
-      throw new UnsupportedVersionException(s"inter.broker.protocol.version: 
${config.interBrokerProtocolVersion} is less than the required version: 
${version}")
+    if (replicaManager.metadataCache.metadataVersion().isLessThan(version))

Review Comment:
   why taking `metadataCache` from `replicaManager`? `KafkaApis` has 
`metadataCache` already



##########
core/src/test/scala/unit/kafka/server/KafkaApisTest.scala:
##########
@@ -196,6 +196,11 @@ class KafkaApisTest extends Logging {
       }
     }
 
+    when(replicaManager.metadataCache)

Review Comment:
   All we need to do is to create `MetadataCache` according to 
`MetadataVersion` used by testing. for example:
   ```scala
     @Test
     def 
shouldThrowUnsupportedVersionExceptionOnHandleAddOffsetToTxnRequestWhenInterBrokerProtocolNotSupported():
 Unit = {
       metadataCache = MetadataCache.zkMetadataCache(brokerId, IBP_0_10_2_IV0)
       brokerEpochManager = new ZkBrokerEpochManager(metadataCache, controller, 
None)
       kafkaApis = createKafkaApis(IBP_0_10_2_IV0)
       assertThrows(classOf[UnsupportedVersionException],
         () => kafkaApis.handleAddOffsetsToTxnRequest(null, 
RequestLocal.withThreadConfinedCaching))
     }
   ```



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