You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/06/09 17:13:54 UTC

[GitHub] [kafka] tombentley commented on a change in pull request #10826: KAFKA-7632: Support Compression Level

tombentley commented on a change in pull request #10826:
URL: https://github.com/apache/kafka/pull/10826#discussion_r648485713



##########
File path: clients/src/main/java/org/apache/kafka/common/record/MemoryRecordsBuilder.java
##########
@@ -183,8 +183,8 @@ public double compressionRatio() {
         return actualCompressionRatio;
     }
 
-    public CompressionType compressionType() {
-        return compressionType;
+    public CompressionConfig compressionConfing() {

Review comment:
       typo, it should be `compressionConfig()`

##########
File path: clients/src/main/java/org/apache/kafka/common/record/CompressionConfig.java
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.record;
+
+import org.apache.kafka.common.utils.BufferSupplier;
+import org.apache.kafka.common.utils.ByteBufferOutputStream;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+
+public class CompressionConfig {
+    private final CompressionType type;
+    private final Integer level;
+
+    public static CompressionConfig none() {
+        return of(CompressionType.NONE);
+    }
+
+    public static CompressionConfig of(final CompressionType type) {
+        return of(Objects.requireNonNull(type), null);
+    }
+
+    public static CompressionConfig of(final CompressionType type, final Integer level) {
+        return new CompressionConfig(Objects.requireNonNull(type), level);
+    }
+
+    private CompressionConfig(final CompressionType type, final Integer level) {
+        this.type = type;
+
+        if (level != null && !type.isValidLevel(level.intValue())) {
+            throw new IllegalArgumentException("Illegal level " + level + " for compression codec " + type.name);

Review comment:
       Should the message include the valid levels?

##########
File path: core/src/main/scala/kafka/server/KafkaConfig.scala
##########
@@ -933,6 +934,9 @@ object KafkaConfig {
   val CompressionTypeDoc = "Specify the final compression type for a given topic. This configuration accepts the standard compression codecs " +
   "('gzip', 'snappy', 'lz4', 'zstd'). It additionally accepts 'uncompressed' which is equivalent to no compression; and " +
   "'producer' which means retain the original compression codec set by the producer."
+  val CompressionLevelDoc = "The compression level for all data generated by the producer. The default level and valid value is up to " +
+    "compression.type. (<code>none</code>, <code>snappy</code>: not available. <code>gzip</code>: 1~9. <code>lz4</code>: 1~17. " +
+    "<code>zstd</code>: -131072~22."

Review comment:
       Since the docs use `[min,...,max]` syntax for things validated by `ConfigDef.Range` I think we should use a similar syntax here for consistency (even though it's not validated by `Range`).




-- 
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:
users@infra.apache.org