cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject git commit: Check for unknown/invalid compression options
Date Wed, 23 May 2012 13:46:38 GMT
Updated Branches:
  refs/heads/cassandra-1.1 b5f99a336 -> 820411fe4


Check for unknown/invalid compression options

patch by slebresne; reviewed by jbellis for CASSANDRA-4266


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/820411fe
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/820411fe
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/820411fe

Branch: refs/heads/cassandra-1.1
Commit: 820411fe4653697528bcbb210ca9e4171579b36f
Parents: b5f99a3
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed May 23 15:45:17 2012 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Wed May 23 15:45:17 2012 +0200

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../org/apache/cassandra/config/CFMetaData.java    |    6 ++-
 src/java/org/apache/cassandra/cql/CFPropDefs.java  |    5 ++-
 src/java/org/apache/cassandra/cql3/CFPropDefs.java |    3 +-
 .../io/compress/CompressionParameters.java         |    9 ++++-
 .../cassandra/io/compress/DeflateCompressor.java   |    7 +++
 .../apache/cassandra/io/compress/ICompressor.java  |    3 +
 .../cassandra/io/compress/SnappyCompressor.java    |   33 +++++++++++++++
 8 files changed, 63 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/820411fe/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 21570c7..bc2bf66 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -57,6 +57,7 @@
  * (cql3) Correctly validate order by queries (CASSANDRA-4246)
  * rename stress to cassandra-stress for saner packaging (CASSANDRA-4256)
  * Fix exception on colum metadata with non-string comparator (CASSANDRA-4269)
+ * Check for unknown/invalid compression options (CASSANDRA-4266)
 Merged from 1.0:
  * Fix super columns bug where cache is not updated (CASSANDRA-4190)
  * fix maxTimestamp to include row tombstones (CASSANDRA-4116)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/820411fe/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/CFMetaData.java b/src/java/org/apache/cassandra/config/CFMetaData.java
index ce4ed76..54ef1f1 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -72,6 +72,9 @@ public final class CFMetaData
     public final static Caching DEFAULT_CACHING_STRATEGY = Caching.KEYS_ONLY;
     public final static Double DEFAULT_BF_FP_CHANCE = null;
 
+    // Note that this is the default only for user created tables
+    public final static String DEFAULT_COMPRESSOR = SnappyCompressor.isAvailable() ? SnappyCompressor.class.getCanonicalName()
: null;
+
     public static final CFMetaData StatusCf = newSystemMetadata(SystemTable.STATUS_CF, 0,
"persistent metadata for the local node", BytesType.instance, null);
     public static final CFMetaData HintsCf = newSystemMetadata(HintedHandOffManager.HINTS_CF,
1, "hinted handoff data", BytesType.instance, BytesType.instance);
     @Deprecated
@@ -595,7 +598,8 @@ public final class CFMetaData
         {
             cf_def.setCompression_options(new HashMap<String, String>()
             {{
-                put(CompressionParameters.SSTABLE_COMPRESSION, SnappyCompressor.class.getCanonicalName());
+                if (DEFAULT_COMPRESSOR != null)
+                    put(CompressionParameters.SSTABLE_COMPRESSION, DEFAULT_COMPRESSOR);
             }});
         }
         if (!cf_def.isSetDclocal_read_repair_chance())

