cassandra-pr mailing list archives

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

    https://github.com/apache/cassandra/pull/292#discussion_r240344277
  
    --- 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;
    --- End diff --
    
    Sorry, just to clarify this is a Cassandra level thing, not a Zstd level thing. Cassandra
calls the `create` method via reflection [here](https://github.com/apache/cassandra/blob/caf50de31b034ed77140b3c1597e7ca6ddc44e17/src/java/org/apache/cassandra/schema/CompressionParams.java#L288-L289),
and since the `ICompressors` are "stateless" we can make a reasonable cache using a `ConcurrentHashMap`
like [LZ4Compressor](https://github.com/apache/cassandra/blob/06209037ea56b5a2a49615a99f1542d6ea1b2947/src/java/org/apache/cassandra/io/compress/LZ4Compressor.java#L61)
does keyed by parameter. This assumes of course that the `Zstd` apis are threadsafe, but I'm
pretty confident they are.


---

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


Mime
View raw message