cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexott <...@git.apache.org>
Subject [GitHub] cassandra pull request #292: provide ZSTD compression support to cassandra (...
Date Mon, 10 Dec 2018 08:55:01 GMT
Github user alexott commented on a diff in the pull request:

    https://github.com/apache/cassandra/pull/292#discussion_r240124308
  
    --- Diff: src/java/org/apache/cassandra/io/compress/ZSTDCompressor.java ---
    @@ -0,0 +1,138 @@
    +/*
    + * 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.cassandra.io.compress;
    +
    +import java.io.IOException;
    +import java.nio.ByteBuffer;
    +import java.util.Collections;
    +import java.util.HashSet;
    +import java.util.Map;
    +import java.util.Set;
    +
    +import com.google.common.annotations.VisibleForTesting;
    +import com.github.luben.zstd.Zstd;
    +
    +public class ZSTDCompressor implements ICompressor
    +{
    +    public static final int FAST_COMPRESSION = 1; // fastest compression time
    +    public static final int DEFAULT_LEVEL = 3;
    +    public static final int BEST_COMPRESSION = 22;// very good compression ratio
    +    private static final ZSTDCompressor instance = new ZSTDCompressor();
    +    private static final String COMPRESSION_LEVEL_OPTION_NAME = "compression_level";
    +    @VisibleForTesting
    +    protected static final int compressionLevel = DEFAULT_LEVEL;
    +
    +    public static ZSTDCompressor create(Map<String, String> compressionOptions)
    +    {
    +        validateCompressionLevel(parseCompressionLevelOption(compressionOptions));
    +        return instance;
    +    }
    +
    +    private static void validateCompressionLevel(int compressionLevel)
    +    {
    +        if (compressionLevel < FAST_COMPRESSION || compressionLevel > BEST_COMPRESSION)
    --- End diff --
    
    ZStd also supports negative compression levels that are fast but at cost of compression:
    
    > The library supports regular compression levels from 1 up to ZSTD_maxCLevel(),
      which is currently 22. Levels >= 20, labeled `--ultra`, should be used with
      caution, as they require more memory. The library also offers negative
      compression levels, which extend the range of speed vs. ratio preferences.
      The lower the level, the faster the speed (at the cost of compression).
    
    I think that it makes sense to add them as well. I think that the maximal negative value
is 17...


---

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Mime
View raw message