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


##########
tools/src/main/java/org/apache/kafka/tools/LogCompactionTester.java:
##########
@@ -226,6 +236,56 @@ public static String peekLine(BufferedReader reader) 
throws IOException {
 
     private static final Random RANDOM = new Random();
 
+    private static void validateCompressionConfig(String compressionType, 
Integer compressionLevel) {
+        validateCompressionType(compressionType);
+        validateCompressionLevel(compressionType, compressionLevel);
+    }
+
+    private static void validateCompressionType(String compressionType) {
+        Set<String> validTypes = Set.of("none", "gzip", "snappy", "lz4", 
"zstd");
+        if (!validTypes.contains(compressionType.toLowerCase(Locale.ROOT))) {
+            System.err.println("Invalid compression type: " + compressionType);
+            System.err.println("Valid types: " + validTypes);
+            Exit.exit(1);
+        }
+    }
+
+    private static void validateCompressionLevel(String compressionType, 
Integer compressionLevel) {
+        if (compressionLevel == null) {
+            return;
+        }
+
+        String normalizedType = compressionType.toLowerCase(Locale.ROOT);
+        switch (normalizedType) {
+            case "none":
+            case "snappy":
+                System.err.println("Compression level not supported for " + 
compressionType);
+                System.err.println("Remove --compression-level option");
+                Exit.exit(1);
+                break;
+            case "gzip":
+                validateLevelRange(compressionLevel, CompressionType.GZIP, 
"gzip");
+                break;
+            case "lz4":
+                validateLevelRange(compressionLevel, CompressionType.LZ4, 
"lz4");
+                break;
+            case "zstd":
+                validateLevelRange(compressionLevel, CompressionType.ZSTD, 
"zstd");
+                break;
+            default:
+                // This should never happen since compression type is 
validated first
+                throw new IllegalStateException("Unknown compression type: " + 
compressionType);
+        }
+    }
+
+    private static void validateLevelRange(int level, CompressionType type, 
String typeName) {

Review Comment:
   this validation is good, but `CompressionType` already cover the checks. 
Perhaps the duplicate checks are not necessary.



##########
tools/src/main/java/org/apache/kafka/tools/LogCompactionTester.java:
##########
@@ -226,6 +236,56 @@ public static String peekLine(BufferedReader reader) 
throws IOException {
 
     private static final Random RANDOM = new Random();
 
+    private static void validateCompressionConfig(String compressionType, 
Integer compressionLevel) {
+        validateCompressionType(compressionType);
+        validateCompressionLevel(compressionType, compressionLevel);
+    }
+
+    private static void validateCompressionType(String compressionType) {

Review Comment:
   This could be replaced by `CompressionType.forName`, 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.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

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

Reply via email to