dongnuo123 commented on code in PR #17886:
URL: https://github.com/apache/kafka/pull/17886#discussion_r1868402702


##########
server-common/src/main/java/org/apache/kafka/server/common/Features.java:
##########
@@ -177,4 +223,92 @@ public static Features featureFromName(String featureName) 
{
     public static Map<String, Short> featureImplsToMap(List<FeatureVersion> 
features) {
         return 
features.stream().collect(Collectors.toMap(FeatureVersion::featureName, 
FeatureVersion::featureLevel));
     }
+
+    public boolean isProductionReady(short featureVersion) {
+        return featureVersion <= latestProduction();
+    }
+
+    public boolean hasFeatureVersion(FeatureVersion featureVersion) {
+        for (FeatureVersion v : featureVersions()) {
+            if (v == featureVersion) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * The method ensures that the following statements are met:
+     * 1. The latest production value is one of the feature values.
+     * 2. The latest production value >= the default value.
+     * 3. The dependencies of the latest production value <= their latest 
production values.
+     * 4. The dependencies of the default value <= their default values.
+     *
+     * Suppose we have feature X as the feature being validated.
+     * Invalid examples:
+     *     - The feature X has default version = XV_10 (dependency = {}), 
latest production = XV_5 (dependency = {})
+     *       (Violating rule 2. The latest production value XV_5 is smaller 
than the default value)
+     *     - The feature X has default version = XV_10 (dependency = {Y: 
YV_3}), latest production = XV_11 (dependency = {Y: YV_4})
+     *       The feature Y has default version = YV_3 (dependency = {}), 
latest production = YV_3 (dependency = {})
+     *       (Violating rule 3. For latest production XV_11, Y's latest 
production YV_3 is smaller than the dependency value YV_4)
+     *     - The feature X has default version = XV_10 (dependency = {Y: 
YV_4}), latest production = XV_11 (dependency = {Y: YV_4})
+     *       The feature Y has default version = YV_3 (dependency = {}), 
latest production = YV_4 (dependency = {})
+     *       (Violating rule 4. For default version XV_10, Y's default value 
YV_3 is smaller than the dependency value YV_4)
+     * Valid examples:
+     *     - The feature X has default version = XV_10 (dependency = {}), 
latest production = XV_10 (dependency = {})
+     *     - The feature X has default version = XV_10 (dependency = {Y: 
YV_3}), latest production = XV_11 (dependency = {Y: YV_4})
+     *       The feature Y has default version = YV_3 (dependency = {}), 
latest production = YV_4 (dependency = {})
+     *     - The feature X has default version = latest production = XV_10 
(dependency = {MetadataVersion: IBP_4_0_IV0})
+     *       (Some features can depend on MetadataVersion, which is not 
checked in this method)

Review Comment:
   I agree we also need to verify MV dependency. Added two checks
   - if the latest production depends on MV, the MV must not be ahead of 
`MetadataVersion.LATEST_PRODUCTION`.
   - if the default production depends on MV, the MV must not be ahead of the 
boostrap MV.



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