Author: xedin
Date: Tue Dec  6 12:30:21 2011
New Revision: 1210884

URL: http://svn.apache.org/viewvc?rev=1210884&view=rev
Log:
fix compression "chunk_length_kb" option to set correct kb value for thrift/avro
patch by Sylvain Lebresne; reviewed by Pavel Yaskevich for CASSANDRA-3558

Modified:
    cassandra/branches/cassandra-1.0/CHANGES.txt
    
cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/io/compress/CompressionParameters.java

Modified: cassandra/branches/cassandra-1.0/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/CHANGES.txt?rev=1210884&r1=1210883&r2=1210884&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/CHANGES.txt (original)
+++ cassandra/branches/cassandra-1.0/CHANGES.txt Tue Dec  6 12:30:21 2011
@@ -14,6 +14,8 @@
    (CASSANDRA-3532)
  * (CQL) Proper ColumnFamily metadata validation on CREATE COLUMNFAMILY 
(CASSANDRA-3565)
  * validate compression parameters on add/update of the ColumnFamily 
(CASSANDRA-3573)
+ * fix compression "chunk_length_kb" option to set correct kb value for 
thrift/avro
+   (CASSANDRA-3558)
 Merged from 0.8:
  * use cannonical host for local node in nodetool info (CASSANDRA-3556)
 

Modified: 
cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/io/compress/CompressionParameters.java
URL: 
http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/io/compress/CompressionParameters.java?rev=1210884&r1=1210883&r2=1210884&view=diff
==============================================================================
--- 
cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/io/compress/CompressionParameters.java
 (original)
+++ 
cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/io/compress/CompressionParameters.java
 Tue Dec  6 12:30:21 2011
@@ -35,7 +35,7 @@ public class CompressionParameters
     public final static int DEFAULT_CHUNK_LENGTH = 65536;
 
     public static final String SSTABLE_COMPRESSION = "sstable_compression";
-    public static final String CHUNK_LENGTH = "chunk_length_kb";
+    public static final String CHUNK_LENGTH_KB = "chunk_length_kb";
 
     public final ICompressor sstableCompressor;
     private final Integer chunkLength;
@@ -45,9 +45,9 @@ public class CompressionParameters
     {
         Map<String, String> options = copyOptions(opts);
         String sstableCompressionClass = options.get(SSTABLE_COMPRESSION);
-        String chunkLength = options.get(CHUNK_LENGTH);
+        String chunkLength = options.get(CHUNK_LENGTH_KB);
         options.remove(SSTABLE_COMPRESSION);
-        options.remove(CHUNK_LENGTH);
+        options.remove(CHUNK_LENGTH_KB);
         CompressionParameters cp = new 
CompressionParameters(sstableCompressionClass, parseChunkLength(chunkLength), 
options);
         cp.validateChunkLength();
         return cp;
@@ -75,7 +75,6 @@ public class CompressionParameters
         return chunkLength == null ? DEFAULT_CHUNK_LENGTH : chunkLength;
     }
 
-
     private static Class<? extends ICompressor> parseCompressorClass(String 
className) throws ConfigurationException
     {
         if (className == null)
@@ -144,18 +143,18 @@ public class CompressionParameters
     /**
      * Parse the chunk length (in KB) and returns it as bytes.
      */
-    private static Integer parseChunkLength(String chLength) throws 
ConfigurationException
+    private static Integer parseChunkLength(String chLengthKB) throws 
ConfigurationException
     {
-        if (chLength == null)
+        if (chLengthKB == null)
             return null;
 
         try
         {
-            return 1024 * Integer.parseInt(chLength);
+            return 1024 * Integer.parseInt(chLengthKB);
         }
         catch (NumberFormatException e)
         {
-            throw new ConfigurationException("Invalid value for " + 
CHUNK_LENGTH, e);
+            throw new ConfigurationException("Invalid value for " + 
CHUNK_LENGTH_KB, e);
         }
     }
 
@@ -168,7 +167,7 @@ public class CompressionParameters
             return; // chunk length not set, this is fine, default will be used
 
         if (chunkLength <= 0)
-            throw new ConfigurationException("Invalid negative or null " + 
CHUNK_LENGTH);
+            throw new ConfigurationException("Invalid negative or null " + 
CHUNK_LENGTH_KB);
 
         int c = chunkLength;
         boolean found = false;
@@ -177,7 +176,7 @@ public class CompressionParameters
             if ((c & 0x01) != 0)
             {
                 if (found)
-                    throw new ConfigurationException(CHUNK_LENGTH + " must be 
a power of 2");
+                    throw new ConfigurationException(CHUNK_LENGTH_KB + " must 
be a power of 2");
                 else
                     found = true;
             }
@@ -196,7 +195,7 @@ public class CompressionParameters
 
         options.put(new Utf8(SSTABLE_COMPRESSION), new 
Utf8(sstableCompressor.getClass().getName()));
         if (chunkLength != null)
-            options.put(new Utf8(CHUNK_LENGTH), new 
Utf8(chunkLength.toString()));
+            options.put(new Utf8(CHUNK_LENGTH_KB), new 
Utf8(chunkLengthInKB()));
         return options;
     }
 
@@ -208,10 +207,15 @@ public class CompressionParameters
 
         options.put(SSTABLE_COMPRESSION, 
sstableCompressor.getClass().getName());
         if (chunkLength != null)
-            options.put(CHUNK_LENGTH, chunkLength.toString());
+            options.put(CHUNK_LENGTH_KB, chunkLengthInKB());
         return options;
     }
 
+    private String chunkLengthInKB()
+    {
+        return String.valueOf(chunkLength() / 1024);
+    }
+
     @Override
     public boolean equals(Object obj)
     {


Reply via email to