http://git-wip-us.apache.org/repos/asf/cassandra/blob/820411fe/src/java/org/apache/cassandra/cql/CFPropDefs.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/CFPropDefs.java b/src/java/org/apache/cassandra/cql/CFPropDefs.java
index f9033a8..7350b3f 100644
--- a/src/java/org/apache/cassandra/cql/CFPropDefs.java
+++ b/src/java/org/apache/cassandra/cql/CFPropDefs.java
@@ -63,6 +63,8 @@ public class CFPropDefs {
     public static final String COMPACTION_OPTIONS_PREFIX = "compaction_strategy_options";
     public static final String COMPRESSION_PARAMETERS_PREFIX = "compression_parameters";
 
+    private static final String DEFAULT_COMPRESSOR = SnappyCompressor.isAvailable() ? SnappyCompressor.class.getCanonicalName()
: null;
+
     static
     {
         comparators.put("ascii", "AsciiType");
@@ -111,7 +113,8 @@ public class CFPropDefs {
     public final Map<String, String> compactionStrategyOptions = new HashMap<String,
String>();
     public final Map<String, String> compressionParameters = new HashMap<String,
String>()
     {{
-        put(CompressionParameters.SSTABLE_COMPRESSION, SnappyCompressor.class.getCanonicalName());
+        if (CFMetaData.DEFAULT_COMPRESSOR != null)
+            put(CompressionParameters.SSTABLE_COMPRESSION, CFMetaData.DEFAULT_COMPRESSOR);
     }};
 
     public void validate() throws InvalidRequestException

http://git-wip-us.apache.org/repos/asf/cassandra/blob/820411fe/src/java/org/apache/cassandra/cql3/CFPropDefs.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/CFPropDefs.java b/src/java/org/apache/cassandra/cql3/CFPropDefs.java
index 7072176..4fc9f5f 100644
--- a/src/java/org/apache/cassandra/cql3/CFPropDefs.java
+++ b/src/java/org/apache/cassandra/cql3/CFPropDefs.java
@@ -93,7 +93,8 @@ public class CFPropDefs
     public final Map<String, String> compactionStrategyOptions = new HashMap<String,
String>();
     public final Map<String, String> compressionParameters = new HashMap<String,
String>()
     {{
-        put(CompressionParameters.SSTABLE_COMPRESSION, SnappyCompressor.class.getCanonicalName());
+        if (CFMetaData.DEFAULT_COMPRESSOR != null)
+            put(CompressionParameters.SSTABLE_COMPRESSION, CFMetaData.DEFAULT_COMPRESSOR);
     }};
 
     public static AbstractType<?> parseType(String type) throws InvalidRequestException

http://git-wip-us.apache.org/repos/asf/cassandra/blob/820411fe/src/java/org/apache/cassandra/io/compress/CompressionParameters.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/compress/CompressionParameters.java b/src/java/org/apache/cassandra/io/compress/CompressionParameters.java
index d152eda..c8a15d7 100644
--- a/src/java/org/apache/cassandra/io/compress/CompressionParameters.java
+++ b/src/java/org/apache/cassandra/io/compress/CompressionParameters.java
@@ -23,6 +23,7 @@ import java.lang.reflect.Method;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.avro.util.Utf8;
 import org.apache.commons.lang.builder.EqualsBuilder;
@@ -104,7 +105,13 @@ public class CompressionParameters
         try
         {
             Method method = compressorClass.getMethod("create", Map.class);
-            return (ICompressor)method.invoke(null, compressionOptions);
+            ICompressor compressor = (ICompressor)method.invoke(null, compressionOptions);
+            // Check for unknown options
+            Set<String> supportedOpts = compressor.supportedOptions();
+            for (String provided : compressionOptions.keySet())
+                if (!supportedOpts.contains(provided))
+                    throw new ConfigurationException("Unknown compression options " + provided);
+            return compressor;
         }
         catch (NoSuchMethodException e)
         {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/820411fe/src/java/org/apache/cassandra/io/compress/DeflateCompressor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/compress/DeflateCompressor.java b/src/java/org/apache/cassandra/io/compress/DeflateCompressor.java
index 1b4bbaf..aecdf82 100644
--- a/src/java/org/apache/cassandra/io/compress/DeflateCompressor.java
+++ b/src/java/org/apache/cassandra/io/compress/DeflateCompressor.java
@@ -19,7 +19,9 @@
 package org.apache.cassandra.io.compress;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.Map;
+import java.util.Set;
 import java.util.zip.DataFormatException;
 import java.util.zip.Deflater;
 import java.util.zip.Inflater;
@@ -57,6 +59,11 @@ public class DeflateCompressor implements ICompressor
         };
     }
 
+    public Set<String> supportedOptions()
+    {
+        return Collections.emptySet();
+    }
+
     public int initialCompressedBufferLength(int chunkLength)
     {
         return chunkLength;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/820411fe/src/java/org/apache/cassandra/io/compress/ICompressor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/compress/ICompressor.java b/src/java/org/apache/cassandra/io/compress/ICompressor.java
index 2e85d4f..4b2a520 100644
--- a/src/java/org/apache/cassandra/io/compress/ICompressor.java
+++ b/src/java/org/apache/cassandra/io/compress/ICompressor.java
@@ -19,6 +19,7 @@
 package org.apache.cassandra.io.compress;
 
 import java.io.IOException;
+import java.util.Set;
 
 public interface ICompressor
 {
@@ -28,6 +29,8 @@ public interface ICompressor
 
     public int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output,
int outputOffset) throws IOException;
 
+    public Set<String> supportedOptions();
+
     /**
      * A simple wrapper of a byte array.
      * Not all implementation allows to know what is the maximum size after

http://git-wip-us.apache.org/repos/asf/cassandra/blob/820411fe/src/java/org/apache/cassandra/io/compress/SnappyCompressor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/compress/SnappyCompressor.java b/src/java/org/apache/cassandra/io/compress/SnappyCompressor.java
index 1d36fe6..9d17492 100644
--- a/src/java/org/apache/cassandra/io/compress/SnappyCompressor.java
+++ b/src/java/org/apache/cassandra/io/compress/SnappyCompressor.java
@@ -19,14 +19,25 @@
 package org.apache.cassandra.io.compress;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.Map;
+import java.util.Set;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.xerial.snappy.Snappy;
 
 public class SnappyCompressor implements ICompressor
 {
     public static final SnappyCompressor instance = new SnappyCompressor();
 
+    private static Logger logger = LoggerFactory.getLogger(SnappyCompressor.class);
+    static
+    {
+        if (!isAvailable())
+            logger.warn("Cannot initialize native Snappy library. Compression on new tables
will be disabled.");
+    }
+
     public static SnappyCompressor create(Map<String, String> compressionOptions)
     {
         // this would throw java.lang.NoClassDefFoundError if Snappy class
@@ -37,6 +48,28 @@ public class SnappyCompressor implements ICompressor
         return instance;
     }
 
+    public static boolean isAvailable()
+    {
+        try
+        {
+            create(Collections.<String, String>emptyMap());
+            return true;
+        }
+        catch (Exception e)
+        {
+            return false;
+        }
+        catch (NoClassDefFoundError e)
+        {
+            return false;
+        }
+    }
+
+    public Set<String> supportedOptions()
+    {
+        return Collections.emptySet();
+    }
+
     public int initialCompressedBufferLength(int chunkLength)
     {
         return Snappy.maxCompressedLength(chunkLength);


Mime
View raw message